|
| 1 | +import javascript |
| 2 | +import testUtilities.InlineExpectationsTest |
| 3 | +import semmle.javascript.security.TaintedUrlSuffix |
| 4 | + |
| 5 | +module TestConfig implements DataFlow::StateConfigSig { |
| 6 | + class FlowState = DataFlow::FlowLabel; |
| 7 | + |
| 8 | + predicate isSource(DataFlow::Node node, DataFlow::FlowLabel state) { |
| 9 | + node = TaintedUrlSuffix::source() and state = TaintedUrlSuffix::label() |
| 10 | + or |
| 11 | + node instanceof RemoteFlowSource and |
| 12 | + not node = TaintedUrlSuffix::source() and |
| 13 | + state.isTaint() |
| 14 | + } |
| 15 | + |
| 16 | + predicate isSink(DataFlow::Node node, DataFlow::FlowLabel state) { none() } |
| 17 | + |
| 18 | + predicate isSink(DataFlow::Node node) { |
| 19 | + exists(DataFlow::CallNode call | |
| 20 | + call.getCalleeName() = "sink" and |
| 21 | + node = call.getArgument(0) |
| 22 | + ) |
| 23 | + } |
| 24 | + |
| 25 | + predicate isAdditionalFlowStep( |
| 26 | + DataFlow::Node node1, DataFlow::FlowLabel state1, DataFlow::Node node2, |
| 27 | + DataFlow::FlowLabel state2 |
| 28 | + ) { |
| 29 | + TaintedUrlSuffix::step(node1, node2, state1, state2) |
| 30 | + } |
| 31 | + |
| 32 | + predicate isBarrier(DataFlow::Node node, DataFlow::FlowLabel label) { |
| 33 | + TaintedUrlSuffix::isBarrier(node, label) |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +module TestFlow = TaintTracking::GlobalWithState<TestConfig>; |
| 38 | + |
| 39 | +module InlineTest implements TestSig { |
| 40 | + string getARelevantTag() { result = "flow" } |
| 41 | + |
| 42 | + predicate hasActualResult(Location location, string element, string tag, string value) { |
| 43 | + tag = "flow" and |
| 44 | + exists(TestFlow::PathNode src, TestFlow::PathNode sink | TestFlow::flowPath(src, sink) | |
| 45 | + sink.getLocation() = location and |
| 46 | + element = "" and |
| 47 | + value = sink.getState() |
| 48 | + ) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +import MakeTest<InlineTest> |
0 commit comments