Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7a90b4

Browse files
committed
JS: Disregard capture groups in lookaround assertions
1 parent 2242df9 commit a7a90b4

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

javascript/ql/src/Security/CWE-020/IncompleteHostnameRegExp.ql

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ import semmle.javascript.CharacterEscapes
1515
import HostnameRegexpShared
1616

1717
/**
18-
* Holds if `term` occurs inside a quantifier or alternative, and thus
19-
* can not be expected to correspond to a unique match.
18+
* Holds if `term` occurs inside a quantifier or alternative (and thus
19+
* can not be expected to correspond to a unique match), or as part of
20+
* a lookaround assertion (which are rarely used for capture groups).
2021
*/
21-
predicate isInsideChoice(RegExpTerm term) {
22+
predicate isInsideChoiceOrSubPattern(RegExpTerm term) {
2223
exists(RegExpParent parent | parent = term.getParent() |
2324
parent instanceof RegExpAlt
2425
or
2526
parent instanceof RegExpQuantifier
2627
or
27-
isInsideChoice(parent)
28+
parent instanceof RegExpSubPattern
29+
or
30+
isInsideChoiceOrSubPattern(parent)
2831
)
2932
}
3033

@@ -33,7 +36,7 @@ predicate isInsideChoice(RegExpTerm term) {
3336
*/
3437
predicate isLikelyCaptureGroup(RegExpGroup group) {
3538
group.isCapture() and
36-
not isInsideChoice(group)
39+
not isInsideChoiceOrSubPattern(group)
3740
}
3841

3942
/**

0 commit comments

Comments
 (0)