-
Notifications
You must be signed in to change notification settings - Fork 1.8k
JS: library for recognizing startsWith, includes, endsWith #735
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
Conversation
Evaluation. I'll look into the performance of node and a few others. |
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.
LGTM, modulo minor typos and evaluation.
After another evaluation, perf looks good. |
Conflicts. |
1cd3aa1
to
cf3dfca
Compare
This should be ready to go. |
Looks like my rebasing eliminated the inline fixes from the review. Should be fixed now. |
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.
Two more minor documentation niggles, otherwise lgtm.
/** | ||
* Gets the polarity if the check. | ||
* | ||
* If the polarity is `false` the check returns `true` if the string does not start |
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.
s/start/end/
|
||
/** | ||
* An expression that appears to be part of an `endsWith`-check, that is, | ||
* roughly equivalent to `A.endsWith(B)` or `!A.endsWith(B)`. |
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.
What does "roughly" mean here?
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.
Ah, good catch. I wrote this before I decided to exclude expressions that aren't strictly equivalent to endsWith
, such as A.substr(-B.length) === B
. I've updated the comment.
Add change note announcing generics support
This adds the classes
StringOps::StartsWith
,StringOps::EndsWith
, andStringOps::Includes
for recognizing calls to the corresponding methods and ad-hoc implementations of these.The former two are needed for some improvements to the tainted path query. I don't have an immediately use for the
endsWith
variant, but it's just there for the sake of completeness.There are a few nags to this approach:
indexOf
andincludes
are also array methods.A.indexOf(B) > 1
implies thatA.includes(B)
, but the false outcome does not imply!A.includes(B)
. The current implementation is conservative in this regard and only recognizes instances that are truly equivalent to startsWith/includes/endsWith.EndsWith
is hard to implement. For example,A.substr(-B.length) === B
is almost a correctendsWith
check, except it returnsfalse
ifB
is empty. Some security queries might still want to treat it as an alias forA.endsWith(B)
, though.One day we might want to generalise this to reason about one-sided tests and "nearly correct" tests, but it might just turn into a time sink. For now, this is at least sufficient for the tainted path query improvements I'm working on.
I'm running an evaluation of all security queries due to change to sanitizers.