File tree Expand file tree Collapse file tree 5 files changed +39
-2
lines changed
semmle/code/csharp/security
test/query-tests/Security Features/CWE-117 Expand file tree Collapse file tree 5 files changed +39
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ category : minorAnalysis
3+ ---
4+ * ` DateTime ` expressions are now considered simple type sanitizers. This affects a wide range of security queries.
Original file line number Diff line number Diff line change @@ -54,7 +54,12 @@ class UrlSanitizedExpr extends Expr {
5454 * An expression node with a simple type.
5555 */
5656class SimpleTypeSanitizedExpr extends DataFlow:: ExprNode {
57- SimpleTypeSanitizedExpr ( ) { this .getType ( ) instanceof SimpleType }
57+ SimpleTypeSanitizedExpr ( ) {
58+ exists ( Type t | t = this .getType ( ) |
59+ t instanceof SimpleType or
60+ t instanceof SystemDateTimeStruct
61+ )
62+ }
5863}
5964
6065/**
Original file line number Diff line number Diff line change 44| LogForging.cs:17:27:17:49 | access to property QueryString : NameValueCollection | LogForging.cs:26:50:26:72 | ... + ... |
55| LogForging.cs:17:27:17:61 | access to indexer : String | LogForging.cs:20:21:20:43 | ... + ... |
66| LogForging.cs:17:27:17:61 | access to indexer : String | LogForging.cs:26:50:26:72 | ... + ... |
7+ | LogForgingAsp.cs:8:32:8:39 | username : String | LogForgingAsp.cs:12:21:12:43 | ... + ... |
78nodes
89| LogForging.cs:17:27:17:49 | access to property QueryString : NameValueCollection | semmle.label | access to property QueryString : NameValueCollection |
910| LogForging.cs:17:27:17:61 | access to indexer : String | semmle.label | access to indexer : String |
1011| LogForging.cs:20:21:20:43 | ... + ... | semmle.label | ... + ... |
1112| LogForging.cs:26:50:26:72 | ... + ... | semmle.label | ... + ... |
13+ | LogForgingAsp.cs:8:32:8:39 | username : String | semmle.label | username : String |
14+ | LogForgingAsp.cs:12:21:12:43 | ... + ... | semmle.label | ... + ... |
1215subpaths
1316#select
1417| LogForging.cs:20:21:20:43 | ... + ... | LogForging.cs:17:27:17:49 | access to property QueryString : NameValueCollection | LogForging.cs:20:21:20:43 | ... + ... | $@ flows to log entry. | LogForging.cs:17:27:17:49 | access to property QueryString | User-provided value |
1518| LogForging.cs:26:50:26:72 | ... + ... | LogForging.cs:17:27:17:49 | access to property QueryString : NameValueCollection | LogForging.cs:26:50:26:72 | ... + ... | $@ flows to log entry. | LogForging.cs:17:27:17:49 | access to property QueryString | User-provided value |
19+ | LogForgingAsp.cs:12:21:12:43 | ... + ... | LogForgingAsp.cs:8:32:8:39 | username : String | LogForgingAsp.cs:12:21:12:43 | ... + ... | $@ flows to log entry. | LogForgingAsp.cs:8:32:8:39 | username | User-provided value |
Original file line number Diff line number Diff line change 1+ using System ;
2+ using Microsoft . AspNetCore . Http ;
3+ using Microsoft . AspNetCore . Http . Headers ;
4+ using Microsoft . AspNetCore . Mvc ;
5+
6+ public class AspController : ControllerBase
7+ {
8+ public void Action1 ( string username )
9+ {
10+ var logger = new ILogger ( ) ;
11+ // BAD: Logged as-is
12+ logger . Warn ( username + " logged in" ) ;
13+ }
14+
15+ public void Action1 ( DateTime date )
16+ {
17+ var logger = new ILogger ( ) ;
18+ // GOOD: DateTime is a sanitizer.
19+ logger . Warn ( $ "Warning about the date: { date : yyyy-MM-dd} ") ;
20+ }
21+ }
Original file line number Diff line number Diff line change 1- semmle-extractor-options: ${testdir}/../../../resources/stubs/System.Web.cs /r:System.Collections.Specialized.dll /r:System.Runtime.Extensions.dll /r:System.Diagnostics.TraceSource.dll
1+ semmle-extractor-options: /nostdlib /noconfig
2+ semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj
3+ semmle-extractor-options: --load-sources-from-project:../../../resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj
4+ semmle-extractor-options: ${testdir}/../../../resources/stubs/System.Web.cs
You can’t perform that action at this time.
0 commit comments