Skip to content

Conversation

ghost
Copy link

@ghost ghost commented Oct 12, 2018

Fixes https://jira.semmle.com/browse/LGTM-2801 by whitelisting the problematic programming pattern.

I have considered lowering the precision of js/user-controlled-bypass to medium several times, so I am not too worried about losing TPs. Tagging as WIP while waiting for a sanity check of the performance.

@ghost ghost added JS WIP This is a work-in-progress, do not merge yet! labels Oct 12, 2018
@ghost ghost self-requested a review as a code owner October 12, 2018 07:45
*
* Example: `if (e) return; action(x)`.
*/
predicate isEarlyAbortGuard(Sink e, SensitiveAction action) {

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?

Copy link
Author

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

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 cause action 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:

while (!verified) {
  if (user-controlled) {
    break;
  }
  verify();
}

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.

Copy link
Author

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 match return and throw only, see tests.
As discussed elsewhere, I have also downgraded the precision of this query to medium.

@ghost
Copy link
Author

ghost commented Oct 16, 2018

Performance is unchanged. A single FP in test code has disappeared.
https://git.semmle.com/esben/dist-compare-reports/tree/js/conditional-bypass-early-return_1539669283308

Copy link

@xiemaisi xiemaisi left a comment

Choose a reason for hiding this comment

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

One minor nit, otherwise LGTM.

@@ -33,6 +33,7 @@
| Remote property injection | Fewer results | The precision of this rule has been revised to "medium". Results are no longer shown on LGTM by default. |
| Missing CSRF middleware | Fewer false-positive results | This rule now recognizes additional CSRF protection middlewares. |
| Server-side URL redirect | More results | This rule now recognizes redirection calls in more cases. |
| User-controlled bypass of security check | Fewer results | This rule no longer flags conditions that guards early returns. The precision of this rule has been revised to "medium". Results are no longer shown on LGTM by default. |

Choose a reason for hiding this comment

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

s/guards/guard/

@ghost
Copy link
Author

ghost commented Oct 16, 2018

Fixed and squashed.
Should we retarget for a patch release (c.f. https://jira.semmle.com/browse/LGTM-2801)?

@xiemaisi
Copy link

Should we retarget for a patch release?

Let's discuss during the meeting.

@xiemaisi xiemaisi removed the WIP This is a work-in-progress, do not merge yet! label Oct 16, 2018
@semmle-qlci semmle-qlci merged commit 1da873e into github:master Oct 17, 2018
aibaars pushed a commit that referenced this pull request Oct 14, 2021
smowton pushed a commit to smowton/codeql that referenced this pull request Apr 16, 2022
Add extension receiver type to function signature in trap file names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants