1616import python
1717import semmle.python.dataflow.new.DataFlow
1818import semmle.python.dataflow.new.TaintTracking
19- import DataFlow :: PathGraph
19+ import TarSlipImprovFlow :: PathGraph
2020import semmle.python.ApiGraphs
2121import semmle.python.dataflow.new.internal.Attributes
2222import semmle.python.dataflow.new.BarrierGuards
@@ -54,12 +54,10 @@ class AllTarfileOpens extends API::CallNode {
5454/**
5555 * A taint-tracking configuration for detecting more "TarSlip" vulnerabilities.
5656 */
57- class Configuration extends TaintTracking :: Configuration {
58- Configuration ( ) { this = "TarSlip" }
57+ private module TarSlipImprovConfig implements DataFlow :: ConfigSig {
58+ predicate isSource ( DataFlow :: Node source ) { source = tarfileOpen ( ) . getACall ( ) }
5959
60- override predicate isSource ( DataFlow:: Node source ) { source = tarfileOpen ( ) .getACall ( ) }
61-
62- override predicate isSink ( DataFlow:: Node sink ) {
60+ predicate isSink ( DataFlow:: Node sink ) {
6361 (
6462 // A sink capturing method calls to `extractall` without `members` argument.
6563 // For a call to `file.extractall` without `members` argument, `file` is considered a sink.
@@ -100,7 +98,7 @@ class Configuration extends TaintTracking::Configuration {
10098 not sink .getScope ( ) .getLocation ( ) .getFile ( ) .inStdlib ( )
10199 }
102100
103- override predicate isAdditionalTaintStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
101+ predicate isAdditionalFlowStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
104102 nodeTo .( MethodCallNode ) .calls ( nodeFrom , "getmembers" ) and
105103 nodeFrom instanceof AllTarfileOpens
106104 or
@@ -113,7 +111,10 @@ class Configuration extends TaintTracking::Configuration {
113111 }
114112}
115113
116- from Configuration config , DataFlow:: PathNode source , DataFlow:: PathNode sink
117- where config .hasFlowPath ( source , sink )
114+ /** Global taint-tracking for detecting more "TarSlip" vulnerabilities. */
115+ module TarSlipImprovFlow = TaintTracking:: Global< TarSlipImprovConfig > ;
116+
117+ from TarSlipImprovFlow:: PathNode source , TarSlipImprovFlow:: PathNode sink
118+ where TarSlipImprovFlow:: flowPath ( source , sink )
118119select sink , source , sink , "Extraction of tarfile from $@ to a potentially untrusted source $@." ,
119120 source .getNode ( ) , source .getNode ( ) .toString ( ) , sink .getNode ( ) , sink .getNode ( ) .toString ( )
0 commit comments