Skip to content

Commit cb53ca4

Browse files
authored
Merge pull request #15367 from michaelnebel/csharp/nullablesimpletypesanitizer
C#: Consider nullable simple types as sanitizers.
2 parents a3c0425 + 9e9b529 commit cb53ca4

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Fixed a Log forging false positive when logging the value of a nullable simple type. This fix also applies to all other queries that use the simple type sanitizer.

csharp/ql/lib/semmle/code/csharp/security/Sanitizers.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class UrlSanitizedExpr extends Expr {
5555
*/
5656
class SimpleTypeSanitizedExpr extends DataFlow::ExprNode {
5757
SimpleTypeSanitizedExpr() {
58-
exists(Type t | t = this.getType() |
58+
exists(Type t | t = this.getType() or t = this.getType().(NullableType).getUnderlyingType() |
5959
t instanceof SimpleType or
6060
t instanceof SystemDateTimeStruct
6161
)

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)