Skip to content

Commit 1bc16fb

Browse files
jorgectfRasmusWL
andauthored
Apply suggestions from code review
Co-authored-by: Rasmus Wriedt Larsen <[email protected]>
1 parent 64b305c commit 1bc16fb

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

python/ql/src/experimental/Security/CWE-522/LDAPInsecureAuth.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ to be sent in cleartext making it easier for an attacker to intercept it.</p>
1717

1818
<p>The first one sets <code>use_SSL</code> to true as a keyword argument whereas the second one fails to provide a value for it, so
1919
the default one is used (<code>False</code>).</p>
20-
<sample src="LDAPInsecureAuth.py" />
20+
<sample src="examples/LDAPInsecureAuth.py" />
2121
</example>
2222

2323
</qhelp>

python/ql/src/experimental/Security/CWE-522/LDAPInsecureAuth.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @description Python LDAP Insecure LDAP Authentication
44
* @kind path-problem
55
* @problem.severity error
6-
* @id python/insecure-ldap-auth
6+
* @id py/insecure-ldap-auth
77
* @tags experimental
88
* security
99
* external/cwe/cwe-522

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,10 @@ private module LDAP {
115115
initialize = ldapInitialize().getACall() and
116116
(
117117
// ldap_connection.start_tls_s()
118+
// see https://www.python-ldap.org/en/python-ldap-3.3.0/reference/ldap.html#ldap.LDAPObject.start_tls_s
118119
exists(DataFlow::AttrRead startTLS |
119120
startTLS.getObject().getALocalSource() = initialize and
120-
startTLS.getAttributeName().matches("%start_tls%")
121+
startTLS.getAttributeName() = "start_tls_s"
121122
)
122123
or
123124
// ldap_connection.set_option(ldap.OPT_X_TLS_%s, True)

python/ql/src/experimental/semmle/python/security/LDAPInsecureAuth.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class LDAPFullHost extends StrConst {
2323
exists(string s |
2424
s = this.getText() and
2525
s.regexpMatch(getFullHostRegex()) and
26-
not s.substring(7, s.length()).regexpMatch(getPrivateHostRegex()) // No need to check for ldaps, it would be SSL by default.
26+
// check what comes after the `ldap://` prefix
27+
not s.substring(7, s.length()).regexpMatch(getPrivateHostRegex())
2728
)
2829
}
2930
}
@@ -36,7 +37,7 @@ class LDAPPrivateHost extends StrConst {
3637
LDAPPrivateHost() { this.getText().regexpMatch(getPrivateHostRegex()) }
3738
}
3839

39-
predicate concatAndCompareAgainstFullHostRegex(Expr schema, Expr host) {
40+
predicate concatAndCompareAgainstFullHostRegex(LDAPSchema schema, StrConst host) {
4041
schema instanceof LDAPSchema and
4142
not host instanceof LDAPPrivateHost and
4243
exists(string full_host |
@@ -96,6 +97,7 @@ class LDAPInsecureAuthConfig extends TaintTracking::Configuration {
9697

9798
override predicate isSource(DataFlow::Node source) {
9899
source instanceof RemoteFlowSource or
100+
source.asExpr() instanceof LDAPFullHost or
99101
source.asExpr() instanceof LDAPBothStrings or
100102
source.asExpr() instanceof LDAPBothVar or
101103
source.asExpr() instanceof LDAPVarString or

0 commit comments

Comments
 (0)