@@ -130,14 +130,8 @@ for (const module of modulesToHook) {
130
130
return ;
131
131
}
132
132
// The first argument of the original function is typically
133
- // a path or a file name.
134
- const firstArgument = params [ 0 ] as string ;
135
- if ( firstArgument . includes ( goal ) ) {
136
- reportFinding (
137
- `Path Traversal in ${ functionName } (): called with '${ firstArgument } '` ,
138
- ) ;
139
- }
140
- guideTowardsContainment ( firstArgument , goal , hookId ) ;
133
+ // a path or a file name. For some functions, it can be a URL or a Buffer.
134
+ detectFindingAndGuideFuzzing ( params [ 0 ] , goal , hookId , functionName ) ;
141
135
} ;
142
136
143
137
registerBeforeHook ( functionName , module . moduleName , false , beforeHook ) ;
@@ -174,19 +168,15 @@ for (const module of functionsWithTwoTargets) {
174
168
if ( params === undefined || params . length < 2 ) {
175
169
return ;
176
170
}
177
- // The first two arguments are paths.
178
- const firstArgument = params [ 0 ] as string ;
179
- const secondArgument = params [ 1 ] as string ;
180
- if ( firstArgument . includes ( goal ) || secondArgument . includes ( goal ) ) {
181
- reportFinding (
182
- `Path Traversal in ${ functionName } (): called with '${ firstArgument } '` +
183
- ` and '${ secondArgument } '` ,
184
- ) ;
185
- }
186
- guideTowardsContainment ( firstArgument , goal , hookId ) ;
187
171
// We don't want to confuse the fuzzer guidance with the same hookId for both function arguments.
188
172
// Therefore, we use an extra hookId for the second argument.
189
- guideTowardsContainment ( secondArgument , goal , extraHookId ) ;
173
+ detectFindingAndGuideFuzzing ( params [ 0 ] , goal , hookId , functionName ) ;
174
+ detectFindingAndGuideFuzzing (
175
+ params [ 1 ] ,
176
+ goal ,
177
+ extraHookId ,
178
+ functionName ,
179
+ ) ;
190
180
} ;
191
181
} ;
192
182
@@ -198,3 +188,24 @@ for (const module of functionsWithTwoTargets) {
198
188
) ;
199
189
}
200
190
}
191
+
192
+ function detectFindingAndGuideFuzzing (
193
+ input : unknown ,
194
+ goal : string ,
195
+ hookId : number ,
196
+ functionName : string ,
197
+ ) {
198
+ if (
199
+ typeof input === "string" ||
200
+ input instanceof URL ||
201
+ input instanceof Buffer
202
+ ) {
203
+ const argument = input . toString ( ) ;
204
+ if ( argument . includes ( goal ) ) {
205
+ reportFinding (
206
+ `Path Traversal in ${ functionName } (): called with '${ argument } '` ,
207
+ ) ;
208
+ }
209
+ guideTowardsContainment ( argument , goal , hookId ) ;
210
+ }
211
+ }
0 commit comments