Skip to content

JS: Add library input as source to js/prototype-polluting-assignment#5908

Merged
erik-krogh merged 17 commits intogithub:mainfrom
erik-krogh:protoLib
Nov 11, 2021
Merged

JS: Add library input as source to js/prototype-polluting-assignment#5908
erik-krogh merged 17 commits intogithub:mainfrom
erik-krogh:protoLib

Conversation

@erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented May 17, 2021

I did an investigation into some prototype related vulnerabilities where I checked which CVEs we could flag by adding library inputs to js/prototype-polluting-assignment.
I didn’t expect much to come from that, but I found 23 CVEs that were flagged using this approach, so now I want to see if that could get merged.

A run across a bunch of projects definitely reveals some noise.
But I had expected worse, so I think it's OK for this warning query.
(But maybe we should lower the precision?)

Performance evaluation looks OK.

Most of the commits (after the initial commit) added one TP or TN to the list of CVEs below.

Edit: It's likely that the current PR does not flag all the below CVEs.
I'll look into which are flagged after the PR has been merged.

CVEs (23):

TP/TN (14): CVE-2020-7724, CVE-2020-7600, CVE-2019-10792, CVE-2020-7638, CVE-2020-8203, CVE-2020-7720, CVE-2020-7788, CVE-2021-25912, CVE-2020-28273, CVE-2020-7774, CVE-2020-28448, CVE-2020-7708, CVE-2019-10806, CVE-2020-7709
TP (9): CVE-2020-7701, CVE-2018-16490, CVE-2020-15256, CVE-2020-28460, CVE-2020-7707, CVE-2020-28268, CVE-2021-23434, CVE-2021-3805, CVE-2020-28282


There are other CVEs that basically boil down to:

export function myGetter(name) {
  return obj[name]; // <- name can be "__proto__", this is just a small gadget in a larger exploit. 
}

I don't think we will ever flag those without getting way to much noise.

@erik-krogh erik-krogh marked this pull request as ready for review May 17, 2021 13:34
@erik-krogh erik-krogh requested a review from a team as a code owner May 17, 2021 13:34
Copy link
Contributor

@asgerf asgerf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the refactorings and sanitizer improvements, but I'm worried about making this query more noisy than it already is.

Some of the paths in the linked query console run start at a parameter but then uses a return step to flow out of the library function to some other library code. These are clearly not interesting as it does not represent an external user calling the library. I seem remember you did something to exclude such paths in other contexts, but I'm not sure if it applies to this query? I'd say we should get that working for this query, if we're to go ahead with this.

strictcount(root.getALeaf()) = 2 and
root.getALeaf().getStringValue() = ""
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have ConcatenationNode.isCoercion() for this

@erik-krogh
Copy link
Contributor Author

I seem remember you did something to exclude such paths in other contexts, but I'm not sure if it applies to this query? I'd say we should get that working for this query, if we're to go ahead with this.

I did exclude such paths in other "library-input" queries, but I forgot to add it here.
It's an extremely simple addition, but it requires another performance evaluation (I'll get that going).
The change might remove some CVE TPs, but I'll look at that after merge.

@erik-krogh
Copy link
Contributor Author

but it requires another performance evaluation (I'll get that going).

New evaluation done.
Performance is still OK (given that it's single-query performance).
And there are about half the number of new results, so it seems to have removed a decent amount of noise.

@asgerf
Copy link
Contributor

asgerf commented Oct 1, 2021

Unfortunately the results still seem very noisy.

In addition to #6789, I'd suggest excluding sinks that aren't dynamic property assignments when the source was a library input (by restricting valid source/sink pairs after the data flow paths have been found). That might bring it down to reasonable levels.

@erik-krogh
Copy link
Contributor Author

erik-krogh commented Oct 27, 2021

In addition to #6789, I'd suggest excluding sinks that aren't dynamic property assignments when the source was a library input (by restricting valid source/sink pairs after the data flow paths have been found). That might bring it down to reasonable levels.

I've implemented it.
I like the suggestion, and I don't think it will cause many FPs.
(I've rebased on top of main and started a new evaluation).

@erik-krogh
Copy link
Contributor Author

The new evaluation looks better.
Still a bit noisy, but less than before.

@asgerf
Copy link
Contributor

asgerf commented Nov 3, 2021

Ok it's getting close but I think we go the extra mile to cut down the remaining FPs.

I've opened #7044 which fixes the FPs in angular and relay.

@erik-krogh
Copy link
Contributor Author

Do you want another evaluation now that I've merged in #7044?

@asgerf
Copy link
Contributor

asgerf commented Nov 8, 2021

Yes, please.

@erik-krogh
Copy link
Contributor Author

Yes, please.

New evaluation is ready.

Copy link
Contributor

@asgerf asgerf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I think the results look reasonable now. Apart from a nit in the change note LGTM now.

Co-authored-by: Asger F <asgerf@github.com>
@erik-krogh erik-krogh merged commit 891694b into github:main Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants