Skip to content

Commit a59c865

Browse files
committed
let interprocedural analysis handle source-available extension methods for LogForgingLogMessageSink's
1 parent d0c4889 commit a59c865

File tree

4 files changed

+13
-55
lines changed

4 files changed

+13
-55
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
category: minorAnalysis
33
---
4-
* The `cs/log-forging` query no longer treats arguments to user-defined extension methods
5-
on `ILogger` types as sinks. Instead, taint is tracked interprocedurally through extension
6-
method bodies, reducing false positives when extension methods sanitize input internally.
7-
Known framework extension methods (`Microsoft.Extensions.Logging.LoggerExtensions`) are
8-
now modeled as explicit sinks via Models as Data.
4+
* The `cs/log-forging` query no longer treats arguments to extension methods with
5+
source code on `ILogger` types as sinks. Instead, taint is tracked interprocedurally
6+
through extension method bodies, reducing false positives when extension methods
7+
sanitize input internally.

csharp/ql/lib/ext/Microsoft.Extensions.Logging.Sinks.model.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ private import semmle.code.csharp.frameworks.system.text.RegularExpressions
1010
private import semmle.code.csharp.security.Sanitizers
1111
private import semmle.code.csharp.security.dataflow.flowsinks.ExternalLocationSink
1212
private import semmle.code.csharp.dataflow.internal.ExternalFlow
13-
private import semmle.code.csharp.commons.Loggers
1413

1514
/**
1615
* A data flow source for untrusted user input used in log entries.
@@ -54,13 +53,14 @@ private class HtmlSanitizer extends Sanitizer {
5453

5554
/**
5655
* An argument to a call to a method on a logger class, excluding extension methods
57-
* which are analyzed interprocedurally.
56+
* with source code which are analyzed interprocedurally.
5857
*/
59-
private class LogForgingLogMessageSink extends Sink {
58+
private class LogForgingLogMessageSink extends Sink, LogMessageSink {
6059
LogForgingLogMessageSink() {
61-
this.getExpr() = any(LoggerType i).getAMethod().getACall().getAnArgument() or
62-
this.getExpr() =
63-
any(MethodCall call | call.getQualifier().getType() instanceof LoggerType).getAnArgument()
60+
not exists(ExtensionMethodCall mc |
61+
this.getExpr() = mc.getAnArgument() and
62+
mc.getTarget().fromSource()
63+
)
6464
}
6565
}
6666

csharp/ql/test/query-tests/Security Features/CWE-117/LogForging.expected

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
edges
88
| LogForging.cs:18:16:18:23 | access to local variable username : String | LogForging.cs:21:21:21:43 | ... + ... | provenance | |
99
| LogForging.cs:18:16:18:23 | access to local variable username : String | LogForging.cs:31:50:31:72 | ... + ... | provenance | |
10-
| LogForging.cs:18:16:18:23 | access to local variable username : String | LogForging.cs:35:26:35:33 | access to local variable username | provenance | Sink:MaD:1 |
10+
| LogForging.cs:18:16:18:23 | access to local variable username : String | LogForging.cs:35:26:35:33 | access to local variable username | provenance | |
1111
| LogForging.cs:18:16:18:23 | access to local variable username : String | LogForging.cs:40:27:40:49 | ... + ... : String | provenance | |
1212
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:18:16:18:23 | access to local variable username : String | provenance | |
13-
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:18:27:18:61 | access to indexer : String | provenance | MaD:2 |
13+
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:18:27:18:61 | access to indexer : String | provenance | MaD:1 |
1414
| LogForging.cs:18:27:18:61 | access to indexer : String | LogForging.cs:18:16:18:23 | access to local variable username : String | provenance | |
1515
| LogForging.cs:40:27:40:49 | ... + ... : String | LogForging.cs:59:63:59:69 | message : String | provenance | |
1616
| LogForging.cs:59:63:59:69 | message : String | LogForging.cs:61:21:61:27 | access to parameter message | provenance | |
1717
| LogForgingAsp.cs:13:32:13:39 | username : String | LogForgingAsp.cs:17:21:17:43 | ... + ... | provenance | |
1818
models
19-
| 1 | Sink: Microsoft.Extensions.Logging; LoggerExtensions; false; LogError; (Microsoft.Extensions.Logging.ILogger,System.String,System.Object[]); ; Argument[1..2]; log-injection; manual |
20-
| 2 | Summary: System.Collections.Specialized; NameValueCollection; false; get_Item; (System.String); ; Argument[this]; ReturnValue; taint; df-generated |
19+
| 1 | Summary: System.Collections.Specialized; NameValueCollection; false; get_Item; (System.String); ; Argument[this]; ReturnValue; taint; df-generated |
2120
nodes
2221
| LogForging.cs:18:16:18:23 | access to local variable username : String | semmle.label | access to local variable username : String |
2322
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | semmle.label | access to property QueryString : NameValueCollection |

0 commit comments

Comments
 (0)