Skip to content

Commit d3a4dad

Browse files
authored
Merge pull request #7240 from smowton/smowton/admin/derecognise-xxe-secure-processing
Note that FEATURE_SECURE_PROCESSING isn't a sufficient defence against XXE
2 parents aa9a8a0 + 9540bee commit d3a4dad

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

java/ql/lib/semmle/code/java/security/XmlParsers.qll

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,6 @@ private class ConstantStringExpr extends Expr {
159159
Expr singleSafeConfig() {
160160
result.(ConstantStringExpr).getStringValue() =
161161
"http://apache.org/xml/features/disallow-doctype-decl"
162-
or
163-
result.(ConstantStringExpr).getStringValue() =
164-
"http://javax.xml.XMLConstants/feature/secure-processing"
165-
or
166-
exists(Field f |
167-
result = f.getAnAccess() and
168-
f.hasName("FEATURE_SECURE_PROCESSING") and
169-
f.getDeclaringType().hasQualifiedName("javax.xml", "XMLConstants")
170-
)
171162
}
172163

173164
/**

java/ql/test/query-tests/security/CWE-611/DocumentBuilderTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public void enableSecurityFeature(Socket sock) throws Exception {
2525
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
2626
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
2727
DocumentBuilder builder = factory.newDocumentBuilder();
28-
builder.parse(sock.getInputStream()); //safe
28+
builder.parse(sock.getInputStream()); //unsafe -- secure-processing by itself is insufficient
2929
}
3030

3131
public void enableSecurityFeature2(Socket sock) throws Exception {
3232
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
3333
factory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
3434
DocumentBuilder builder = factory.newDocumentBuilder();
35-
builder.parse(sock.getInputStream()); //safe
35+
builder.parse(sock.getInputStream()); //unsafe -- secure-processing by itself is insufficient
3636
}
3737

3838
public void enableDTD(Socket sock) throws Exception {

java/ql/test/query-tests/security/CWE-611/XXE.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ edges
7777
| XPathExpressionTests.java:27:37:27:57 | getInputStream(...) : InputStream | XPathExpressionTests.java:27:21:27:58 | new InputSource(...) |
7878
nodes
7979
| DocumentBuilderTests.java:14:19:14:39 | getInputStream(...) | semmle.label | getInputStream(...) |
80+
| DocumentBuilderTests.java:28:19:28:39 | getInputStream(...) | semmle.label | getInputStream(...) |
81+
| DocumentBuilderTests.java:35:19:35:39 | getInputStream(...) | semmle.label | getInputStream(...) |
8082
| DocumentBuilderTests.java:42:19:42:39 | getInputStream(...) | semmle.label | getInputStream(...) |
8183
| DocumentBuilderTests.java:49:19:49:39 | getInputStream(...) | semmle.label | getInputStream(...) |
8284
| DocumentBuilderTests.java:64:19:64:39 | getInputStream(...) | semmle.label | getInputStream(...) |
@@ -250,6 +252,8 @@ nodes
250252
subpaths
251253
#select
252254
| DocumentBuilderTests.java:14:19:14:39 | getInputStream(...) | DocumentBuilderTests.java:14:19:14:39 | getInputStream(...) | DocumentBuilderTests.java:14:19:14:39 | getInputStream(...) | Unsafe parsing of XML file from $@. | DocumentBuilderTests.java:14:19:14:39 | getInputStream(...) | user input |
255+
| DocumentBuilderTests.java:28:19:28:39 | getInputStream(...) | DocumentBuilderTests.java:28:19:28:39 | getInputStream(...) | DocumentBuilderTests.java:28:19:28:39 | getInputStream(...) | Unsafe parsing of XML file from $@. | DocumentBuilderTests.java:28:19:28:39 | getInputStream(...) | user input |
256+
| DocumentBuilderTests.java:35:19:35:39 | getInputStream(...) | DocumentBuilderTests.java:35:19:35:39 | getInputStream(...) | DocumentBuilderTests.java:35:19:35:39 | getInputStream(...) | Unsafe parsing of XML file from $@. | DocumentBuilderTests.java:35:19:35:39 | getInputStream(...) | user input |
253257
| DocumentBuilderTests.java:42:19:42:39 | getInputStream(...) | DocumentBuilderTests.java:42:19:42:39 | getInputStream(...) | DocumentBuilderTests.java:42:19:42:39 | getInputStream(...) | Unsafe parsing of XML file from $@. | DocumentBuilderTests.java:42:19:42:39 | getInputStream(...) | user input |
254258
| DocumentBuilderTests.java:49:19:49:39 | getInputStream(...) | DocumentBuilderTests.java:49:19:49:39 | getInputStream(...) | DocumentBuilderTests.java:49:19:49:39 | getInputStream(...) | Unsafe parsing of XML file from $@. | DocumentBuilderTests.java:49:19:49:39 | getInputStream(...) | user input |
255259
| DocumentBuilderTests.java:64:19:64:39 | getInputStream(...) | DocumentBuilderTests.java:64:19:64:39 | getInputStream(...) | DocumentBuilderTests.java:64:19:64:39 | getInputStream(...) | Unsafe parsing of XML file from $@. | DocumentBuilderTests.java:64:19:64:39 | getInputStream(...) | user input |

0 commit comments

Comments
 (0)