File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -249,6 +249,22 @@ export class HttpService {
249249 // Add custom user agent
250250 config . headers [ 'User-Agent' ] = 'SparrowRuntime/1.0.0' ;
251251
252+ // DNS rebinding protection: re-validate resolved IP before request
253+ const resolvedAddresses = await lookup ( new URL ( url ) . hostname , { all : true } ) ;
254+ for ( const addr of resolvedAddresses ) {
255+ const ip = ipaddr . parse ( addr . address ) ;
256+ if (
257+ ip . range ( ) === 'linkLocal' ||
258+ ip . range ( ) === 'loopback' ||
259+ ip . range ( ) === 'private' ||
260+ ip . range ( ) === 'reserved'
261+ ) {
262+ throw new BadRequestException (
263+ `Access to internal IP addresses is not allowed: ${ addr . address } ` ,
264+ ) ;
265+ }
266+ }
267+
252268 try {
253269 const response = await this . httpService . axiosRef ( {
254270 url : config . url ,
You can’t perform that action at this time.
0 commit comments