Skip to content

Commit 4cc2ac9

Browse files
authored
exclude char classes that match everything
1 parent 25d29b2 commit 4cc2ac9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

javascript/ql/src/Security/CWE-116/IncompleteMultiCharacterSanitization.ql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ DangerousPrefixSubstring getADangerousMatchedChar(EmptyReplaceRegExpTerm t) {
6767
or
6868
t.getAMatchedString() = result
6969
or
70-
ReDoSUtil::getCanonicalCharClass(t).(ReDoSUtil::CharacterClass).matches(result) and
71-
result.regexpMatch("\\w")
70+
exists(ReDoSUtil::CharacterClass cc |
71+
cc = ReDoSUtil::getCanonicalCharClass(t) and
72+
cc.matches(result) and
73+
not cc.matches(">")
74+
)
7275
or
7376
t instanceof RegExpDot and
7477
result.length() = 1

javascript/ql/test/query-tests/Security/CWE-116/IncompleteSanitization/tst-multi-character-sanitization.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,5 @@
143143
content = content.replace(/<[a-zA-Z\/](.|\n)*?>/g, '') || ' '; // NOT OK
144144
content = content.replace(/<(script|iframe|video)[\s\S]*?<\/(script|iframe|video)>/g, '') // NOT OK
145145
content = content.replace(/<(script|iframe|video)(.|\s)*?\/(script|iframe|video)>/g, '') // NOT OK
146+
content = content.replace(/<[^<]*>/g, ""); // OK
146147
});

0 commit comments

Comments
 (0)