Skip to content

Commit 9082fd2

Browse files
committed
Add taint flow tests for clear
1 parent 109b96f commit 9082fd2

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import "net/http"
4+
5+
func clearTestBad(sourceReq *http.Request) string {
6+
b := make([]byte, 8)
7+
sourceReq.Body.Read(b)
8+
return string(b)
9+
}
10+
11+
func clearTestGood(sourceReq *http.Request) string {
12+
b := make([]byte, 8)
13+
sourceReq.Body.Read(b)
14+
clear(b) // should prevent taint flow
15+
return string(b)
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
edges
2+
| Builtin.go:6:2:6:2 | definition of b | Builtin.go:8:9:8:17 | type conversion |
3+
| Builtin.go:7:2:7:15 | selection of Body | Builtin.go:6:2:6:2 | definition of b |
4+
nodes
5+
| Builtin.go:6:2:6:2 | definition of b | semmle.label | definition of b |
6+
| Builtin.go:7:2:7:15 | selection of Body | semmle.label | selection of Body |
7+
| Builtin.go:8:9:8:17 | type conversion | semmle.label | type conversion |
8+
subpaths
9+
#select
10+
| Builtin.go:8:9:8:17 | type conversion | Builtin.go:7:2:7:15 | selection of Body | Builtin.go:8:9:8:17 | type conversion | Found taint flow |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @description Check that DefaultTaintSanitizer instances prevent taint flow.
3+
* @kind path-problem
4+
*/
5+
6+
import go
7+
8+
module Config implements DataFlow::ConfigSig {
9+
predicate isSource(DataFlow::Node n) { n instanceof UntrustedFlowSource }
10+
11+
predicate isSink(DataFlow::Node n) { any(ReturnStmt s).getAnExpr() = n.asExpr() }
12+
}
13+
14+
module Flow = TaintTracking::Global<Config>;
15+
16+
import Flow::PathGraph
17+
18+
from Flow::PathNode source, Flow::PathNode sink
19+
where Flow::flowPath(source, sink)
20+
select sink.getNode(), source, sink, "Found taint flow"

0 commit comments

Comments
 (0)