|
| 1 | +import go |
| 2 | +import semmle.go.dataflow.ExternalFlow |
| 3 | +import ModelValidation |
| 4 | +import TestUtilities.InlineExpectationsTest |
| 5 | + |
| 6 | +module SqlTest implements TestSig { |
| 7 | + string getARelevantTag() { result = "query" } |
| 8 | + |
| 9 | + predicate hasActualResult(Location location, string element, string tag, string value) { |
| 10 | + tag = "query" and |
| 11 | + exists(SQL::Query q, SQL::QueryString qs | qs = q.getAQueryString() | |
| 12 | + q.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), |
| 13 | + location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and |
| 14 | + element = q.toString() and |
| 15 | + value = qs.toString() |
| 16 | + ) |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +module QueryString implements TestSig { |
| 21 | + string getARelevantTag() { result = "querystring" } |
| 22 | + |
| 23 | + predicate hasActualResult(Location location, string element, string tag, string value) { |
| 24 | + tag = "querystring" and |
| 25 | + element = "" and |
| 26 | + exists(SQL::QueryString qs | not exists(SQL::Query q | qs = q.getAQueryString()) | |
| 27 | + qs.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), |
| 28 | + location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and |
| 29 | + value = qs.toString() |
| 30 | + ) |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +module Config implements DataFlow::ConfigSig { |
| 35 | + predicate isSource(DataFlow::Node n) { n.asExpr() instanceof StringLit } |
| 36 | + |
| 37 | + predicate isSink(DataFlow::Node n) { |
| 38 | + n = any(DataFlow::CallNode cn | cn.getTarget().getName() = "sink").getAnArgument() |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +module Flow = TaintTracking::Global<Config>; |
| 43 | + |
| 44 | +module TaintFlow implements TestSig { |
| 45 | + string getARelevantTag() { result = "flowfrom" } |
| 46 | + |
| 47 | + predicate hasActualResult(Location location, string element, string tag, string value) { |
| 48 | + tag = "flowfrom" and |
| 49 | + element = "" and |
| 50 | + exists(DataFlow::Node fromNode, DataFlow::Node toNode | |
| 51 | + toNode |
| 52 | + .hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(), |
| 53 | + location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and |
| 54 | + Flow::flow(fromNode, toNode) and |
| 55 | + value = fromNode.asExpr().(StringLit).getValue() |
| 56 | + ) |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +import MakeTest<MergeTests3<SqlTest, QueryString, TaintFlow>> |
0 commit comments