Skip to content

Commit a026120

Browse files
committed
Python: Move configuration over and refine it
The original configuration did not match sinks with sanitizers. Here it is resolved using flow state, it could also be done by using two configurations.
1 parent d539920 commit a026120

File tree

3 files changed

+89
-26
lines changed

3 files changed

+89
-26
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* Provides a taint-tracking configuration for detecting LDAP injection vulnerabilities
3+
*/
4+
5+
import python
6+
import semmle.python.Concepts
7+
import semmle.python.dataflow.new.DataFlow
8+
import semmle.python.dataflow.new.TaintTracking
9+
import semmle.python.dataflow.new.RemoteFlowSources
10+
11+
/**
12+
* A taint-tracking configuration for detecting LDAP injections.
13+
*/
14+
class LDAPInjectionFlowConfig extends TaintTracking::Configuration {
15+
LDAPInjectionFlowConfig() { this = "LDAPInjectionFlowConfig" }
16+
17+
override predicate isSource(DataFlow::Node source, DataFlow::FlowState state) {
18+
source instanceof RemoteFlowSource and
19+
state instanceof Unsafe
20+
}
21+
22+
override predicate isSink(DataFlow::Node sink, DataFlow::FlowState state) {
23+
sink = any(LdapExecution ldap).getBaseDn() and
24+
(state instanceof Unsafe or state instanceof UnsafeForDn)
25+
or
26+
sink = any(LdapExecution ldap).getFilter() and
27+
(state instanceof Unsafe or state instanceof UnsafeForFilter)
28+
}
29+
30+
override predicate isBarrier(DataFlow::Node node, DataFlow::FlowState state) {
31+
// All additional flow steps signify a state change.
32+
// (n, `state`) --> (`node`, s)
33+
// Thus, if a node in `state` transitions to `node` and a new state,
34+
// then `state` should be blocked at `node`.
35+
isAdditionalFlowStep(_, state, node, _)
36+
}
37+
38+
override predicate isAdditionalFlowStep(
39+
DataFlow::Node node1, DataFlow::FlowState state1, DataFlow::Node node2,
40+
DataFlow::FlowState state2
41+
) {
42+
exists(LdapDnEscaping ldapDnEsc |
43+
node1 = ldapDnEsc.getAnInput() and
44+
node2 = ldapDnEsc.getOutput()
45+
|
46+
state1 instanceof Unsafe and
47+
state2 instanceof UnsafeForFilter
48+
or
49+
state1 instanceof UnsafeForDn and
50+
state2 instanceof Safe
51+
)
52+
or
53+
exists(LdapFilterEscaping ldapFilterEsc |
54+
node1 = ldapFilterEsc.getAnInput() and
55+
node2 = ldapFilterEsc.getOutput()
56+
|
57+
state1 instanceof Unsafe and
58+
state2 instanceof UnsafeForDn
59+
or
60+
state1 instanceof UnsafeForFilter and
61+
state2 instanceof Safe
62+
)
63+
}
64+
}
65+
66+
/** A flow satte signifying generally unsafe input. */
67+
class Unsafe extends DataFlow::FlowState {
68+
Unsafe() { this = "Unsafe" }
69+
}
70+
71+
/** A flow state signifying input that is only unsafe for DNs. */
72+
class UnsafeForDn extends DataFlow::FlowState {
73+
UnsafeForDn() { this = "UnsafeForDn" }
74+
}
75+
76+
/** A flow state signifying input that is only unsafe for filter strings. */
77+
class UnsafeForFilter extends DataFlow::FlowState {
78+
UnsafeForFilter() { this = "UnsafeForFilter" }
79+
}
80+
81+
/**
82+
* A flow state that signifies safe input.
83+
* Including this makes `isAdditionalFlowStep` and `isBarrier` simpler.
84+
*/
85+
class Safe extends DataFlow::FlowState {
86+
Safe() { this = "Safe" }
87+
}

python/ql/src/experimental/Security/CWE-090/LDAPInjection.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* @kind path-problem
66
* @problem.severity error
77
* @id py/ldap-injection
8-
* @tags security
8+
* @tags security
99
* external/cwe/cwe-090
1010
*/
1111

1212
// Determine precision above
1313
import python
14-
import experimental.semmle.python.security.injection.LDAP
14+
import semmle.python.security.dataflow.LdapInjection
1515
import DataFlow::PathGraph
1616

1717
from LDAPInjectionFlowConfig config, DataFlow::PathNode source, DataFlow::PathNode sink

python/ql/src/experimental/semmle/python/security/injection/LDAP.qll

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)