-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathInsecureSQLConnection.ql
More file actions
56 lines (50 loc) · 1.82 KB
/
InsecureSQLConnection.ql
File metadata and controls
56 lines (50 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @name Insecure SQL connection
* @description Using an SQL Server connection without enforcing encryption is a security vulnerability.
* @kind path-problem
* @id cs/insecure-sql-connection
* @problem.severity error
* @security-severity 7.5
* @precision medium
* @tags security
* external/cwe/cwe-327
*/
import csharp
import InsecureSqlConnection::PathGraph
/**
* A data flow configuration for tracking strings passed to `SqlConnection[StringBuilder]` instances.
*/
module InsecureSqlConnectionConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
exists(string s | s = source.asExpr().(StringLiteral).getValue().toLowerCase() |
s.matches("%encrypt=false%")
or
not s.matches("%encrypt=%")
)
}
predicate isSink(DataFlow::Node sink) {
exists(ObjectCreation oc |
oc.getRuntimeArgument(0) = sink.asExpr() and
(
oc.getType().getName() = "SqlConnectionStringBuilder"
or
oc.getType().getName() = "SqlConnection"
) and
not exists(MemberInitializer mi |
mi = oc.getInitializer().(ObjectInitializer).getAMemberInitializer() and
mi.getLeftOperand().(PropertyAccess).getTarget().getName() = "Encrypt" and
mi.getRightOperand().(BoolLiteral).getValue() = "true"
)
)
}
predicate observeDiffInformedIncrementalMode() { any() }
}
/**
* A data flow configuration for tracking strings passed to `SqlConnection[StringBuilder]` instances.
*/
module InsecureSqlConnection = DataFlow::Global<InsecureSqlConnectionConfig>;
from InsecureSqlConnection::PathNode source, InsecureSqlConnection::PathNode sink
where InsecureSqlConnection::flowPath(source, sink)
select sink.getNode(), source, sink,
"$@ flows to this SQL connection and does not specify `Encrypt=True`.", source.getNode(),
"Connection string"