-
Notifications
You must be signed in to change notification settings - Fork 1.8k
JS: avoid flagging early returns in js/user-controlled-bypass #315
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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.
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.
This is a very syntactic check. Could we perhaps generalise this a bit using dominance and condition guard nodes?
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.
The syntactic check is quite deliberate as it is intended to whitelist a specific programming pattern.
The use of guard nodes and dominance is part of the Sink-character:
https://github.com/Semmle/ql/blob/16b29b2d08ea9232cad3ff0ab2d31724f66cfe23/javascript/ql/src/semmle/javascript/security/dataflow/ConditionalBypass.qll#L85-L90
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.
It seems to me that this check goes against the intention of the query. You are essentially saying that if it's possible to take a branch that doesn't reach
action
, then we whitelist that. But isn't the whole point of the query to flag cases where user input can causeaction
not to be executed?Perhaps what we really want to exclude here are cases where avoiding
action
causes an abnormal termination of some sort. The proposed approach achieves that in the given example, but surely not in general?I'm thinking of something like this:
Here, we would consider
verify()
to be a sensitive action, and the syntactic pattern looks much like in the example we want to whitelist, except that in this case we wouldn't want to whitelist.As I am writing this, though, I am becoming less and less convinced that I actually understand what this query is meant to flag.
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.
Good point about
break
. I have reformulated the pattern to matchreturn
andthrow
only, see tests.As discussed elsewhere, I have also downgraded the precision of this query to
medium
.