Skip to content

Commit 8c87162

Browse files
committed
sync to ruby
1 parent f9eee90 commit 8c87162

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ruby/ql/lib/codeql/ruby/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
/**

0 commit comments

Comments
 (0)