Skip to content

Commit 73ddc05

Browse files
committed
C#: Re-factor InsecureSqlConnection to use the new API.
1 parent 3687770 commit 73ddc05

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

csharp/ql/src/Security Features/CWE-327/InsecureSQLConnection.ql

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,21 @@
1111
*/
1212

1313
import csharp
14-
import DataFlow::PathGraph
14+
import InsecureSqlConnection::PathGraph
1515

1616
/**
1717
* A data flow configuration for tracking strings passed to `SqlConnection[StringBuilder]` instances.
1818
*/
19-
class TaintTrackingConfiguration extends DataFlow::Configuration {
20-
TaintTrackingConfiguration() { this = "TaintTrackingConfiguration" }
21-
22-
override predicate isSource(DataFlow::Node source) {
19+
module InsecureSqlConnectionConfig implements DataFlow::ConfigSig {
20+
predicate isSource(DataFlow::Node source) {
2321
exists(string s | s = source.asExpr().(StringLiteral).getValue().toLowerCase() |
2422
s.matches("%encrypt=false%")
2523
or
2624
not s.matches("%encrypt=%")
2725
)
2826
}
2927

30-
override predicate isSink(DataFlow::Node sink) {
28+
predicate isSink(DataFlow::Node sink) {
3129
exists(ObjectCreation oc |
3230
oc.getRuntimeArgument(0) = sink.asExpr() and
3331
(
@@ -39,8 +37,13 @@ class TaintTrackingConfiguration extends DataFlow::Configuration {
3937
}
4038
}
4139

42-
from TaintTrackingConfiguration c, DataFlow::PathNode source, DataFlow::PathNode sink
43-
where c.hasFlowPath(source, sink)
40+
/**
41+
* A data flow configuration for tracking strings passed to `SqlConnection[StringBuilder]` instances.
42+
*/
43+
module InsecureSqlConnection = DataFlow::Global<InsecureSqlConnectionConfig>;
44+
45+
from InsecureSqlConnection::PathNode source, InsecureSqlConnection::PathNode sink
46+
where InsecureSqlConnection::flowPath(source, sink)
4447
select sink.getNode(), source, sink,
4548
"$@ flows to this SQL connection and does not specify `Encrypt=True`.", source.getNode(),
4649
"Connection string"

0 commit comments

Comments
 (0)