Skip to content

Commit 8822803

Browse files
committed
equalityAsSanitizerGuard and add empty string comment
1 parent 2d387a9 commit 8822803

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,27 @@ private class GoLdapBindSink extends LdapAuthSink {
3636
*/
3737
class RegexpCheckAsBarrierGuard extends RegexpCheckBarrier, LdapSanitizer { }
3838

39+
/**
40+
* An empty string.
41+
*/
42+
class EmptyString extends DataFlow::Node {
43+
EmptyString() { this.asExpr().getStringValue() = "" }
44+
}
45+
3946
private predicate equalityAsSanitizerGuard(DataFlow::Node g, Expr e, boolean outcome) {
40-
exists(DataFlow::Node passwd, DataFlow::EqualityTestNode eq |
47+
exists(DataFlow::Node nonConstNode, DataFlow::Node constNode, DataFlow::EqualityTestNode eq |
4148
g = eq and
42-
passwd = eq.getAnOperand() and
43-
e = passwd.asExpr() and
49+
nonConstNode = eq.getAnOperand() and
50+
not nonConstNode.isConst() and
51+
constNode = eq.getAnOperand() and
52+
constNode.isConst() and
53+
e = nonConstNode.asExpr() and
4454
(
45-
eq.getAnOperand().getStringValue().length() > 0 and outcome = eq.getPolarity()
55+
// If `constNode` is not an empty string a comparison is considered a sanitizer
56+
not constNode instanceof EmptyString and outcome = eq.getPolarity()
4657
or
47-
eq.getAnOperand().getStringValue().length() = 0 and
48-
outcome = eq.getPolarity().booleanNot()
58+
// If `constNode` is an empty string a not comparison is considered a sanitizer
59+
constNode instanceof EmptyString and outcome = eq.getPolarity().booleanNot()
4960
)
5061
)
5162
}
@@ -60,12 +71,6 @@ class EqualityAsSanitizerGuard extends LdapSanitizer {
6071
}
6172
}
6273

63-
/**
64-
*/
65-
class EmptyString extends DataFlow::Node {
66-
EmptyString() { this.asExpr().getStringValue() = "" }
67-
}
68-
6974
/**
7075
* A taint-tracking configuration for reasoning about when an `UntrustedFlowSource`
7176
* flows into an argument or field that is vulnerable to Improper LDAP Authentication.

0 commit comments

Comments
 (0)