-
Notifications
You must be signed in to change notification settings - Fork 1.8k
JS: Add steps into static regexp capture group references #3824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS: Add steps into static regexp capture group references #3824
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a better solution than the basic-block based idea I had to solve the same issue 👍
Just some small docstring comments from my end.
I'm also interested in seeing how it scales to larger benchmarks.
Co-authored-by: Erik Krogh Kristensen <erik-krogh@github.com>
exists(DataFlow::MethodCallNode replace | | ||
replace.getMethodName() = "replace" and | ||
getANodeReachingCaptureRef(succ) = replace.getCallback(1).getFunction().getEntry() and | ||
pred = replace.getReceiver() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exists(DataFlow::MethodCallNode replace | | |
replace.getMethodName() = "replace" and | |
getANodeReachingCaptureRef(succ) = replace.getCallback(1).getFunction().getEntry() and | |
pred = replace.getReceiver() | |
) | |
exists(StringReplaceCall replace | | |
getANodeReachingCaptureRef(succ) = replace.getRawReplacement().getFunction().getEntry() and | |
pred = replace.getReceiver() | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd need getALocalSource().(DataFlow::FunctionNode).
in there as well, which was a bit verbose, so I added StringReplaceCall.getReplacementCallback()
instead, PTAL.
Running an evaluation on big-apps. |
Big-apps evaluation went fine. |
@esbena can I get an approve? You're still requesting changes. |
Adds taint steps from regexp matching to a following use of
RegExp.$1
or similar.Note that we don't check if the regexp in the capture group is restrictive enough to sanitize the input. I've (re)created an issue for it here.
Also note that
RegExp.$1
and friends are only assigned to on a successful match. If the match fails, the old values remain. I added test cases to explain this, but couldn't find any real-world examples where this mattered, so I kept it simple by just assuming every match erases the old values, regardless of whether there is a success check.Fixes #3739.