Skip to content

Commit 8d2ae13

Browse files
committed
move String.prototype.match taint step to a general AdditionalTaintStep
1 parent e49b5e4 commit 8d2ae13

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

javascript/ql/src/semmle/javascript/dataflow/TaintTracking.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,23 @@ module TaintTracking {
558558
succ = this
559559
}
560560
}
561+
562+
563+
/**
564+
* A taint propagating data flow edge arising from calling `String.prototype.match()`.
565+
*/
566+
private class StringMatchTaintStep extends AdditionalTaintStep, DataFlow::MethodCallNode {
567+
StringMatchTaintStep() {
568+
this.getMethodName() = "match" and
569+
this.getNumArgument() = 1 and
570+
this.getArgument(0) .analyze().getAType() = TTRegExp()
571+
}
572+
573+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
574+
pred = this.getReceiver() and
575+
succ = this
576+
}
577+
}
561578

562579
/**
563580
* A taint propagating data flow edge arising from JSON unparsing.

javascript/ql/src/semmle/javascript/security/dataflow/ExceptionXss.qll

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,6 @@ module ExceptionXss {
7575
or
7676
pred = any(DataFlow::FunctionNode func).getExceptionalReturn()
7777
)
78-
or
79-
// String.prototype.match()
80-
exists(DataFlow::MethodCallNode call |
81-
call = succ and
82-
pred = call.getReceiver() and
83-
call.getMethodName() = "match" and
84-
call.getNumArgument() = 1 and
85-
// TODO: Better way of detecting regExp / String.prototype.match() calls?
86-
(
87-
call.getArgument(0).getALocalSource().asExpr() instanceof RegExpLiteral or
88-
call.getArgument(0).getALocalSource().(DataFlow::NewNode).getCalleeName() = "RegExp"
89-
)
90-
)
9178
}
9279
}
9380

javascript/ql/test/query-tests/Security/CWE-079/ExceptionXss.expected

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ nodes
3232
| addEventListener.js:12:24:12:33 | event.data |
3333
| addEventListener.js:12:24:12:33 | event.data |
3434
| exception-xss.js:2:9:2:31 | foo |
35+
| exception-xss.js:2:9:2:31 | foo |
36+
| exception-xss.js:2:15:2:31 | document.location |
37+
| exception-xss.js:2:15:2:31 | document.location |
3538
| exception-xss.js:2:15:2:31 | document.location |
3639
| exception-xss.js:2:15:2:31 | document.location |
3740
| exception-xss.js:4:20:4:20 | x |
@@ -75,6 +78,10 @@ nodes
7578
| exception-xss.js:82:10:82:10 | e |
7679
| exception-xss.js:83:18:83:18 | e |
7780
| exception-xss.js:83:18:83:18 | e |
81+
| exception-xss.js:86:17:86:19 | foo |
82+
| exception-xss.js:86:17:86:19 | foo |
83+
| exception-xss.js:86:17:86:19 | foo |
84+
| exception-xss.js:86:17:86:19 | foo |
7885
| jquery.js:2:7:2:40 | tainted |
7986
| jquery.js:2:7:2:40 | tainted |
8087
| jquery.js:2:17:2:33 | document.location |
@@ -743,6 +750,12 @@ edges
743750
| exception-xss.js:2:9:2:31 | foo | exception-xss.js:33:19:33:21 | foo |
744751
| exception-xss.js:2:9:2:31 | foo | exception-xss.js:46:16:46:18 | foo |
745752
| exception-xss.js:2:9:2:31 | foo | exception-xss.js:81:16:81:18 | foo |
753+
| exception-xss.js:2:9:2:31 | foo | exception-xss.js:86:17:86:19 | foo |
754+
| exception-xss.js:2:9:2:31 | foo | exception-xss.js:86:17:86:19 | foo |
755+
| exception-xss.js:2:9:2:31 | foo | exception-xss.js:86:17:86:19 | foo |
756+
| exception-xss.js:2:9:2:31 | foo | exception-xss.js:86:17:86:19 | foo |
757+
| exception-xss.js:2:15:2:31 | document.location | exception-xss.js:2:9:2:31 | foo |
758+
| exception-xss.js:2:15:2:31 | document.location | exception-xss.js:2:9:2:31 | foo |
746759
| exception-xss.js:2:15:2:31 | document.location | exception-xss.js:2:9:2:31 | foo |
747760
| exception-xss.js:2:15:2:31 | document.location | exception-xss.js:2:9:2:31 | foo |
748761
| exception-xss.js:4:20:4:20 | x | exception-xss.js:5:14:5:14 | x |

javascript/ql/test/query-tests/Security/CWE-079/exception-xss.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@
8282
} catch(e) {
8383
$('myId').html(e); // NOT OK!
8484
}
85+
86+
$('myId').html(foo); // Direct leak, reported by other query.
8587
});

0 commit comments

Comments
 (0)