Skip to content

Commit bf197b9

Browse files
committed
Add testcase
1 parent 36bb5f5 commit bf197b9

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import python
2+
import semmle.python.security.TaintTracking
3+
import semmle.python.security.strings.Untrusted
4+
5+
class FooSource extends TaintSource {
6+
FooSource() { this.(CallNode).getFunction().(NameNode).getId() = "foo_source" }
7+
8+
override predicate isSourceOf(TaintKind kind) { kind instanceof UntrustedStringKind }
9+
10+
override string toString() { result = "FooSource" }
11+
}
12+
13+
class FooSink extends TaintSink {
14+
FooSink() {
15+
exists(CallNode call |
16+
call.getFunction().(NameNode).getId() = "foo_sink" and
17+
call.getAnArg() = this
18+
)
19+
}
20+
21+
override predicate sinks(TaintKind kind) { kind instanceof UntrustedStringKind }
22+
23+
override string toString() { result = "FooSink" }
24+
}
25+
26+
class FooConfig extends TaintTracking::Configuration {
27+
FooConfig() { this = "FooConfig" }
28+
29+
override predicate isSource(TaintTracking::Source source) { source instanceof FooSource }
30+
31+
override predicate isSink(TaintTracking::Sink sink) { sink instanceof FooSink }
32+
}
33+
34+
class BarSink extends TaintSink {
35+
BarSink() {
36+
exists(CallNode call |
37+
call.getFunction().(NameNode).getId() = "bar_sink" and
38+
call.getAnArg() = this
39+
)
40+
}
41+
42+
override predicate sinks(TaintKind kind) { kind instanceof UntrustedStringKind }
43+
44+
override string toString() { result = "BarSink" }
45+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.py:16:9:16:20 | foo_source() | test.py:17:14:17:14 | x |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import python
2+
import Config
3+
4+
from FooConfig config, TaintedPathSource src, TaintedPathSink sink
5+
where config.hasFlowPath(src, sink)
6+
select src.getSource(), sink.getSink()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def foo_source():
2+
return 'foo'
3+
4+
5+
def foo_sink(x):
6+
if x == 'foo':
7+
print('fire the foo missiles')
8+
9+
10+
def bar_sink(x):
11+
if x == 'bar':
12+
print('fire the bar missiles')
13+
14+
15+
def should_report():
16+
x = foo_source()
17+
foo_sink(x)
18+
19+
20+
def should_not_report():
21+
x = foo_source()
22+
bar_sink(x)

0 commit comments

Comments
 (0)