-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: main
Are you sure you want to change the base?
Conversation
e2725dd
to
445c294
Compare
escape = any(DataFlow::CallNode c).getAnArgument() | ||
) and | ||
// no return value | ||
(this.getFunction() instanceof ArrowFunctionExpr or not exists(this.getAReturn())) and |
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 could exclude arrow functions with an explicit return, like () => { ...; return x }
(this.getFunction() instanceof ArrowFunctionExpr or not exists(this.getAReturn())) and | |
(this.getFunction().getBody() instanceof Expr or not exists(this.getAReturn())) and |
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. |
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.
If we rephrase this in terms of events, we can avoid inventing non-standard terms:
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. |
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. |
Please retarget on |
d4cc58f
to
e592e2b
Compare
(rebased on top of #4996) |
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:
AsyncTerminatableFunction
to handle callback stylegetACallee
with the one in JS: add initial version of ServerCrash.ql #3672