Skip to content

Commit 5598420

Browse files
committed
C#: Add example of log forging alert for simple nullable types and updated expected test output.
1 parent 696a72a commit 5598420

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ edges
77
| LogForging.cs:18:27:18:61 | access to indexer : String | LogForging.cs:29:50:29:72 | ... + ... |
88
| LogForging.cs:18:27:18:61 | access to indexer : String | LogForging.cs:33:26:33:33 | access to local variable username |
99
| LogForgingAsp.cs:8:32:8:39 | username : String | LogForgingAsp.cs:12:21:12:43 | ... + ... |
10+
| LogForgingAsp.cs:22:35:22:38 | date : Nullable<DateTime> | LogForgingAsp.cs:28:25:28:68 | $"..." |
11+
| LogForgingAsp.cs:32:31:32:31 | b : Nullable<Boolean> | LogForgingAsp.cs:38:25:38:54 | $"..." |
1012
nodes
1113
| LogForging.cs:18:27:18:49 | access to property QueryString : NameValueCollection | semmle.label | access to property QueryString : NameValueCollection |
1214
| LogForging.cs:18:27:18:61 | access to indexer : String | semmle.label | access to indexer : String |
@@ -15,9 +17,15 @@ nodes
1517
| LogForging.cs:33:26:33:33 | access to local variable username | semmle.label | access to local variable username |
1618
| LogForgingAsp.cs:8:32:8:39 | username : String | semmle.label | username : String |
1719
| LogForgingAsp.cs:12:21:12:43 | ... + ... | semmle.label | ... + ... |
20+
| LogForgingAsp.cs:22:35:22:38 | date : Nullable<DateTime> | semmle.label | date : Nullable<DateTime> |
21+
| LogForgingAsp.cs:28:25:28:68 | $"..." | semmle.label | $"..." |
22+
| LogForgingAsp.cs:32:31:32:31 | b : Nullable<Boolean> | semmle.label | b : Nullable<Boolean> |
23+
| LogForgingAsp.cs:38:25:38:54 | $"..." | semmle.label | $"..." |
1824
subpaths
1925
#select
2026
| 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 |
2127
| 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 |
2228
| 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 |
2329
| 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 |
30+
| LogForgingAsp.cs:28:25:28:68 | $"..." | LogForgingAsp.cs:22:35:22:38 | date : Nullable<DateTime> | LogForgingAsp.cs:28:25:28:68 | $"..." | This log entry depends on a $@. | LogForgingAsp.cs:22:35:22:38 | date | user-provided value |
31+
| LogForgingAsp.cs:38:25:38:54 | $"..." | LogForgingAsp.cs:32:31:32:31 | b : Nullable<Boolean> | LogForgingAsp.cs:38:25:38:54 | $"..." | This log entry depends on a $@. | LogForgingAsp.cs:32:31:32:31 | b | user-provided value |

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,24 @@ public void Action1(DateTime date)
1818
// GOOD: DateTime is a sanitizer.
1919
logger.Warn($"Warning about the date: {date:yyyy-MM-dd}");
2020
}
21+
22+
public void Action2(DateTime? date)
23+
{
24+
var logger = new ILogger();
25+
if (date is not null)
26+
{
27+
// GOOD: DateTime? is a sanitizer.
28+
logger.Warn($"Warning about the date: {date:yyyy-MM-dd}");
29+
}
30+
}
31+
32+
public void Action2(bool? b)
33+
{
34+
var logger = new ILogger();
35+
if (b is not null)
36+
{
37+
// GOOD: Boolean? is a sanitizer.
38+
logger.Warn($"Warning about the bool: {b}");
39+
}
40+
}
2141
}

0 commit comments

Comments
 (0)