File tree Expand file tree Collapse file tree 5 files changed +75
-0
lines changed
src/semmle/python/dataflow
test/library-tests/taint/flowpath_regression Expand file tree Collapse file tree 5 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ module TaintTracking {
5151 */
5252 predicate isSink ( DataFlow:: Node node , TaintKind kind ) {
5353 exists ( TaintSink sink |
54+ this .isSink ( sink ) and
5455 node .asCfgNode ( ) = sink and
5556 sink .sinks ( kind )
5657 )
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ | test.py:16:9:16:20 | foo_source() | test.py:17:14:17:14 | x |
Original file line number Diff line number Diff line change 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 ( )
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments