Skip to content

Commit 2ece977

Browse files
authored
Merge pull request #10410 from erik-krogh/nonAsciiRange
JS: don't report every non-ascii range in js/overly-large-range
2 parents d7cdeb8 + 2523946 commit 2ece977

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

java/ql/lib/semmle/code/java/security/OverlyLargeRangeQuery.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ class OverlyWideRange extends RegExpCharacterRange {
9696
toCodePoint("A") <= high
9797
or
9898
// a non-alphanumeric char as part of the range boundaries
99-
exists(int bound | bound = [low, high] | not isAlphanumeric(bound.toUnicode()))
99+
exists(int bound | bound = [low, high] | not isAlphanumeric(bound.toUnicode())) and
100+
// while still being ascii
101+
low < 128 and
102+
high < 128
100103
) and
101104
// allowlist for known ranges
102105
not this = allowedWideRanges()

javascript/ql/lib/semmle/javascript/security/OverlyLargeRangeQuery.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ class OverlyWideRange extends RegExpCharacterRange {
9696
toCodePoint("A") <= high
9797
or
9898
// a non-alphanumeric char as part of the range boundaries
99-
exists(int bound | bound = [low, high] | not isAlphanumeric(bound.toUnicode()))
99+
exists(int bound | bound = [low, high] | not isAlphanumeric(bound.toUnicode())) and
100+
// while still being ascii
101+
low < 128 and
102+
high < 128
100103
) and
101104
// allowlist for known ranges
102105
not this = allowedWideRanges()

javascript/ql/test/query-tests/Security/CWE-020/SuspiciousRegexpRange/tst.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ var numberToLetter = /[7-F]/; // NOT OK
2525
var overlapsWithClass1 = /[0-9\d]/; // NOT OK
2626

2727
var overlapsWithClass2 = /[\w,.-?:*+]/; // NOT OK
28+
29+
var tst2 = /^([-]|[-])+$/; // OK
30+
var tst3 = /[0-9-]/; // OK

python/ql/lib/semmle/python/security/OverlyLargeRangeQuery.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ class OverlyWideRange extends RegExpCharacterRange {
9696
toCodePoint("A") <= high
9797
or
9898
// a non-alphanumeric char as part of the range boundaries
99-
exists(int bound | bound = [low, high] | not isAlphanumeric(bound.toUnicode()))
99+
exists(int bound | bound = [low, high] | not isAlphanumeric(bound.toUnicode())) and
100+
// while still being ascii
101+
low < 128 and
102+
high < 128
100103
) and
101104
// allowlist for known ranges
102105
not this = allowedWideRanges()

ruby/ql/lib/codeql/ruby/security/OverlyLargeRangeQuery.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ class OverlyWideRange extends RegExpCharacterRange {
9696
toCodePoint("A") <= high
9797
or
9898
// a non-alphanumeric char as part of the range boundaries
99-
exists(int bound | bound = [low, high] | not isAlphanumeric(bound.toUnicode()))
99+
exists(int bound | bound = [low, high] | not isAlphanumeric(bound.toUnicode())) and
100+
// while still being ascii
101+
low < 128 and
102+
high < 128
100103
) and
101104
// allowlist for known ranges
102105
not this = allowedWideRanges()

0 commit comments

Comments
 (0)