File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
go/ql/src/experimental/CWE-321 Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments