Merge pull request #15367 from michaelnebel/csharp/nullablesimpletypesanitizer

C#: Consider nullable simple types as sanitizers.
This commit is contained in:
Michael Nebel
2024-01-19 09:09:36 +01:00
committed by GitHub
3 changed files with 25 additions and 1 deletions

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* 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.

View File

@@ -55,7 +55,7 @@ class UrlSanitizedExpr extends Expr {
*/
class SimpleTypeSanitizedExpr extends DataFlow::ExprNode {
SimpleTypeSanitizedExpr() {
exists(Type t | t = this.getType() |
exists(Type t | t = this.getType() or t = this.getType().(NullableType).getUnderlyingType() |
t instanceof SimpleType or
t instanceof SystemDateTimeStruct
)

View File

@@ -18,4 +18,24 @@ public class AspController : ControllerBase
// GOOD: DateTime is a sanitizer.
logger.Warn($"Warning about the date: {date:yyyy-MM-dd}");
}
public void Action2(DateTime? date)
{
var logger = new ILogger();
if (date is not null)
{
// GOOD: DateTime? is a sanitizer.
logger.Warn($"Warning about the date: {date:yyyy-MM-dd}");
}
}
public void Action2(bool? b)
{
var logger = new ILogger();
if (b is not null)
{
// GOOD: Boolean? is a sanitizer.
logger.Warn($"Warning about the bool: {b}");
}
}
}