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

Skip to content

Commit f9eee90

Browse files
committed
fix FP by requiring that the regular expression mention on of the chars important in the prefix
1 parent bd400be commit f9eee90

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ private class DangerousPrefix extends string {
1515
this = "<!--" or
1616
this = "<" + ["iframe", "script", "cript", "scrip", "style"]
1717
}
18+
19+
/**
20+
* Gets a character that is important to the dangerous prefix.
21+
* That is, a char that should be mentioned in a regular expression that explicitly sanitizes the dangerous prefix.
22+
*/
23+
string getAnImportantChar() {
24+
if this = ["/..", "../"] then result = ["/", "."] else result = "<"
25+
}
1826
}
1927

2028
/**
@@ -62,7 +70,11 @@ private DangerousPrefixSubstring getADangerousMatchedChar(EmptyReplaceRegExpTerm
6270
*/
6371
private DangerousPrefix getADangerousMatchedPrefix(EmptyReplaceRegExpTerm t) {
6472
result = getADangerousMatchedPrefixSubstring(t) and
65-
not exists(EmptyReplaceRegExpTerm pred | pred = t.getPredecessor+() and not pred.isNullable())
73+
not exists(EmptyReplaceRegExpTerm pred | pred = t.getPredecessor+() and not pred.isNullable()) and
74+
// the regex must explicitly mention a char important to the prefix.
75+
forex(string char | char = result.getAnImportantChar() |
76+
t.getRootTerm().getAChild*().(RegExpConstant).getValue().matches("%" + char + "%")
77+
)
6678
}
6779

6880
/**

javascript/ql/test/query-tests/Security/CWE-116/IncompleteSanitization/IncompleteMultiCharacterSanitization.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,3 @@
3939
| tst-multi-character-sanitization.js:145:13:145:90 | content ... /g, '') | This string may still contain $@, which may cause an HTML element injection vulnerability. | tst-multi-character-sanitization.js:145:30:145:30 | < | <script |
4040
| tst-multi-character-sanitization.js:148:3:148:99 | n.clone ... gi, '') | This string may still contain $@, which may cause an HTML element injection vulnerability. | tst-multi-character-sanitization.js:148:41:148:41 | < | <script |
4141
| tst-multi-character-sanitization.js:152:3:152:99 | n.clone ... gi, '') | This string may still contain $@, which may cause an HTML element injection vulnerability. | tst-multi-character-sanitization.js:152:41:152:41 | < | <script |
42-
| tst-multi-character-sanitization.js:156:13:156:44 | content ... )/, '') | This string may still contain $@, which may cause an HTML element injection vulnerability. | tst-multi-character-sanitization.js:156:30:156:32 | .+? | <script |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,5 @@
153153
o.push({specified : 1, nodeName : a});
154154
});
155155

156-
content = content.replace(/.+?(?=\s)/, ''); // OK - but flagged as not sanitizing <script> tags [INCONSISTENCY]
156+
content = content.replace(/.+?(?=\s)/, ''); // OK
157157
});

0 commit comments

Comments
 (0)