File tree Expand file tree Collapse file tree 5 files changed +74
-0
lines changed
csharp/ql/test/library-tests/dataflow/flowsources/stored/database/dapper Expand file tree Collapse file tree 5 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ extensions :
2
+
3
+ - addsTo :
4
+ pack : codeql/threat-models
5
+ extensible : threatModelConfiguration
6
+ data :
7
+ - ["database", true, 0]
Original file line number Diff line number Diff line change
1
+ import csharp
2
+ import semmle.code.csharp.security.dataflow.flowsources.FlowSources
3
+ import TestUtilities.InlineFlowTest
4
+ import TaintFlowTest< DatabseConfig >
5
+
6
+ module DatabseConfig implements DataFlow:: ConfigSig {
7
+ predicate isSource ( DataFlow:: Node source ) { source instanceof ThreatModelFlowSource }
8
+
9
+ predicate isSink ( DataFlow:: Node sink ) {
10
+ exists ( MethodCall mc | mc .getTarget ( ) .hasName ( "Sink" ) | sink .asExpr ( ) = mc .getArgument ( 0 ) )
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Data ;
3
+ using System . Data . Entity ;
4
+ using System . Data . SqlClient ;
5
+ using System . Threading . Tasks ;
6
+ using Dapper ;
7
+
8
+ namespace Test
9
+ {
10
+ class UseDapper
11
+ {
12
+ public static void Bad01 ( string connectionString , string query )
13
+ {
14
+ using ( var connection = new SqlConnection ( connectionString ) )
15
+ {
16
+ var result = connection . Query < object > ( query ) ;
17
+ Sink ( result ) ; // $ hasTaintFlow=line:16
18
+ }
19
+ }
20
+
21
+ public static async Task Bad02 ( string connectionString , string query )
22
+ {
23
+ using ( var connection = new SqlConnection ( connectionString ) )
24
+ {
25
+ var result = await connection . QueryAsync < object > ( query ) ;
26
+ Sink ( result ) ; // $ hasTaintFlow=line:25
27
+ }
28
+ }
29
+
30
+ public static void Bad03 ( string connectionString , string query )
31
+ {
32
+ using ( var connection = new SqlConnection ( connectionString ) )
33
+ {
34
+ var result = connection . QueryFirst ( query ) ;
35
+ Sink ( result ) ; // $ hasTaintFlow=line:34
36
+ }
37
+ }
38
+
39
+ public static void Bad04 ( string connectionString , string query )
40
+ {
41
+ using ( var connection = new SqlConnection ( connectionString ) )
42
+ {
43
+ var results = connection . Query < object > ( query ) . AsList ( ) ;
44
+ Sink ( results ) ; // $ hasTaintFlow=line:43
45
+ }
46
+ }
47
+
48
+ public static void Sink ( object o ) { }
49
+ }
50
+ }
Original file line number Diff line number Diff line change
1
+ semmle-extractor-options: /nostdlib /noconfig
2
+ semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../../../resources/stubs/Dapper/2.1.24/Dapper.csproj
3
+ semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../../../resources/stubs/System.Data.SqlClient/4.8.5/System.Data.SqlClient.csproj
4
+ semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../../../resources/stubs/System.Data.SQLite/1.0.118/System.Data.SQLite.csproj
5
+ semmle-extractor-options: ${testdir}/../../../../../../resources/stubs/System.Windows.cs
You can’t perform that action at this time.
0 commit comments