JS: Manually prune data flow in prototype-pollution-utility#2735
Merged
semmle-qlci merged 4 commits intogithub:masterfrom Feb 5, 2020
Merged
Conversation
erik-krogh
reviewed
Feb 3, 2020
Contributor
Author
|
Looking at this again I realise I made the query depend on an internal API ( |
1d3deaf to
3ccdaa9
Compare
Contributor
Author
|
I've exposed the previously-internal I opted to keep it as a predicate without a receiver or return type as this minimises the chance for breaking changes later. In particular, the type of the invocation node may be loosened when adding flow from property writes into setters. |
esbena
requested changes
Feb 5, 2020
Contributor
esbena
left a comment
There was a problem hiding this comment.
That is a nice surgical improvement.
All of my comments are requests for additional explanation-comments for the changes.
javascript/ql/src/Security/CWE-400/PrototypePollutionUtility.ql
Outdated
Show resolved
Hide resolved
javascript/ql/src/Security/CWE-400/PrototypePollutionUtility.ql
Outdated
Show resolved
Hide resolved
javascript/ql/src/Security/CWE-400/PrototypePollutionUtility.ql
Outdated
Show resolved
Hide resolved
Co-Authored-By: Esben Sparre Andreasen <esbena@github.com>
esbena
approved these changes
Feb 5, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Speeds up the prototype-pollution-utility query by pruning sinks much more aggressively.
To recap: a dynamic write
base[key] = rhspotentially gives rise to three sinks (base,key,rhs). We must find a path to all three sinks for this write to be flagged. However, if one of the sinks is obviously not reachable from a source (e.g. it's a constant), the analysis will still try to find paths to the other sinks, even though they can never lead to an alert.This PR prunes out dynamic writes by doing a bit of preliminary data flow. In particular, we check that
keymight come from a property enumeration andbasemight refer toObject.prototype, which requires flow from a dynamic property read whose key comes from a property enumeration.In this pruning flow, we deliberately do not track flow out of returns because this simply doesn't happen in the cases we're looking for (but we do summarize functions).
Evaluation shows a moderate improvement and we even lose the pesky FP in jQuery.