Skip to content

Commit 84ab860

Browse files
committed
python: rewrite type tracker for ldap operations
There are several other clean ups I would like to do in this file, but this can wait until we promote the query.
1 parent 0654e39 commit 84ab860

File tree

1 file changed

+4
-24
lines changed
  • python/ql/src/experimental/semmle/python/frameworks

1 file changed

+4
-24
lines changed

python/ql/src/experimental/semmle/python/frameworks/LDAP.qll

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ private module Ldap {
2626
API::Node ldapInitialize() { result = ldap().getMember("initialize") }
2727

2828
/** Gets a reference to a `ldap` operation. */
29-
private DataFlow::TypeTrackingNode ldapOperation(DataFlow::TypeTracker t) {
30-
t.start() and
31-
result.(DataFlow::AttrRead).getObject().getALocalSource() = ldapInitialize().getACall()
32-
or
33-
exists(DataFlow::TypeTracker t2 | result = ldapOperation(t2).track(t2, t))
29+
private API::Node ldapOperation(string name) {
30+
result = ldapInitialize().getReturn().getMember(name)
3431
}
3532

3633
/**
@@ -44,24 +41,13 @@ private module Ldap {
4441
}
4542
}
4643

47-
/** Gets a reference to a `ldap` operation. */
48-
private DataFlow::Node ldapOperation() {
49-
ldapOperation(DataFlow::TypeTracker::end()).flowsTo(result)
50-
}
51-
52-
/** Gets a reference to a `ldap` query. */
53-
private DataFlow::Node ldapQuery() {
54-
result = ldapOperation() and
55-
result.(DataFlow::AttrRead).getAttributeName() instanceof Ldap2QueryMethods
56-
}
57-
5844
/**
5945
* A class to find `ldap` methods executing a query.
6046
*
6147
* See `LDAP2QueryMethods`
6248
*/
6349
private class Ldap2Query extends DataFlow::CallCfgNode, LdapQuery::Range {
64-
Ldap2Query() { this.getFunction() = ldapQuery() }
50+
Ldap2Query() { this = ldapOperation(any(Ldap2QueryMethods m)).getACall() }
6551

6652
override DataFlow::Node getQuery() {
6753
result in [this.getArg(0), this.getArg(2), this.getArgByName("filterstr")]
@@ -82,12 +68,6 @@ private module Ldap {
8268
}
8369
}
8470

85-
/** Gets a reference to a `ldap` bind. */
86-
private DataFlow::Node ldapBind() {
87-
result = ldapOperation() and
88-
result.(DataFlow::AttrRead).getAttributeName() instanceof Ldap2BindMethods
89-
}
90-
9171
/**List of SSL-demanding options */
9272
private class LdapSslOptions extends DataFlow::Node {
9373
LdapSslOptions() {
@@ -101,7 +81,7 @@ private module Ldap {
10181
* See `LDAP2BindMethods`
10282
*/
10383
private class Ldap2Bind extends DataFlow::CallCfgNode, LdapBind::Range {
104-
Ldap2Bind() { this.getFunction() = ldapBind() }
84+
Ldap2Bind() { this = ldapOperation(any(Ldap2BindMethods m)).getACall() }
10585

10686
override DataFlow::Node getPassword() {
10787
result in [this.getArg(1), this.getArgByName("cred")]

0 commit comments

Comments
 (0)