Skip to content

Commit 0c4e1fc

Browse files
committed
C#: Add testcase with false positive for CWE-117 (overload of String.Relace not correctly recognized as a sanitizer).
1 parent 6713436 commit 0c4e1fc

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public void ProcessRequest(HttpContext ctx)
2121
logger.Warn(username + " logged in");
2222
// GOOD: New-lines removed
2323
logger.Warn(username.Replace(Environment.NewLine, "") + " logged in");
24+
// GOOD: New-lines removed
25+
logger.Warn(username.Replace(Environment.NewLine, "", StringComparison.InvariantCultureIgnoreCase) + " logged in");
2426
// GOOD: Html encoded
2527
logger.Warn(WebUtility.HtmlEncode(username) + " logged in");
2628
// BAD: Logged as-is to TraceSource
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
edges
22
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:18:27:18:61 | access to indexer : String |
33
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:21:21:21:43 | ... + ... |
4-
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:27:50:27:72 | ... + ... |
5-
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:31:26:31:33 | access to local variable username |
4+
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:25:21:25:28 | access to local variable username : String |
5+
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:29:50:29:72 | ... + ... |
6+
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:33:26:33:33 | access to local variable username |
67
| LogForging.cs:18:27:18:61 | access to indexer : String | LogForging.cs:21:21:21:43 | ... + ... |
7-
| LogForging.cs:18:27:18:61 | access to indexer : String | LogForging.cs:27:50:27:72 | ... + ... |
8-
| LogForging.cs:18:27:18:61 | access to indexer : String | LogForging.cs:31:26:31:33 | access to local variable username |
8+
| LogForging.cs:18:27:18:61 | access to indexer : String | LogForging.cs:25:21:25:28 | access to local variable username : String |
9+
| LogForging.cs:18:27:18:61 | access to indexer : String | LogForging.cs:29:50:29:72 | ... + ... |
10+
| LogForging.cs:18:27:18:61 | access to indexer : String | LogForging.cs:33:26:33:33 | access to local variable username |
11+
| LogForging.cs:25:21:25:28 | access to local variable username : String | LogForging.cs:25:21:25:106 | call to method Replace : String |
12+
| LogForging.cs:25:21:25:106 | call to method Replace : String | LogForging.cs:25:21:25:121 | ... + ... |
913
| LogForgingAsp.cs:8:32:8:39 | username : String | LogForgingAsp.cs:12:21:12:43 | ... + ... |
1014
nodes
1115
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | semmle.label | access to property QueryString : NameValueCollection |
1216
| LogForging.cs:18:27:18:61 | access to indexer : String | semmle.label | access to indexer : String |
1317
| LogForging.cs:21:21:21:43 | ... + ... | semmle.label | ... + ... |
14-
| LogForging.cs:27:50:27:72 | ... + ... | semmle.label | ... + ... |
15-
| LogForging.cs:31:26:31:33 | access to local variable username | semmle.label | access to local variable username |
18+
| LogForging.cs:25:21:25:28 | access to local variable username : String | semmle.label | access to local variable username : String |
19+
| LogForging.cs:25:21:25:106 | call to method Replace : String | semmle.label | call to method Replace : String |
20+
| LogForging.cs:25:21:25:121 | ... + ... | semmle.label | ... + ... |
21+
| LogForging.cs:29:50:29:72 | ... + ... | semmle.label | ... + ... |
22+
| LogForging.cs:33:26:33:33 | access to local variable username | semmle.label | access to local variable username |
1623
| LogForgingAsp.cs:8:32:8:39 | username : String | semmle.label | username : String |
1724
| LogForgingAsp.cs:12:21:12:43 | ... + ... | semmle.label | ... + ... |
1825
subpaths
1926
#select
2027
| LogForging.cs:21:21:21:43 | ... + ... | LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:21:21:21:43 | ... + ... | This log entry depends on a $@. | LogForging.cs:18:27:18:49 | access to property QueryString | user-provided value |
21-
| LogForging.cs:27:50:27:72 | ... + ... | LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:27:50:27:72 | ... + ... | This log entry depends on a $@. | LogForging.cs:18:27:18:49 | access to property QueryString | user-provided value |
22-
| LogForging.cs:31:26:31:33 | access to local variable username | LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:31:26:31:33 | access to local variable username | This log entry depends on a $@. | LogForging.cs:18:27:18:49 | access to property QueryString | user-provided value |
28+
| LogForging.cs:25:21:25:121 | ... + ... | LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:25:21:25:121 | ... + ... | This log entry depends on a $@. | LogForging.cs:18:27:18:49 | access to property QueryString | user-provided value |
29+
| LogForging.cs:29:50:29:72 | ... + ... | LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:29:50:29:72 | ... + ... | This log entry depends on a $@. | LogForging.cs:18:27:18:49 | access to property QueryString | user-provided value |
30+
| LogForging.cs:33:26:33:33 | access to local variable username | LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | LogForging.cs:33:26:33:33 | access to local variable username | This log entry depends on a $@. | LogForging.cs:18:27:18:49 | access to property QueryString | user-provided value |
2331
| LogForgingAsp.cs:12:21:12:43 | ... + ... | LogForgingAsp.cs:8:32:8:39 | username : String | LogForgingAsp.cs:12:21:12:43 | ... + ... | This log entry depends on a $@. | LogForgingAsp.cs:8:32:8:39 | username | user-provided value |

0 commit comments

Comments
 (0)