|
13 | 13 | import java |
14 | 14 | import semmle.code.java.dataflow.FlowSources |
15 | 15 | import semmle.code.java.StringFormat |
16 | | -import DataFlow::PathGraph |
17 | 16 |
|
18 | | -class ExternallyControlledFormatStringConfig extends TaintTracking::Configuration { |
19 | | - ExternallyControlledFormatStringConfig() { this = "ExternallyControlledFormatStringConfig" } |
| 17 | +module ExternallyControlledFormatStringConfig implements DataFlow::ConfigSig { |
| 18 | + predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource } |
20 | 19 |
|
21 | | - override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource } |
22 | | - |
23 | | - override predicate isSink(DataFlow::Node sink) { |
| 20 | + predicate isSink(DataFlow::Node sink) { |
24 | 21 | sink.asExpr() = any(StringFormat formatCall).getFormatArgument() |
25 | 22 | } |
26 | 23 |
|
27 | | - override predicate isSanitizer(DataFlow::Node node) { |
| 24 | + predicate isBarrier(DataFlow::Node node) { |
28 | 25 | node.getType() instanceof NumericType or node.getType() instanceof BooleanType |
29 | 26 | } |
30 | 27 | } |
31 | 28 |
|
| 29 | +module ExternallyControlledFormatStringFlow = |
| 30 | + TaintTracking::Make<ExternallyControlledFormatStringConfig>; |
| 31 | + |
| 32 | +import ExternallyControlledFormatStringFlow::PathGraph |
| 33 | + |
32 | 34 | from |
33 | | - DataFlow::PathNode source, DataFlow::PathNode sink, StringFormat formatCall, |
34 | | - ExternallyControlledFormatStringConfig conf |
35 | | -where conf.hasFlowPath(source, sink) and sink.getNode().asExpr() = formatCall.getFormatArgument() |
| 35 | + ExternallyControlledFormatStringFlow::PathNode source, |
| 36 | + ExternallyControlledFormatStringFlow::PathNode sink, StringFormat formatCall |
| 37 | +where |
| 38 | + ExternallyControlledFormatStringFlow::hasFlowPath(source, sink) and |
| 39 | + sink.getNode().asExpr() = formatCall.getFormatArgument() |
36 | 40 | select formatCall.getFormatArgument(), source, sink, "Format string depends on a $@.", |
37 | 41 | source.getNode(), "user-provided value" |
0 commit comments