Skip to content

Commit a26c01d

Browse files
committed
Go: Add support for pretty-printed provenace in tests. Convert one test.
1 parent 0e8d72c commit a26c01d

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

go/ql/lib/semmle/go/dataflow/ExternalFlow.qll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,44 @@ private import internal.FlowSummaryImpl::Private
8484
private import internal.FlowSummaryImpl::Private::External
8585
private import codeql.mad.ModelValidation as SharedModelVal
8686

87+
/**
88+
* Holds if the given extension tuple `madId` should pretty-print as `model`.
89+
*
90+
* This predicate should only be used in tests.
91+
*/
92+
predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
93+
exists(
94+
string package, string type, boolean subtypes, string name, string signature, string ext,
95+
string output, string kind, string provenance
96+
|
97+
sourceModel(package, type, subtypes, name, signature, ext, output, kind, provenance, madId) and
98+
model =
99+
"Source: " + package + "; " + type + "; " + subtypes + "; " + name + "; " + signature + "; " +
100+
ext + "; " + output + "; " + kind + "; " + provenance
101+
)
102+
or
103+
exists(
104+
string package, string type, boolean subtypes, string name, string signature, string ext,
105+
string input, string kind, string provenance
106+
|
107+
sinkModel(package, type, subtypes, name, signature, ext, input, kind, provenance, madId) and
108+
model =
109+
"Sink: " + package + "; " + type + "; " + subtypes + "; " + name + "; " + signature + "; " +
110+
ext + "; " + input + "; " + kind + "; " + provenance
111+
)
112+
or
113+
exists(
114+
string package, string type, boolean subtypes, string name, string signature, string ext,
115+
string input, string output, string kind, string provenance
116+
|
117+
summaryModel(package, type, subtypes, name, signature, ext, input, output, kind, provenance,
118+
madId) and
119+
model =
120+
"Summary: " + package + "; " + type + "; " + subtypes + "; " + name + "; " + signature + "; " +
121+
ext + "; " + input + "; " + output + "; " + kind + "; " + provenance
122+
)
123+
}
124+
87125
private predicate relevantPackage(string package) {
88126
sourceModel(package, _, _, _, _, _, _, _, _, _) or
89127
sinkModel(package, _, _, _, _, _, _, _, _, _) or

go/ql/test/query-tests/Security/CWE-022/TaintedPath.expected

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
models
2+
| 1 | Summary: net/url; URL; true; Query; ; ; Argument[-1]; ReturnValue; taint; manual |
3+
| 2 | Summary: path; ; false; Clean; ; ; Argument[0]; ReturnValue; taint; manual |
14
edges
2-
| TaintedPath.go:14:18:14:22 | selection of URL | TaintedPath.go:14:18:14:30 | call to Query | provenance | MaD:735 |
5+
| TaintedPath.go:14:18:14:22 | selection of URL | TaintedPath.go:14:18:14:30 | call to Query | provenance | MaD:1 |
36
| TaintedPath.go:14:18:14:30 | call to Query | TaintedPath.go:17:29:17:40 | tainted_path | provenance | |
47
| TaintedPath.go:14:18:14:30 | call to Query | TaintedPath.go:21:57:21:68 | tainted_path | provenance | |
58
| TaintedPath.go:14:18:14:30 | call to Query | TaintedPath.go:68:39:68:56 | ...+... | provenance | |
69
| TaintedPath.go:21:57:21:68 | tainted_path | TaintedPath.go:21:28:21:69 | call to Join | provenance | FunctionModel |
7-
| TaintedPath.go:68:39:68:56 | ...+... | TaintedPath.go:68:28:68:57 | call to Clean | provenance | MaD:761 |
10+
| TaintedPath.go:68:39:68:56 | ...+... | TaintedPath.go:68:28:68:57 | call to Clean | provenance | MaD:2 |
811
nodes
912
| TaintedPath.go:14:18:14:22 | selection of URL | semmle.label | selection of URL |
1013
| TaintedPath.go:14:18:14:30 | call to Query | semmle.label | call to Query |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @kind path-problem
3+
*/
4+
5+
import go
6+
import semmle.go.security.TaintedPath
7+
import codeql.dataflow.test.ProvenancePathGraph
8+
import semmle.go.dataflow.ExternalFlow
9+
import ShowProvenance<interpretModelForTest/2, TaintedPath::Flow::PathNode, TaintedPath::Flow::PathGraph>
10+
11+
from TaintedPath::Flow::PathNode source, TaintedPath::Flow::PathNode sink
12+
where TaintedPath::Flow::flowPath(source, sink)
13+
select sink.getNode(), source, sink, "This path depends on a $@.", source.getNode(),
14+
"user-provided value"

go/ql/test/query-tests/Security/CWE-022/TaintedPath.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)