|
13 | 13 |
|
14 | 14 | import cpp
|
15 | 15 | import semmle.code.cpp.commons.Environment
|
16 |
| -import semmle.code.cpp.ir.dataflow.internal.DefaultTaintTrackingImpl |
17 |
| -import TaintedWithPath |
| 16 | +import semmle.code.cpp.ir.dataflow.TaintTracking |
| 17 | +import semmle.code.cpp.ir.IR |
| 18 | +import Flow::PathGraph |
18 | 19 |
|
19 | 20 | /** A call that prints its arguments to `stdout`. */
|
20 | 21 | class PrintStdoutCall extends FunctionCall {
|
21 |
| - PrintStdoutCall() { |
22 |
| - this.getTarget().hasGlobalOrStdName("puts") or |
23 |
| - this.getTarget().hasGlobalOrStdName("printf") |
24 |
| - } |
| 22 | + PrintStdoutCall() { this.getTarget().hasGlobalOrStdName(["puts", "printf"]) } |
25 | 23 | }
|
26 | 24 |
|
27 | 25 | /** A read of the QUERY_STRING environment variable */
|
28 | 26 | class QueryString extends EnvironmentRead {
|
29 | 27 | QueryString() { this.getEnvironmentVariable() = "QUERY_STRING" }
|
30 | 28 | }
|
31 | 29 |
|
32 |
| -class Configuration extends TaintTrackingConfiguration { |
33 |
| - override predicate isSource(Expr source) { source instanceof QueryString } |
| 30 | +module Config implements DataFlow::ConfigSig { |
| 31 | + predicate isSource(DataFlow::Node node) { node.asExpr() instanceof QueryString } |
34 | 32 |
|
35 |
| - override predicate isSink(Element tainted) { |
36 |
| - exists(PrintStdoutCall call | call.getAnArgument() = tainted) |
| 33 | + predicate isSink(DataFlow::Node node) { |
| 34 | + exists(PrintStdoutCall call | call.getAnArgument() = node.asExpr()) |
37 | 35 | }
|
38 | 36 |
|
39 |
| - override predicate isBarrier(Expr e) { |
40 |
| - super.isBarrier(e) or e.getUnspecifiedType() instanceof IntegralType |
| 37 | + predicate isBarrier(DataFlow::Node node) { |
| 38 | + node.asExpr().getUnspecifiedType() instanceof IntegralType |
41 | 39 | }
|
42 | 40 | }
|
43 | 41 |
|
44 |
| -from QueryString query, Element printedArg, PathNode sourceNode, PathNode sinkNode |
45 |
| -where taintedWithPath(query, printedArg, sourceNode, sinkNode) |
46 |
| -select printedArg, sourceNode, sinkNode, "Cross-site scripting vulnerability due to $@.", query, |
47 |
| - "this query data" |
| 42 | +module Flow = TaintTracking::Global<Config>; |
| 43 | + |
| 44 | +from QueryString query, Flow::PathNode sourceNode, Flow::PathNode sinkNode |
| 45 | +where |
| 46 | + Flow::flowPath(sourceNode, sinkNode) and |
| 47 | + query = sourceNode.getNode().asExpr() |
| 48 | +select sinkNode.getNode(), sourceNode, sinkNode, "Cross-site scripting vulnerability due to $@.", |
| 49 | + query, "this query data" |
0 commit comments