|
1 | 1 | import go |
2 | 2 | import TestUtilities.InlineExpectationsTest |
3 | 3 |
|
| 4 | +predicate isYamlFunction(Function f) { |
| 5 | + f.hasQualifiedName(package("gopkg.in/yaml", ""), _) |
| 6 | + or |
| 7 | + f.(Method).hasQualifiedName(package("gopkg.in/yaml", ""), _, _) |
| 8 | +} |
| 9 | + |
| 10 | +DataFlow::CallNode getAYamlCall() { |
| 11 | + isYamlFunction(result.getACalleeIncludingExternals().asFunction()) |
| 12 | +} |
| 13 | + |
| 14 | +class TaintTransitsFunctionConfig extends TaintTracking::Configuration { |
| 15 | + TaintTransitsFunctionConfig() { this = "TaintTransitsFunctionConfig" } |
| 16 | + |
| 17 | + predicate isSourceSinkPair(DataFlow::Node inNode, DataFlow::Node outNode) { |
| 18 | + exists(DataFlow::CallNode cn | cn = getAYamlCall() | |
| 19 | + inNode = [cn.getAnArgument(), cn.getReceiver()] and |
| 20 | + ( |
| 21 | + outNode.(DataFlow::PostUpdateNode).getPreUpdateNode() = |
| 22 | + [cn.getAnArgument(), cn.getReceiver()] |
| 23 | + or |
| 24 | + outNode = cn.getAResult() |
| 25 | + ) |
| 26 | + ) |
| 27 | + } |
| 28 | + |
| 29 | + override predicate isSource(DataFlow::Node n) { isSourceSinkPair(n, _) } |
| 30 | + |
| 31 | + override predicate isSink(DataFlow::Node n) { isSourceSinkPair(_, n) } |
| 32 | +} |
| 33 | + |
4 | 34 | class TaintFunctionModelTest extends InlineExpectationsTest { |
5 | 35 | TaintFunctionModelTest() { this = "TaintFunctionModelTest" } |
6 | 36 |
|
7 | 37 | override string getARelevantTag() { result = "ttfnmodelstep" } |
8 | 38 |
|
9 | 39 | override predicate hasActualResult(Location location, string element, string tag, string value) { |
10 | 40 | tag = "ttfnmodelstep" and |
11 | | - exists(TaintTracking::FunctionModel model, DataFlow::CallNode call | call = model.getACall() | |
12 | | - call.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), |
13 | | - location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and |
14 | | - element = call.toString() and |
15 | | - value = "\"" + model.getAnInputNode(call) + " -> " + model.getAnOutputNode(call) + "\"" |
| 41 | + ( |
| 42 | + exists(TaintTracking::FunctionModel model, DataFlow::CallNode call | call = model.getACall() | |
| 43 | + call.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), |
| 44 | + location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and |
| 45 | + element = call.toString() and |
| 46 | + value = "\"" + model.getAnInputNode(call) + " -> " + model.getAnOutputNode(call) + "\"" |
| 47 | + ) |
| 48 | + or |
| 49 | + exists(TaintTransitsFunctionConfig config, DataFlow::Node arg, DataFlow::Node output | |
| 50 | + config.hasFlow(arg, output) and |
| 51 | + config.isSourceSinkPair(arg, output) and |
| 52 | + arg.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), |
| 53 | + location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and |
| 54 | + element = arg.toString() and |
| 55 | + value = "\"" + arg + " -> " + output + "\"" |
| 56 | + ) |
16 | 57 | ) |
17 | 58 | } |
18 | 59 | } |
|
0 commit comments