File tree Expand file tree Collapse file tree 3 files changed +52
-1
lines changed
lib/semmle/code/csharp/security
test/query-tests/Security Features/CWE-117 Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,8 @@ class SimpleTypeSanitizedExpr extends DataFlow::ExprNode {
5757 SimpleTypeSanitizedExpr ( ) {
5858 exists ( Type t | t = this .getType ( ) or t = this .getType ( ) .( NullableType ) .getUnderlyingType ( ) |
5959 t instanceof SimpleType or
60- t instanceof SystemDateTimeStruct
60+ t instanceof SystemDateTimeStruct or
61+ t instanceof Enum
6162 )
6263 }
6364}
Original file line number Diff line number Diff line change 1+ ---
2+ category : fix
3+ ---
4+ * Enhanced LogForgingQuery to treat C# Enums as simple types.
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Diagnostics ;
3+ using System . IO ;
4+ using System . Net ;
5+ using System . Web ;
6+ using Microsoft . Extensions . Logging ;
7+
8+ class ILogger
9+ {
10+ public void Warn ( string message ) { }
11+ }
12+
13+ enum TestEnum
14+ {
15+ TestEnumValue
16+ }
17+
18+ public class LogForgingSimpleTypes
19+ {
20+ public void Execute ( HttpContext ctx )
21+ {
22+ // GOOD: int
23+ logger . Warn ( "Logging simple type (int):" 1 ) ;
24+
25+ // GOOD: long
26+ logger . Warn ( "Logging simple type (int):" 1L ) ;
27+
28+ // GOOD: float
29+ logger . Warn ( "Logging simple type (float):" 1.1 ) ;
30+
31+ // GOOD: double
32+ logger . Warn ( "Logging simple type (double):" 1.1d ) ;
33+
34+ // GOOD: decimal
35+ logger . Warn ( "Logging simple type (double):" 1.1m ) ;
36+
37+ // GOOD: Enum
38+ logger . Warn ( "Logging simple type (Enum):" TestEnum. TestEnumVAlue ) ;
39+
40+ // GOOD: DateTime
41+ logger . Warn ( "Logging simple type (int):" new DateTime( ) ) ;
42+
43+ // GOOD: DateTimeOffset
44+ logger . Warn ( "Logging simple type (int):" DateTimeOffset. UtcNow ) ;
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments