|
| 1 | +/** |
| 2 | + * @name 'Secure' attribute is not set to true |
| 3 | + * @description Omitting the 'Secure' attribute allows data to be transmitted insecurely |
| 4 | + * using HTTP. Always set 'Secure' to 'true' to ensure that HTTPS |
| 5 | + * is used at all times. |
| 6 | + * @kind problem |
| 7 | + * @problem.severity error |
| 8 | + * @precision high |
| 9 | + * @id rust/insecure-cookie |
| 10 | + * @tags security |
| 11 | + * external/cwe/cwe-319 |
| 12 | + * external/cwe/cwe-614 |
| 13 | + */ |
| 14 | + |
| 15 | +import rust |
| 16 | +import codeql.rust.dataflow.DataFlow |
| 17 | +import codeql.rust.dataflow.TaintTracking |
| 18 | +import InsecureCookieFlow::PathGraph |
| 19 | + |
| 20 | +/** |
| 21 | + * A data flow configuration for tracking values representing cookies without the |
| 22 | + * 'secure' flag set. |
| 23 | + */ |
| 24 | +module InsecureCookieConfig implements DataFlow::ConfigSig { |
| 25 | + predicate isSource(DataFlow::Node node) { |
| 26 | + // creation of a cookie with default settings (insecure) |
| 27 | + exists(CallExprBase ce | |
| 28 | + ce.getStaticTarget().getCanonicalPath() = "<cookie::Cookie>::build" and |
| 29 | + node.asExpr().getExpr() = ce |
| 30 | + ) |
| 31 | + } |
| 32 | + |
| 33 | + predicate isSink(DataFlow::Node node) { |
| 34 | + // qualifier of a call to `.build`. |
| 35 | + exists(MethodCallExpr ce | |
| 36 | + ce.getStaticTarget().getCanonicalPath() = "<cookie::builder::CookieBuilder>::build" and |
| 37 | + node.asExpr().getExpr() = ce.getReceiver() |
| 38 | + ) |
| 39 | + } |
| 40 | + |
| 41 | + predicate observeDiffInformedIncrementalMode() { any() } |
| 42 | +} |
| 43 | + |
| 44 | +module InsecureCookieFlow = TaintTracking::Global<InsecureCookieConfig>; |
| 45 | + |
| 46 | +from InsecureCookieFlow::PathNode sourceNode, InsecureCookieFlow::PathNode sinkNode |
| 47 | +where InsecureCookieFlow::flowPath(sourceNode, sinkNode) |
| 48 | +select sinkNode.getNode(), sourceNode, sinkNode, "Cookie attribute 'Secure' is not set to true." |
0 commit comments