@@ -11,95 +11,97 @@ class DocumentBuilderTests {
11
11
public void unconfiguredParse (Socket sock ) throws Exception {
12
12
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
13
13
DocumentBuilder builder = factory .newDocumentBuilder ();
14
- builder .parse (sock .getInputStream ()); //unsafe
14
+ builder .parse (sock .getInputStream ()); // $ hasTaintFlow
15
15
}
16
16
17
17
public void disableDTD (Socket sock ) throws Exception {
18
18
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
19
19
factory .setFeature ("http://apache.org/xml/features/disallow-doctype-decl" , true );
20
20
DocumentBuilder builder = factory .newDocumentBuilder ();
21
- builder .parse (sock .getInputStream ()); //safe
21
+ builder .parse (sock .getInputStream ()); // safe
22
22
}
23
23
24
24
public void enableSecurityFeature (Socket sock ) throws Exception {
25
25
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
26
26
factory .setFeature (XMLConstants .FEATURE_SECURE_PROCESSING , true );
27
27
DocumentBuilder builder = factory .newDocumentBuilder ();
28
- builder .parse (sock .getInputStream ()); //unsafe -- secure-processing by itself is insufficient
28
+ builder .parse (sock .getInputStream ()); // $ hasTaintFlow -- secure-processing by itself is
29
+ // insufficient
29
30
}
30
31
31
32
public void enableSecurityFeature2 (Socket sock ) throws Exception {
32
33
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
33
34
factory .setFeature ("http://javax.xml.XMLConstants/feature/secure-processing" , true );
34
35
DocumentBuilder builder = factory .newDocumentBuilder ();
35
- builder .parse (sock .getInputStream ()); //unsafe -- secure-processing by itself is insufficient
36
+ builder .parse (sock .getInputStream ()); // $ hasTaintFlow -- secure-processing by itself is
37
+ // insufficient
36
38
}
37
39
38
40
public void enableDTD (Socket sock ) throws Exception {
39
41
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
40
42
factory .setFeature ("http://apache.org/xml/features/disallow-doctype-decl" , false );
41
43
DocumentBuilder builder = factory .newDocumentBuilder ();
42
- builder .parse (sock .getInputStream ()); //unsafe
44
+ builder .parse (sock .getInputStream ()); // $ hasTaintFlow
43
45
}
44
46
45
47
public void disableSecurityFeature (Socket sock ) throws Exception {
46
48
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
47
49
factory .setFeature ("http://javax.xml.XMLConstants/feature/secure-processing" , false );
48
50
DocumentBuilder builder = factory .newDocumentBuilder ();
49
- builder .parse (sock .getInputStream ()); //unsafe
51
+ builder .parse (sock .getInputStream ()); // $ hasTaintFlow
50
52
}
51
53
52
54
public void disableExternalEntities (Socket sock ) throws Exception {
53
55
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
54
56
factory .setFeature ("http://xml.org/sax/features/external-parameter-entities" , false );
55
57
factory .setFeature ("http://xml.org/sax/features/external-general-entities" , false );
56
58
DocumentBuilder builder = factory .newDocumentBuilder ();
57
- builder .parse (sock .getInputStream ()); //safe
59
+ builder .parse (sock .getInputStream ()); // safe
58
60
}
59
61
60
62
public void partialDisableExternalEntities (Socket sock ) throws Exception {
61
63
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
62
64
factory .setFeature ("http://xml.org/sax/features/external-parameter-entities" , false );
63
65
DocumentBuilder builder = factory .newDocumentBuilder ();
64
- builder .parse (sock .getInputStream ()); //unsafe
66
+ builder .parse (sock .getInputStream ()); // $ hasTaintFlow
65
67
}
66
68
67
69
public void partialDisableExternalEntities2 (Socket sock ) throws Exception {
68
70
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
69
71
factory .setFeature ("http://xml.org/sax/features/external-general-entities" , false );
70
72
DocumentBuilder builder = factory .newDocumentBuilder ();
71
- builder .parse (sock .getInputStream ()); //unsafe
73
+ builder .parse (sock .getInputStream ()); // $ hasTaintFlow
72
74
}
73
75
74
76
public void misConfigureExternalEntities1 (Socket sock ) throws Exception {
75
77
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
76
78
factory .setFeature ("http://xml.org/sax/features/external-parameter-entities" , true );
77
79
factory .setFeature ("http://xml.org/sax/features/external-general-entities" , false );
78
80
DocumentBuilder builder = factory .newDocumentBuilder ();
79
- builder .parse (sock .getInputStream ()); //unsafe
81
+ builder .parse (sock .getInputStream ()); // $ hasTaintFlow
80
82
}
81
83
82
84
public void misConfigureExternalEntities2 (Socket sock ) throws Exception {
83
85
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
84
86
factory .setFeature ("http://xml.org/sax/features/external-parameter-entities" , false );
85
87
factory .setFeature ("http://xml.org/sax/features/external-general-entities" , true );
86
88
DocumentBuilder builder = factory .newDocumentBuilder ();
87
- builder .parse (sock .getInputStream ()); //unsafe
89
+ builder .parse (sock .getInputStream ()); // $ hasTaintFlow
88
90
}
89
91
90
92
public void taintedSAXInputSource1 (Socket sock ) throws Exception {
91
- DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
92
- DocumentBuilder builder = factory .newDocumentBuilder ();
93
- SAXSource source = new SAXSource (new InputSource (sock .getInputStream ()));
94
- builder .parse (source .getInputSource ()); //unsafe
93
+ DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
94
+ DocumentBuilder builder = factory .newDocumentBuilder ();
95
+ SAXSource source = new SAXSource (new InputSource (sock .getInputStream ()));
96
+ builder .parse (source .getInputSource ()); // $ hasTaintFlow
95
97
}
96
98
97
99
public void taintedSAXInputSource2 (Socket sock ) throws Exception {
98
- DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
99
- DocumentBuilder builder = factory .newDocumentBuilder ();
100
- StreamSource source = new StreamSource (sock .getInputStream ());
101
- builder .parse (SAXSource .sourceToInputSource (source )); //unsafe
102
- builder .parse (source .getInputStream ()); //unsafe
100
+ DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
101
+ DocumentBuilder builder = factory .newDocumentBuilder ();
102
+ StreamSource source = new StreamSource (sock .getInputStream ());
103
+ builder .parse (SAXSource .sourceToInputSource (source )); // $ hasTaintFlow
104
+ builder .parse (source .getInputStream ()); // $ hasTaintFlow
103
105
}
104
106
105
107
private static DocumentBuilderFactory getDocumentBuilderFactory () throws Exception {
@@ -112,21 +114,22 @@ private static DocumentBuilderFactory getDocumentBuilderFactory() throws Excepti
112
114
return factory ;
113
115
}
114
116
115
- private static final ThreadLocal <DocumentBuilder > XML_DOCUMENT_BUILDER = new ThreadLocal <DocumentBuilder >() {
116
- @ Override
117
- protected DocumentBuilder initialValue () {
118
- try {
119
- DocumentBuilderFactory factory = getDocumentBuilderFactory ();
120
- return factory .newDocumentBuilder ();
121
- } catch (Exception ex ) {
122
- throw new RuntimeException (ex );
123
- }
124
- }
125
- };
117
+ private static final ThreadLocal <DocumentBuilder > XML_DOCUMENT_BUILDER =
118
+ new ThreadLocal <DocumentBuilder >() {
119
+ @ Override
120
+ protected DocumentBuilder initialValue () {
121
+ try {
122
+ DocumentBuilderFactory factory = getDocumentBuilderFactory ();
123
+ return factory .newDocumentBuilder ();
124
+ } catch (Exception ex ) {
125
+ throw new RuntimeException (ex );
126
+ }
127
+ }
128
+ };
126
129
127
130
public void disableExternalEntities2 (Socket sock ) throws Exception {
128
131
DocumentBuilder builder = XML_DOCUMENT_BUILDER .get ();
129
- builder .parse (sock .getInputStream ()); //safe
132
+ builder .parse (sock .getInputStream ()); // safe
130
133
}
131
134
132
135
}
0 commit comments