JS: Add 'prototype pollution in utility function' query#2617
JS: Add 'prototype pollution in utility function' query#2617semmle-qlci merged 17 commits intogithub:masterfrom
Conversation
|
What about the FP rate? You get quite a few results just on |
|
There's a FP in jQuery due to our imprecise treatment of overloading in general. The rest are TPs as far as I can tell (although whether any user-controlled inputs flow there remains TBD). |
|
Re-running the evaluation shows the wall clock timing was a fluke. +1 for tuple counts/DPM. |
esbena
left a comment
There was a problem hiding this comment.
Amazing! I am floored by how elegant and precise this turned out to be.
I do not think any of my comments require a new evaluation, well done.
I am a little surprised, but happy, that I can not find any places that explicitly requires the recursive merge call. My expectation for the query was that the recursive call was a key requirement that had to be explicit.
javascript/ql/src/Security/CWE-400/PrototypePollutionUtility.qhelp
Outdated
Show resolved
Hide resolved
eef0023 to
2245882
Compare
|
Added a change note, and rebased to fix change note conflict. I also changed the CWE numbers. Actually I'd like to move both the prototype pollution queries to CWE-471 (modification of assumed-immutable data) but I think I'll do that in another PR. |
|
Excellent. Two meta tasks:
|
mchammer01
left a comment
There was a problem hiding this comment.
@asgerf - this LGTM.
I have made a few minor comments and leave it up to you to decide whether they are worth addressing. There is a typo (in in) which needs fixed,
Hope this helps!
| One way to cause prototype pollution is through use of an unsafe <em>merge</em> or <em>extend</em> function | ||
| to recursively copy properties from one object to another. | ||
| Such a function has the potential to modify any object reachable from the destination object, and | ||
| the built-in <code>Object.prototype</code> is usually reachable through the special properties |
There was a problem hiding this comment.
Suggesting: is usually reachable through the proto and constructor.prototype special properties.
There was a problem hiding this comment.
Hm, again it's fairly technical and I think it's easier to understand the other way.
javascript/ql/src/Security/CWE-400/PrototypePollutionUtility.qhelp
Outdated
Show resolved
Hide resolved
…help Co-Authored-By: mc <42146119+mchammer01@users.noreply.github.com>
|
Thanks for the review @mchammer01 |
mchammer01
left a comment
There was a problem hiding this comment.
Thanks for the updates @asgerf
Adds a query that looks for recursive merge functions that are susceptible to prototype pollution. It doesn't check for user-controlled inputs.
For example, it flags this function as vulnerable:
It looks for a property enumeration (the
for-inloop above) and a dynamic property write (dst[key] = src[key]above), where three flow paths can be found:keyto the base of the dynamic property writekeyto the property name of the dynamic property writesrc[key]to the right-hand side fo the dynamic property writeIt's relatively expensive as there are a lot of sources and sinks, and the graph pruning does not take into account that we require all three paths to exist. For example, if the base of a dynamic property write is definitely unreachable from a source, it might still try to find paths to the property name and RHS of that property write, even though these paths will never result in an alert.
The latest evaluation shows the first serious conflict I've seen between wall-clock time and tuple counts/DPMs, and I'd like to run a few more evaluations to determine which one tells the truth.