Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2d170b

Browse files
committed
JS: Port XpathInjection
1 parent 03f8c0f commit c2d170b

3 files changed

Lines changed: 36 additions & 39 deletions

File tree

javascript/ql/lib/semmle/javascript/security/dataflow/XpathInjectionQuery.qll

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,23 @@ import XpathInjectionCustomizations::XpathInjection
1414
/**
1515
* A taint-tracking configuration for untrusted user input used in XPath expression.
1616
*/
17-
class Configuration extends TaintTracking::Configuration {
17+
module XpathInjectionConfig implements DataFlow::ConfigSig {
18+
predicate isSource(DataFlow::Node source) { source instanceof Source }
19+
20+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
21+
22+
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
23+
}
24+
25+
/**
26+
* Taint-tracking for untrusted user input used in XPath expression.
27+
*/
28+
module XpathInjectionFlow = TaintTracking::Global<XpathInjectionConfig>;
29+
30+
/**
31+
* DEPRECATED. Use the `XpathInjectionFlow` module instead.
32+
*/
33+
deprecated class Configuration extends TaintTracking::Configuration {
1834
Configuration() { this = "XpathInjection" }
1935

2036
override predicate isSource(DataFlow::Node source) { source instanceof Source }

javascript/ql/src/Security/CWE-643/XpathInjection.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
import javascript
1515
import semmle.javascript.security.dataflow.XpathInjectionQuery
16-
import DataFlow::PathGraph
16+
import XpathInjectionFlow::PathGraph
1717

18-
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
19-
where cfg.hasFlowPath(source, sink)
18+
from XpathInjectionFlow::PathNode source, XpathInjectionFlow::PathNode sink
19+
where XpathInjectionFlow::flowPath(source, sink)
2020
select sink.getNode(), source, sink, "XPath expression depends on a $@.", source.getNode(),
2121
"user-provided value"

javascript/ql/test/query-tests/Security/CWE-643/XpathInjection.expected

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,31 @@
1-
nodes
2-
| XpathInjectionBad.js:6:7:6:38 | userName |
3-
| XpathInjectionBad.js:6:18:6:38 | req.par ... rName") |
4-
| XpathInjectionBad.js:6:18:6:38 | req.par ... rName") |
5-
| XpathInjectionBad.js:9:34:9:96 | "//user ... text()" |
6-
| XpathInjectionBad.js:9:34:9:96 | "//user ... text()" |
7-
| XpathInjectionBad.js:9:66:9:73 | userName |
8-
| tst2.js:1:13:1:34 | documen ... on.hash |
9-
| tst2.js:1:13:1:34 | documen ... on.hash |
10-
| tst2.js:1:13:1:47 | documen ... ring(1) |
11-
| tst2.js:2:27:2:31 | query |
12-
| tst2.js:2:27:2:31 | query |
13-
| tst2.js:3:19:3:23 | query |
14-
| tst2.js:3:19:3:23 | query |
15-
| tst.js:6:7:6:37 | tainted |
16-
| tst.js:6:17:6:37 | req.par ... rName") |
17-
| tst.js:6:17:6:37 | req.par ... rName") |
18-
| tst.js:7:15:7:21 | tainted |
19-
| tst.js:7:15:7:21 | tainted |
20-
| tst.js:8:16:8:22 | tainted |
21-
| tst.js:8:16:8:22 | tainted |
22-
| tst.js:9:17:9:23 | tainted |
23-
| tst.js:9:17:9:23 | tainted |
24-
| tst.js:11:8:11:14 | tainted |
25-
| tst.js:11:8:11:14 | tainted |
261
edges
272
| XpathInjectionBad.js:6:7:6:38 | userName | XpathInjectionBad.js:9:66:9:73 | userName |
283
| XpathInjectionBad.js:6:18:6:38 | req.par ... rName") | XpathInjectionBad.js:6:7:6:38 | userName |
29-
| XpathInjectionBad.js:6:18:6:38 | req.par ... rName") | XpathInjectionBad.js:6:7:6:38 | userName |
30-
| XpathInjectionBad.js:9:66:9:73 | userName | XpathInjectionBad.js:9:34:9:96 | "//user ... text()" |
314
| XpathInjectionBad.js:9:66:9:73 | userName | XpathInjectionBad.js:9:34:9:96 | "//user ... text()" |
325
| tst2.js:1:13:1:34 | documen ... on.hash | tst2.js:1:13:1:47 | documen ... ring(1) |
33-
| tst2.js:1:13:1:34 | documen ... on.hash | tst2.js:1:13:1:47 | documen ... ring(1) |
34-
| tst2.js:1:13:1:47 | documen ... ring(1) | tst2.js:2:27:2:31 | query |
356
| tst2.js:1:13:1:47 | documen ... ring(1) | tst2.js:2:27:2:31 | query |
367
| tst2.js:1:13:1:47 | documen ... ring(1) | tst2.js:3:19:3:23 | query |
37-
| tst2.js:1:13:1:47 | documen ... ring(1) | tst2.js:3:19:3:23 | query |
388
| tst.js:6:7:6:37 | tainted | tst.js:7:15:7:21 | tainted |
39-
| tst.js:6:7:6:37 | tainted | tst.js:7:15:7:21 | tainted |
40-
| tst.js:6:7:6:37 | tainted | tst.js:8:16:8:22 | tainted |
419
| tst.js:6:7:6:37 | tainted | tst.js:8:16:8:22 | tainted |
4210
| tst.js:6:7:6:37 | tainted | tst.js:9:17:9:23 | tainted |
43-
| tst.js:6:7:6:37 | tainted | tst.js:9:17:9:23 | tainted |
4411
| tst.js:6:7:6:37 | tainted | tst.js:11:8:11:14 | tainted |
45-
| tst.js:6:7:6:37 | tainted | tst.js:11:8:11:14 | tainted |
46-
| tst.js:6:17:6:37 | req.par ... rName") | tst.js:6:7:6:37 | tainted |
4712
| tst.js:6:17:6:37 | req.par ... rName") | tst.js:6:7:6:37 | tainted |
13+
nodes
14+
| XpathInjectionBad.js:6:7:6:38 | userName | semmle.label | userName |
15+
| XpathInjectionBad.js:6:18:6:38 | req.par ... rName") | semmle.label | req.par ... rName") |
16+
| XpathInjectionBad.js:9:34:9:96 | "//user ... text()" | semmle.label | "//user ... text()" |
17+
| XpathInjectionBad.js:9:66:9:73 | userName | semmle.label | userName |
18+
| tst2.js:1:13:1:34 | documen ... on.hash | semmle.label | documen ... on.hash |
19+
| tst2.js:1:13:1:47 | documen ... ring(1) | semmle.label | documen ... ring(1) |
20+
| tst2.js:2:27:2:31 | query | semmle.label | query |
21+
| tst2.js:3:19:3:23 | query | semmle.label | query |
22+
| tst.js:6:7:6:37 | tainted | semmle.label | tainted |
23+
| tst.js:6:17:6:37 | req.par ... rName") | semmle.label | req.par ... rName") |
24+
| tst.js:7:15:7:21 | tainted | semmle.label | tainted |
25+
| tst.js:8:16:8:22 | tainted | semmle.label | tainted |
26+
| tst.js:9:17:9:23 | tainted | semmle.label | tainted |
27+
| tst.js:11:8:11:14 | tainted | semmle.label | tainted |
28+
subpaths
4829
#select
4930
| XpathInjectionBad.js:9:34:9:96 | "//user ... text()" | XpathInjectionBad.js:6:18:6:38 | req.par ... rName") | XpathInjectionBad.js:9:34:9:96 | "//user ... text()" | XPath expression depends on a $@. | XpathInjectionBad.js:6:18:6:38 | req.par ... rName") | user-provided value |
5031
| tst2.js:2:27:2:31 | query | tst2.js:1:13:1:34 | documen ... on.hash | tst2.js:2:27:2:31 | query | XPath expression depends on a $@. | tst2.js:1:13:1:34 | documen ... on.hash | user-provided value |

0 commit comments

Comments
 (0)