Skip to content

Commit d859a91

Browse files
committed
C++: Add support for createLSParser.
1 parent 79aba67 commit d859a91

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

cpp/ql/src/Security/CWE/CWE-611/XXE.ql

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ class ParseFunction extends Function {
163163
ParseFunction() { this.getClassAndName("parse") instanceof AbstractDOMParserClass }
164164
}
165165

166+
/**
167+
* The `createLSParser` function that returns a newly created `LSParser` object.
168+
*/
169+
class CreateLSParser extends Function {
170+
CreateLSParser() { this.hasName("createLSParser") }
171+
}
172+
166173
/**
167174
* Configuration for tracking XML objects and their states.
168175
*/
@@ -178,6 +185,13 @@ class XXEConfiguration extends DataFlow::Configuration {
178185
call.getThisArgument() and
179186
encodeXercesDOMFlowState(flowstate, 0, 1) // default configuration
180187
)
188+
or
189+
// source is the result of a call to `createLSParser`.
190+
exists(Call call |
191+
call.getTarget() instanceof CreateLSParser and
192+
call = node.asExpr() and
193+
encodeXercesDOMFlowState(flowstate, 0, 1) // default configuration
194+
)
181195
}
182196

183197
override predicate isSink(DataFlow::Node node, string flowstate) {
@@ -208,5 +222,4 @@ class XXEConfiguration extends DataFlow::Configuration {
208222
from XXEConfiguration conf, DataFlow::PathNode source, DataFlow::PathNode sink
209223
where conf.hasFlowPath(source, sink)
210224
select sink, source, sink,
211-
"This $@ is not configured to prevent an XML external entity (XXE) attack.", source,
212-
"XML parser"
225+
"This $@ is not configured to prevent an XML external entity (XXE) attack.", source, "XML parser"

cpp/ql/test/query-tests/Security/CWE/CWE-611/XXE.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ edges
2525
| tests.cpp:140:23:140:43 | XercesDOMParser output argument | tests.cpp:146:18:146:18 | q |
2626
| tests.cpp:144:18:144:18 | q | tests.cpp:130:39:130:39 | p |
2727
| tests.cpp:146:18:146:18 | q | tests.cpp:134:39:134:39 | p |
28+
| tests.cpp:150:16:150:29 | call to createLSParser | tests.cpp:152:2:152:2 | p |
2829
nodes
2930
| tests.cpp:33:23:33:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
3031
| tests.cpp:35:2:35:2 | p | semmle.label | p |
@@ -61,6 +62,8 @@ nodes
6162
| tests.cpp:140:23:140:43 | XercesDOMParser output argument | semmle.label | XercesDOMParser output argument |
6263
| tests.cpp:144:18:144:18 | q | semmle.label | q |
6364
| tests.cpp:146:18:146:18 | q | semmle.label | q |
65+
| tests.cpp:150:16:150:29 | call to createLSParser | semmle.label | call to createLSParser |
66+
| tests.cpp:152:2:152:2 | p | semmle.label | p |
6467
subpaths
6568
#select
6669
| tests.cpp:35:2:35:2 | p | tests.cpp:33:23:33:43 | XercesDOMParser output argument | tests.cpp:35:2:35:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:33:23:33:43 | XercesDOMParser output argument | XML parser |
@@ -74,3 +77,4 @@ subpaths
7477
| tests.cpp:122:3:122:3 | q | tests.cpp:118:24:118:44 | XercesDOMParser output argument | tests.cpp:122:3:122:3 | q | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:118:24:118:44 | XercesDOMParser output argument | XML parser |
7578
| tests.cpp:131:2:131:2 | p | tests.cpp:140:23:140:43 | XercesDOMParser output argument | tests.cpp:131:2:131:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:140:23:140:43 | XercesDOMParser output argument | XML parser |
7679
| tests.cpp:135:2:135:2 | p | tests.cpp:140:23:140:43 | XercesDOMParser output argument | tests.cpp:135:2:135:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:140:23:140:43 | XercesDOMParser output argument | XML parser |
80+
| tests.cpp:152:2:152:2 | p | tests.cpp:150:16:150:29 | call to createLSParser | tests.cpp:152:2:152:2 | p | This $@ is not configured to prevent an XML external entity (XXE) attack. | tests.cpp:150:16:150:29 | call to createLSParser | XML parser |

cpp/ql/test/query-tests/Security/CWE/CWE-611/tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void test10(InputSource &data) {
149149
void test11(InputSource &data) {
150150
LSParser *p = createLSParser();
151151

152-
p->parse(data); // BAD (parser not correctly configured) [NOT DETECTED]
152+
p->parse(data); // BAD (parser not correctly configured)
153153
}
154154

155155
void test12(InputSource &data) {

0 commit comments

Comments
 (0)