Expand log injection sanitizers to annotation regex matches

This commit is contained in:
Owen Mansel-Chan
2026-02-14 08:26:26 +00:00
parent 924bb92d91
commit 9fc95f5171
2 changed files with 15 additions and 8 deletions

View File

@@ -64,11 +64,12 @@ private predicate stringMethodArgumentValueMatches(CompileTimeConstantExpr const
}
/**
* Holds if the return value of `ma` is sanitized against log injection attacks
* by removing line breaks from it.
* Holds if `e` is sanitized against log injection attacks by removing line
* breaks from it.
*/
private predicate logInjectionSanitizer(MethodCall ma) {
exists(CompileTimeConstantExpr target, CompileTimeConstantExpr replacement |
private predicate logInjectionSanitizer(Expr e) {
exists(MethodCall ma, CompileTimeConstantExpr target, CompileTimeConstantExpr replacement |
e = ma and
stringMethodCall(ma, target, replacement) and
not stringMethodArgumentValueMatches(replacement, ["%\n%", "%\r%"])
|
@@ -89,6 +90,13 @@ private predicate logInjectionSanitizer(MethodCall ma) {
target.getStringValue() = ["\n", "\r", "\\n", "\\r", "\\R"]
)
)
or
exists(RegexMatch rm, CompileTimeConstantExpr target |
rm instanceof Annotation and
e = rm.getASanitizedExpr() and
target = rm.getRegex() and
regexPreventsLogInjection(target.getStringValue(), true)
)
}
/**