@@ -4,17 +4,14 @@ import go
4
4
* The File system access sinks of `net/http` package
5
5
*/
6
6
class HttpServeFile extends FileSystemAccess:: Range , DataFlow:: CallNode {
7
- int pathArg ;
8
-
9
7
HttpServeFile ( ) {
10
8
exists ( Function f |
11
9
f .hasQualifiedName ( "net/http" , "ServeFile" ) and
12
- this = f .getACall ( ) and
13
- pathArg = 2
10
+ this = f .getACall ( )
14
11
)
15
12
}
16
13
17
- override DataFlow:: Node getAPathArgument ( ) { result = this .getArgument ( pathArg ) }
14
+ override DataFlow:: Node getAPathArgument ( ) { result = this .getArgument ( 2 ) }
18
15
}
19
16
20
17
/**
@@ -42,7 +39,7 @@ class BeegoFileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode
42
39
}
43
40
44
41
/**
45
- * Provide File system access sinks of [beego](https://github.com/beego/beego) web framework
42
+ * The File system access sinks of [beego](https://github.com/beego/beego) web framework
46
43
*/
47
44
class EchoFileSystemAccess extends FileSystemAccess:: Range , DataFlow:: CallNode {
48
45
int pathArg ;
@@ -128,75 +125,65 @@ class FiberSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode {
128
125
129
126
/**
130
127
* Provide File system access sinks of [afero](https://github.com/spf13/afero) framework
131
- * The Types that are not vulnerable: `afero.BasePathFs` and `afero.IOFS`
132
128
*/
133
129
module Afero {
134
- string aferoPackage ( ) { result = "github.com/spf13/afero" }
130
+ string aferoPackage ( ) { result = package ( "github.com/spf13/afero" , "" ) }
135
131
136
132
/**
137
- * Provide File system access sinks of [afero](https://github.com/spf13/afero) framework methods
133
+ * The File system access sinks of [afero](https://github.com/spf13/afero) framework methods
138
134
*/
139
135
class AferoSystemAccess extends FileSystemAccess:: Range , DataFlow:: CallNode {
140
- int pathArg ;
141
-
142
136
AferoSystemAccess ( ) {
143
137
exists ( Method f |
144
- f .hasQualifiedName ( package ( aferoPackage ( ) , "" ) , "HttpFs" ,
138
+ f .hasQualifiedName ( aferoPackage ( ) , "HttpFs" ,
145
139
[ "Create" , "Open" , "OpenFile" , "Remove" , "RemoveAll" ] ) and
146
- this = f .getACall ( ) and
147
- pathArg = 0
140
+ this = f .getACall ( )
148
141
or
149
- f .hasQualifiedName ( package ( aferoPackage ( ) , "" ) , "RegexpFs" ,
142
+ f .hasQualifiedName ( aferoPackage ( ) , "RegexpFs" ,
150
143
[ "Create" , "Open" , "OpenFile" , "Remove" , "RemoveAll" , "Mkdir" , "MkdirAll" ] ) and
151
- this = f .getACall ( ) and
152
- pathArg = 0
144
+ this = f .getACall ( )
153
145
or
154
- f .hasQualifiedName ( package ( aferoPackage ( ) , "" ) , "ReadOnlyFs" ,
146
+ f .hasQualifiedName ( aferoPackage ( ) , "ReadOnlyFs" ,
155
147
[ "Create" , "Open" , "OpenFile" , "ReadDir" , "ReadlinkIfPossible" , "Mkdir" , "MkdirAll" ] ) and
156
- this = f .getACall ( ) and
157
- pathArg = 0
148
+ this = f .getACall ( )
158
149
or
159
- f .hasQualifiedName ( package ( aferoPackage ( ) , "" ) , "OsFs" ,
150
+ f .hasQualifiedName ( aferoPackage ( ) , "OsFs" ,
160
151
[
161
152
"Create" , "Open" , "OpenFile" , "ReadlinkIfPossible" , "Remove" , "RemoveAll" , "Mkdir" ,
162
153
"MkdirAll"
163
154
] ) and
164
- this = f .getACall ( ) and
165
- pathArg = 0
155
+ this = f .getACall ( )
166
156
or
167
- f .hasQualifiedName ( package ( aferoPackage ( ) , "" ) , "MemMapFs" ,
157
+ f .hasQualifiedName ( aferoPackage ( ) , "MemMapFs" ,
168
158
[ "Create" , "Open" , "OpenFile" , "Remove" , "RemoveAll" , "Mkdir" , "MkdirAll" ] ) and
169
- this = f .getACall ( ) and
170
- pathArg = 0
159
+ this = f .getACall ( )
171
160
)
172
161
}
173
162
174
- override DataFlow:: Node getAPathArgument ( ) { result = this .getArgument ( pathArg ) }
163
+ override DataFlow:: Node getAPathArgument ( ) { result = this .getArgument ( 0 ) }
175
164
}
176
165
177
166
/**
178
- * Provide File system access sinks of [afero](https://github.com/spf13/afero) framework utility functions
167
+ * The File system access sinks of [afero](https://github.com/spf13/afero) framework utility functions
168
+ *
179
169
* The Types that are not vulnerable: `afero.BasePathFs` and `afero.IOFS`
180
170
*/
181
171
class AferoUtilityFunctionSystemAccess extends FileSystemAccess:: Range , DataFlow:: CallNode {
182
- int pathArg ;
183
-
184
172
AferoUtilityFunctionSystemAccess ( ) {
185
173
// utility functions
186
174
exists ( Function f |
187
- f .hasQualifiedName ( package ( aferoPackage ( ) , "" ) ,
175
+ f .hasQualifiedName ( aferoPackage ( ) ,
188
176
[ "WriteReader" , "SafeWriteReader" , "WriteFile" , "ReadFile" , "ReadDir" ] ) and
189
177
this = f .getACall ( ) and
190
- pathArg = 1 and
191
178
not aferoSanitizer ( this .getArgument ( 0 ) )
192
179
)
193
180
}
194
181
195
- override DataFlow:: Node getAPathArgument ( ) { result = this .getArgument ( pathArg ) }
182
+ override DataFlow:: Node getAPathArgument ( ) { result = this .getArgument ( 1 ) }
196
183
}
197
184
198
185
/**
199
- * A sanitizer for when the Afero utility functions has a first argument of a safe type like NewBasePathFs
186
+ * Holds if the Afero utility function has a first argument of a safe type like ` NewBasePathFs`.
200
187
*
201
188
* e.g.
202
189
* ```
@@ -206,19 +193,21 @@ module Afero {
206
193
*/
207
194
predicate aferoSanitizer ( DataFlow:: Node n ) {
208
195
exists ( Function f |
209
- f .hasQualifiedName ( package ( aferoPackage ( ) , "" ) , "NewBasePathFs" ) and
210
- TaintTracking :: localTaint ( f .getACall ( ) , n )
196
+ f .hasQualifiedName ( aferoPackage ( ) , "NewBasePathFs" ) and
197
+ DataFlow :: localFlow ( f .getACall ( ) , n )
211
198
)
212
199
}
213
200
214
201
/**
202
+ * Holds if there is a dataflow node from n1 to n2 when initializing the Afero instance
203
+ *
215
204
* A helper for `aferoSanitizer` for when the Afero instance is initialized with one of the safe FS types like IOFS
216
205
*
217
206
* e.g.`n2 := &afero.Afero{Fs: afero.NewBasePathFs(osFS, "./")}` n1 is `afero.NewBasePathFs(osFS, "./")`
218
207
*/
219
208
predicate additionalTaintStep ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
220
- exists ( StructLit st | st .getType ( ) .hasQualifiedName ( package ( aferoPackage ( ) , "" ) , "Afero" ) |
221
- n1 .asExpr ( ) = st .getAChildExpr * ( ) and
209
+ exists ( StructLit st | st .getType ( ) .hasQualifiedName ( aferoPackage ( ) , "Afero" ) |
210
+ n1 .asExpr ( ) = st .getAChildExpr ( ) . ( KeyValueExpr ) . getAChildExpr ( ) and
222
211
n2 .asExpr ( ) = st
223
212
)
224
213
}
0 commit comments