mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
recognize sanitizing string replace call for regexp-injection
This commit is contained in:
@@ -55,4 +55,27 @@ module RegExpInjection {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A global regexp replacement involving the `{`, `[`, or `+` meta-character, viewed as a sanitizer for
|
||||
* regexp-injection vulnerabilities.
|
||||
*/
|
||||
class MetacharEscapeSanitizer extends Sanitizer, StringReplaceCall {
|
||||
MetacharEscapeSanitizer() {
|
||||
isGlobal() and
|
||||
(
|
||||
RegExp::alwaysMatchesMetaCharacter(getRegExp().getRoot(), ["{", "[", "+"])
|
||||
or
|
||||
// or it's like a wild-card.
|
||||
RegExp::isWildcardLike(getRegExp().getRoot())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Meta characters used in the above sanitizer.
|
||||
*/
|
||||
private class RegexpMetaChars extends RegExp::MetaCharacter {
|
||||
RegexpMetaChars() { this = ["{", "[", "+"] }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user