File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
src/queries/security/cwe-020
test/query-tests/security/cwe-020/SuspiciousRegexpRange Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 13
13
14
14
import codeql.ruby.security.SuspiciousRegexpRangeQuery
15
15
16
+ RegExpCharacterClass potentialMisparsedCharClass ( ) {
17
+ // some escapes, e.g. [\000-\037] are currently misparsed.
18
+ result .getAChild ( ) .( RegExpNormalChar ) .getValue ( ) = "\\"
19
+ or
20
+ // nested char classes are currently misparsed
21
+ result .getAChild ( ) .( RegExpNormalChar ) .getValue ( ) = "["
22
+ }
23
+
16
24
from RegExpCharacterRange range , string reason
17
- where problem ( range , reason )
25
+ where
26
+ problem ( range , reason ) and
27
+ not range .getParent ( ) = potentialMisparsedCharClass ( )
18
28
select range , "Suspicious character range that " + reason + "."
Original file line number Diff line number Diff line change 8
8
9
9
printable = /[!-~]/ # OK - used to select most printable ASCII characters
10
10
11
- codePoints = /[^\x21 -\x7E ]|[[\] (){}<>/ %] /g # OK
11
+ codePoints = /[^\x21 -\x7E ]|[\ [\] (){}<>\ / %]/ # OK
12
12
13
- NON_ALPHANUMERIC_REGEXP = /([^\# -~| |!])/g # OK
13
+ NON_ALPHANUMERIC_REGEXP = /([^\# -~| |!])/ # OK
14
14
15
15
smallOverlap = /[0-9a-fA-f]/ # NOT OK
16
16
25
25
overlapsWithClass1 = /[0-9\d ]/ # NOT OK
26
26
27
27
overlapsWithClass2 = /[\w ,.-?:*+]/ # NOT OK
28
+
29
+ escapes = /[\000 -\037 \047 \134 \177 -\377 ]/n # OK - they are escapes
30
+
31
+ nested = /[a-z&&[^a-c]]/ # OK
You can’t perform that action at this time.
0 commit comments