Skip to content

Commit d654e98

Browse files
committed
Add empty string as source
1 parent 1a9bfb3 commit d654e98

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

go/ql/src/experimental/CWE-287/ImproperLdapAuth.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,22 @@ class EqualityAsSanitizerGuard extends LdapSanitizer {
6666
}
6767
}
6868

69+
/**
70+
*/
71+
class EmptyString extends DataFlow::Node {
72+
EmptyString() { this.asExpr().getStringValue() = "" }
73+
}
74+
6975
/**
7076
* A taint-tracking configuration for reasoning about when an `UntrustedFlowSource`
7177
* flows into an argument or field that is vulnerable to Improper LDAP Authentication.
7278
*/
7379
class ImproperLdapAuthConfiguration extends TaintTracking::Configuration {
7480
ImproperLdapAuthConfiguration() { this = "Improper LDAP Auth" }
7581

76-
override predicate isSource(DataFlow::Node source) { source instanceof UntrustedFlowSource }
82+
override predicate isSource(DataFlow::Node source) {
83+
source instanceof UntrustedFlowSource or source instanceof EmptyString
84+
}
7785

7886
override predicate isSink(DataFlow::Node sink) { sink instanceof LdapAuthSink }
7987

go/ql/test/experimental/CWE-287/ImproperLdapAuth.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,31 @@ func good2(w http.ResponseWriter, req *http.Request) (interface{}, error) {
6969
}
7070
}
7171

72+
func bad2(req *http.Request) {
73+
// LDAP server details
74+
ldapServer := "ldap.example.com"
75+
ldapPort := 389
76+
bindDN := "cn=admin,dc=example,dc=com"
77+
// BAD : empty password
78+
bindPassword := ""
79+
80+
// Connect to the LDAP server
81+
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldapServer, ldapPort))
82+
if err != nil {
83+
log.Fatalf("Failed to connect to LDAP server: %v", err)
84+
}
85+
defer l.Close()
86+
87+
// BAD : bindPassword is empty
88+
err = l.Bind(bindDN, bindPassword)
89+
if err != nil {
90+
log.Fatalf("LDAP bind failed: %v", err)
91+
}
92+
}
93+
7294
func main() {
7395
bad(nil, nil)
7496
good1(nil, nil)
7597
good2(nil, nil)
98+
bad2(nil, nil)
7699
}

0 commit comments

Comments
 (0)