@@ -61,13 +61,22 @@ class UnsafeUnpackingConfig extends TaintTracking::Configuration {
6161 }
6262
6363 override predicate isAdditionalTaintStep ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
64+ // Reading the response
65+ nodeTo .( MethodCallNode ) .calls ( nodeFrom , "read" )
66+ or
6467 // Open a file for access
6568 exists ( MethodCallNode cn |
6669 nodeTo = cn .getObject ( ) and
6770 cn .getMethodName ( ) = "open" and
6871 cn .flowsTo ( nodeFrom )
6972 )
7073 or
74+ // Write access
75+ exists ( MethodCallNode cn |
76+ cn .calls ( nodeTo , "write" ) and
77+ nodeFrom = cn .getArg ( 0 )
78+ )
79+ or
7180 // Open a file for access using builtin
7281 nodeFrom = API:: builtin ( "open" ) .getACall ( ) and nodeTo = nodeFrom .( API:: CallNode ) .getArg ( 0 )
7382 or
@@ -76,11 +85,13 @@ class UnsafeUnpackingConfig extends TaintTracking::Configuration {
7685 // see chunks(): https://docs.djangoproject.com/en/4.1/ref/files/uploads/#django.core.files.uploadedfile.UploadedFile.chunks
7786 nodeTo .( MethodCallNode ) .calls ( nodeFrom , [ "getlist" , "get" , "chunks" ] )
7887 or
79- // Reading the response
80- nodeTo .( MethodCallNode ) .calls ( nodeFrom , "read" )
81- or
82- // Accessing the name or raw content
83- nodeTo .( AttrRead ) .accesses ( nodeFrom , [ "name" , "raw" ] )
88+ // Writing the response data to the archive
89+ exists ( Stdlib:: FileLikeObject:: InstanceSource is , Node f , MethodCallNode mc |
90+ is .flowsTo ( f ) and
91+ mc .calls ( f , "write" ) and
92+ nodeFrom = mc .getArg ( 0 ) and
93+ nodeTo = is .( CallCfgNode ) .getArg ( 0 )
94+ )
8495 or
8596 // Considering the use of "fs"
8697 exists ( API:: CallNode fs , MethodCallNode mcn |
@@ -97,22 +108,11 @@ class UnsafeUnpackingConfig extends TaintTracking::Configuration {
97108 nodeTo = mcn
98109 )
99110 or
111+ // Accessing the name or raw content
112+ nodeTo .( AttrRead ) .accesses ( nodeFrom , [ "name" , "raw" ] )
113+ or
100114 // Join the base_dir to the filename
101115 nodeTo = API:: moduleImport ( "os" ) .getMember ( "path" ) .getMember ( "join" ) .getACall ( ) and
102116 nodeFrom = nodeTo .( API:: CallNode ) .getArg ( 1 )
103- or
104- // Write access
105- exists ( MethodCallNode cn |
106- cn .calls ( nodeTo , "write" ) and
107- nodeFrom = cn .getArg ( 0 )
108- )
109- or
110- // Writing the response data to the archive
111- exists ( Stdlib:: FileLikeObject:: InstanceSource is , Node f , MethodCallNode mc |
112- is .flowsTo ( f ) and
113- mc .calls ( f , "write" ) and
114- nodeFrom = mc .getArg ( 0 ) and
115- nodeTo = is .( CallCfgNode ) .getArg ( 0 )
116- )
117117 }
118118}
0 commit comments