JS: Use StringReplaceCall

This commit is contained in:
Asger Feldthaus
2020-06-29 09:31:56 +01:00
parent bdb7e3def3
commit 1e5f846168
2 changed files with 7 additions and 3 deletions

View File

@@ -121,6 +121,11 @@ class StringReplaceCall extends DataFlow::MethodCallNode {
*/
DataFlow::Node getRawReplacement() { result = getArgument(1) }
/**
* Gets a function flowing into the second argument of this call to `replace`.
*/
DataFlow::FunctionNode getReplacementCallback() { result = getCallback(1) }
/**
* Holds if this is a global replacement, that is, the first argument is a regular expression
* with the `g` flag.

View File

@@ -757,9 +757,8 @@ module TaintTracking {
private predicate staticRegExpCaptureStep(DataFlow::Node pred, DataFlow::Node succ) {
getACaptureSetter(pred) = getANodeReachingCaptureRef(succ)
or
exists(DataFlow::MethodCallNode replace |
replace.getMethodName() = "replace" and
getANodeReachingCaptureRef(succ) = replace.getCallback(1).getFunction().getEntry() and
exists(StringReplaceCall replace |
getANodeReachingCaptureRef(succ) = replace.getReplacementCallback().getFunction().getEntry() and
pred = replace.getReceiver()
)
}