Skip to content

Commit 1e5f846

Browse files
committed
JS: Use StringReplaceCall
1 parent bdb7e3d commit 1e5f846

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

javascript/ql/src/semmle/javascript/StandardLibrary.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ class StringReplaceCall extends DataFlow::MethodCallNode {
121121
*/
122122
DataFlow::Node getRawReplacement() { result = getArgument(1) }
123123

124+
/**
125+
* Gets a function flowing into the second argument of this call to `replace`.
126+
*/
127+
DataFlow::FunctionNode getReplacementCallback() { result = getCallback(1) }
128+
124129
/**
125130
* Holds if this is a global replacement, that is, the first argument is a regular expression
126131
* with the `g` flag.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,8 @@ module TaintTracking {
757757
private predicate staticRegExpCaptureStep(DataFlow::Node pred, DataFlow::Node succ) {
758758
getACaptureSetter(pred) = getANodeReachingCaptureRef(succ)
759759
or
760-
exists(DataFlow::MethodCallNode replace |
761-
replace.getMethodName() = "replace" and
762-
getANodeReachingCaptureRef(succ) = replace.getCallback(1).getFunction().getEntry() and
760+
exists(StringReplaceCall replace |
761+
getANodeReachingCaptureRef(succ) = replace.getReplacementCallback().getFunction().getEntry() and
763762
pred = replace.getReceiver()
764763
)
765764
}

0 commit comments

Comments
 (0)