Skip to content
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 new query: js/unclosed-stream #3682

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

esbena
Copy link
Contributor

@esbena esbena commented Jun 11, 2020

CVE-2019-10742: TP/TN

This query is a bit heuristic, but it seems to work out in practice (as in: it only flags the CVE above, and nothing else).

The idea of the query is to look for stream handlers that can be excepted to be invoked as long as there is more data in the stream, once we have such a handler, we check if it "terminates" its enclosing promise without also closing the stream.

Such a termination is problematic since once the enclosing promise is terminated, it seems unlikely that something can close the stream as the stream was "created inside" the promise.

Caveat: this is only truly problematic when an attacker keeps feeding data into the stream, which is exactly why the CVE was assigned.

TODOs later:

@esbena esbena added the JS label Jun 11, 2020
@esbena esbena requested review from mchammer01 and a team as code owners June 11, 2020 08:40
@esbena esbena changed the base branch from master to js-team-sprint June 11, 2020 10:34
erik-krogh
erik-krogh previously approved these changes Jun 12, 2020
@esbena esbena force-pushed the js/hanging-stream branch from e2725dd to 445c294 Compare June 18, 2020 07:14
@esbena esbena added the Awaiting evaluation Do not merge yet, this PR is waiting for an evaluation to finish label Jun 18, 2020
escape = any(DataFlow::CallNode c).getAnArgument()
) and
// no return value
(this.getFunction() instanceof ArrowFunctionExpr or not exists(this.getAReturn())) and
Copy link
Contributor

Choose a reason for hiding this comment

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

We could exclude arrow functions with an explicit return, like () => { ...; return x }

Suggested change
(this.getFunction() instanceof ArrowFunctionExpr or not exists(this.getAReturn())) and
(this.getFunction().getBody() instanceof Expr or not exists(this.getAReturn())) and

Comment on lines +10 to +12
Callback-based input streams generate calls until they are empty or
closed explicitly, and they will take up system resources until
that point in time.
Copy link
Contributor

Choose a reason for hiding this comment

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

If we rephrase this in terms of events, we can avoid inventing non-standard terms:

Suggested change
Callback-based input streams generate calls until they are empty or
closed explicitly, and they will take up system resources until
that point in time.
Input streams in Node.js emit events until they are empty or
closed explicitly, and they will take up system resources until
that point in time.

@esbena
Copy link
Contributor Author

esbena commented Jun 19, 2020

Hmm. I am not sure we should merge this yet, it should be generalized more first. There are simply no remotely interesting results anywhere on LGTM.com to make it worthwhile the computation time at the moment.
Forgetting to close a stream properly used to be a common problem in Java, so I would expect at least some interesting results from this query for JavaScript.

@asgerf
Copy link
Contributor

asgerf commented Jun 23, 2020

Please retarget on master when you have time to look into at this again.

@esbena esbena marked this pull request as draft June 23, 2020 12:27
@esbena esbena changed the base branch from js-team-sprint to master June 23, 2020 12:27
@esbena esbena dismissed erik-krogh’s stale review June 23, 2020 12:27

The base branch was changed.

@adityasharad adityasharad changed the base branch from master to main August 14, 2020 18:34
@esbena
Copy link
Contributor Author

esbena commented Jan 21, 2021

(rebased on top of #4996)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting evaluation Do not merge yet, this PR is waiting for an evaluation to finish documentation JS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants