C#: Consider string.ReplaceLineEndings(string) as a sanitizer for log forging.

This commit is contained in:
Michael Nebel
2024-10-21 12:03:59 +02:00
parent 0b8e83dc87
commit b2b1a3ea65
2 changed files with 11 additions and 1 deletions

View File

@@ -354,6 +354,14 @@ class SystemStringClass extends StringType {
result.getReturnType() instanceof StringType
}
/** Gets the `ReplaceLineEndings(string) method. */
Method getReplaceLineEndingsMethod() {
result.getDeclaringType() = this and
result.hasName("ReplaceLineEndings") and
result.getNumberOfParameters() = 1 and
result.getReturnType() instanceof StringType
}
/** Gets a `Format(...)` method. */
Method getFormatMethod() {
result.getDeclaringType() = this and

View File

@@ -70,7 +70,9 @@ private class ExternalLoggingExprSink extends Sink {
private class StringReplaceSanitizer extends Sanitizer {
StringReplaceSanitizer() {
exists(Method m |
exists(SystemStringClass s | m = s.getReplaceMethod() or m = s.getRemoveMethod())
exists(SystemStringClass s |
m = s.getReplaceMethod() or m = s.getRemoveMethod() or m = s.getReplaceLineEndingsMethod()
)
or
m = any(SystemTextRegularExpressionsRegexClass r).getAReplaceMethod()
|