Skip to content

Commit b48a07e

Browse files
committed
Tighten up CompareExprSanitizer
- Document - Only actually consider comparisons - Don't sanitize literals
1 parent 3155771 commit b48a07e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

go/ql/src/experimental/CWE-321/HardcodedKeysLib.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,18 @@ module HardcodedKeys {
154154
}
155155

156156
/**
157-
* Mark any comparision expression where any operand is tainted as a
158-
* sanitizer for all instances of the taint
157+
* Sanitizes any other use of an operand to a comparison, on the assumption that this may filter
158+
* out special constant values -- for example, in context `if key != "invalid_key" { ... }`,
159+
* if `"invalid_key"` is indeed the only dangerous key then guarded uses of `key` are likely
160+
* to be safe.
161+
*
162+
* TODO: Before promoting this query look at replacing this with something more principled.
159163
*/
160164
private class CompareExprSanitizer extends Sanitizer {
161165
CompareExprSanitizer() {
162-
exists(BinaryExpr c |
163-
c.getAnOperand().getGlobalValueNumber() = this.asExpr().getGlobalValueNumber()
166+
exists(ComparisonExpr c |
167+
c.getAnOperand().getGlobalValueNumber() = this.asExpr().getGlobalValueNumber() and
168+
not this.asExpr() instanceof Literal
164169
)
165170
}
166171
}

0 commit comments

Comments
 (0)