mirror of
https://github.com/github/codeql.git
synced 2026-04-26 01:05:15 +02:00
Merge pull request #15367 from michaelnebel/csharp/nullablesimpletypesanitizer
C#: Consider nullable simple types as sanitizers.
This commit is contained in:
@@ -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.
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user