Skip to content

Commit b314c54

Browse files
author
Max Schaefer
committed
JavaScript: Track taint through RegExp.prototype.replace.
1 parent 25d06ad commit b314c54

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,27 @@ module TaintTracking {
473473
}
474474
}
475475

476+
/**
477+
* A taint-propagating data flow edge from the first (and only) argument in a call to
478+
* `RegExp.prototype.exec` to its result.
479+
*/
480+
private class RegExpExecTaintStep extends AdditionalTaintStep {
481+
DataFlow::MethodCallNode self;
482+
483+
RegExpExecTaintStep() {
484+
this = self and
485+
self.getReceiver().analyze().getAType() = TTRegExp() and
486+
self.getMethodName() = "exec" and
487+
self.getNumArgument() = 1
488+
}
489+
490+
491+
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
492+
pred = self.getArgument(0) and
493+
succ = this
494+
}
495+
}
496+
476497
/**
477498
* A taint propagating data flow edge arising from JSON unparsing.
478499
*/

javascript/ql/test/library-tests/InterProceduralFlow/TaintTracking.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
| tst.js:2:17:2:22 | "src1" | tst.js:4:15:4:29 | RegExp(source1) |
5151
| tst.js:2:17:2:22 | "src1" | tst.js:5:15:5:33 | new String(source1) |
5252
| tst.js:2:17:2:22 | "src1" | tst.js:6:15:6:33 | new String(source1) |
53+
| tst.js:2:17:2:22 | "src1" | tst.js:11:17:11:20 | m[0] |
5354
| tst.js:2:17:2:22 | "src1" | tst.js:14:15:14:32 | decodeURI(source1) |
5455
| tst.js:2:17:2:22 | "src1" | tst.js:15:15:15:41 | decodeU ... ource1) |
5556
| tst.js:2:17:2:22 | "src1" | tst.js:16:15:16:32 | encodeURI(source1) |

0 commit comments

Comments
 (0)