Skip to content

Commit b2b1a3e

Browse files
committed
C#: Consider string.ReplaceLineEndings(string) as a sanitizer for log forging.
1 parent 0b8e83d commit b2b1a3e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

csharp/ql/lib/semmle/code/csharp/frameworks/System.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,14 @@ class SystemStringClass extends StringType {
354354
result.getReturnType() instanceof StringType
355355
}
356356

357+
/** Gets the `ReplaceLineEndings(string) method. */
358+
Method getReplaceLineEndingsMethod() {
359+
result.getDeclaringType() = this and
360+
result.hasName("ReplaceLineEndings") and
361+
result.getNumberOfParameters() = 1 and
362+
result.getReturnType() instanceof StringType
363+
}
364+
357365
/** Gets a `Format(...)` method. */
358366
Method getFormatMethod() {
359367
result.getDeclaringType() = this and

csharp/ql/lib/semmle/code/csharp/security/dataflow/LogForgingQuery.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ private class ExternalLoggingExprSink extends Sink {
7070
private class StringReplaceSanitizer extends Sanitizer {
7171
StringReplaceSanitizer() {
7272
exists(Method m |
73-
exists(SystemStringClass s | m = s.getReplaceMethod() or m = s.getRemoveMethod())
73+
exists(SystemStringClass s |
74+
m = s.getReplaceMethod() or m = s.getRemoveMethod() or m = s.getReplaceLineEndingsMethod()
75+
)
7476
or
7577
m = any(SystemTextRegularExpressionsRegexClass r).getAReplaceMethod()
7678
|

0 commit comments

Comments
 (0)