|
| 1 | + |
| 2 | + |
| 3 | +/** |
| 4 | + * @name Untrusted input for a condition |
| 5 | + * @description Using untrusted inputs in a statement that makes a |
| 6 | + * security decision makes code vulnerable to |
| 7 | + * attack. |
| 8 | + * @kind path-problem |
| 9 | + * @problem.severity warning |
| 10 | + * @security-severity 7.5 |
| 11 | + * @precision medium |
| 12 | + * @id cpp/tainted-loop-check |
| 13 | + * @tags security |
| 14 | + * external/cwe/cwe-606 |
| 15 | + */ |
| 16 | + |
| 17 | + import cpp |
| 18 | + import semmle.code.cpp.security.Security |
| 19 | + import semmle.code.cpp.security.FlowSources |
| 20 | + import semmle.code.cpp.ir.dataflow.TaintTracking |
| 21 | + import semmle.code.cpp.ir.IR |
| 22 | + import Flow::PathGraph |
| 23 | + |
| 24 | + predicate sensitiveCondition(Expr condition) { |
| 25 | + exists(ForStmt forstmt | |
| 26 | + forstmt.getCondition().getAChild*() = condition |
| 27 | + ) |
| 28 | + } |
| 29 | + |
| 30 | + |
| 31 | + predicate isSource(FlowSource source, string sourceType) { sourceType = source.getSourceType() } |
| 32 | + |
| 33 | + module Config implements DataFlow::ConfigSig { |
| 34 | + predicate isSource(DataFlow::Node node) { isSource(node, _) } |
| 35 | + |
| 36 | + predicate isSink(DataFlow::Node node) { |
| 37 | + sensitiveCondition(node.asExpr()) |
| 38 | + } |
| 39 | + |
| 40 | + } |
| 41 | + |
| 42 | + module Flow = TaintTracking::Global<Config>; |
| 43 | + |
| 44 | + |
| 45 | + from |
| 46 | + string sourceType, DataFlow::Node source, DataFlow::Node sink, |
| 47 | + Flow::PathNode sourceNode, Flow::PathNode sinkNode |
| 48 | + where |
| 49 | + source = sourceNode.getNode() and |
| 50 | + sink = sinkNode.getNode() and |
| 51 | + isSource(source, sourceType) and |
| 52 | + sensitiveCondition(sink.asExpr()) and |
| 53 | + Flow::flowPath(sourceNode, sinkNode) |
| 54 | + select sink, sourceNode, sinkNode, "Taint data to loop condition" |
0 commit comments