1010 * external/cwe/cwe-327
1111 */
1212
13- import csharp
14- import InsecureSqlConnection:: PathGraph
15-
16- class Source extends DataFlow:: Node {
17- string sourcestring ;
18- Source ( ) {
19- sourcestring = this .asExpr ( ) .( StringLiteral ) .getValue ( ) .toLowerCase ( ) and
20- (
21- not sourcestring .matches ( "%encrypt=%" ) or
22- sourcestring .matches ( "%encrypt=false%" )
23- )
24- }
25- predicate setsEncryptFalse ( ) {
26- sourcestring .matches ( "%encrypt=false%" )
27- }
28- }
29-
30- class Sink extends DataFlow:: Node {
31- Version version ;
32- Sink ( ) {
33- exists ( ObjectCreation oc |
34- oc .getRuntimeArgument ( 0 ) = this .asExpr ( ) and
35- (
36- oc .getType ( ) .getName ( ) = "SqlConnectionStringBuilder"
37- or
38- oc .getType ( ) .getName ( ) = "SqlConnection"
39- ) and
40- version = oc .getType ( ) .getALocation ( ) .( Assembly ) .getVersion ( )
41- )
42- }
43- predicate isEncryptedByDefault ( ) {
44- version .compareTo ( "4.0" ) >= 0
45- }
46- }
47-
48- predicate isEncryptTrue ( Source source , Sink sink ) {
49- sink .isEncryptedByDefault ( ) and
50- not source .setsEncryptFalse ( )
51- }
52-
53- /**
54- * A data flow configuration for tracking strings passed to `SqlConnection[StringBuilder]` instances.
55- */
56- module InsecureSqlConnectionConfig implements DataFlow:: ConfigSig {
57- predicate isSource ( DataFlow:: Node source ) {
58- source instanceof Source
59- }
60-
61- predicate isSink ( DataFlow:: Node sink ) {
62- sink instanceof Sink
63- }
64- }
65-
66- /**
67- * A data flow configuration for tracking strings passed to `SqlConnection[StringBuilder]` instances.
68- */
69- module InsecureSqlConnection = DataFlow:: Global< InsecureSqlConnectionConfig > ;
70-
71- from InsecureSqlConnection:: PathNode source , InsecureSqlConnection:: PathNode sink
72- where InsecureSqlConnection:: flowPath ( source , sink ) and
73- not isEncryptTrue ( source .getNode ( ) .( Source ) , sink .getNode ( ) .( Sink ) )
74- select sink .getNode ( ) , source , sink ,
75- "$@ flows to this SQL connection and does not specify `Encrypt=True`." , source .getNode ( ) ,
76- "Connection string"
77-
13+ import csharp
14+ import InsecureSqlConnection:: PathGraph
15+
16+ class Source extends DataFlow:: Node {
17+ string sourcestring ;
18+
19+ Source ( ) {
20+ sourcestring = this .asExpr ( ) .( StringLiteral ) .getValue ( ) .toLowerCase ( ) and
21+ (
22+ not sourcestring .matches ( "%encrypt=%" ) or
23+ sourcestring .matches ( "%encrypt=false%" )
24+ )
25+ }
26+
27+ predicate setsEncryptFalse ( ) { sourcestring .matches ( "%encrypt=false%" ) }
28+ }
29+
30+ class Sink extends DataFlow:: Node {
31+ Version version ;
32+
33+ Sink ( ) {
34+ exists ( ObjectCreation oc |
35+ oc .getRuntimeArgument ( 0 ) = this .asExpr ( ) and
36+ (
37+ oc .getType ( ) .getName ( ) = "SqlConnectionStringBuilder"
38+ or
39+ oc .getType ( ) .getName ( ) = "SqlConnection"
40+ ) and
41+ version = oc .getType ( ) .getALocation ( ) .( Assembly ) .getVersion ( )
42+ )
43+ }
44+
45+ predicate isEncryptedByDefault ( ) { version .compareTo ( "4.0" ) >= 0 }
46+ }
47+
48+ predicate isEncryptTrue ( Source source , Sink sink ) {
49+ sink .isEncryptedByDefault ( ) and
50+ not source .setsEncryptFalse ( )
51+ }
52+
53+ /**
54+ * A data flow configuration for tracking strings passed to `SqlConnection[StringBuilder]` instances.
55+ */
56+ module InsecureSqlConnectionConfig implements DataFlow:: ConfigSig {
57+ predicate isSource ( DataFlow:: Node source ) { source instanceof Source }
58+
59+ predicate isSink ( DataFlow:: Node sink ) { sink instanceof Sink }
60+ }
61+
62+ /**
63+ * A data flow configuration for tracking strings passed to `SqlConnection[StringBuilder]` instances.
64+ */
65+ module InsecureSqlConnection = DataFlow:: Global< InsecureSqlConnectionConfig > ;
66+
67+ from InsecureSqlConnection:: PathNode source , InsecureSqlConnection:: PathNode sink
68+ where
69+ InsecureSqlConnection:: flowPath ( source , sink ) and
70+ not isEncryptTrue ( source .getNode ( ) .( Source ) , sink .getNode ( ) .( Sink ) )
71+ select sink .getNode ( ) , source , sink ,
72+ "$@ flows to this SQL connection and does not specify `Encrypt=True`." , source .getNode ( ) ,
73+ "Connection string"
0 commit comments