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 @@ -230,6 +230,22 @@ export class HttpService {
230230
231231 // Add custom user agent
232232 config . headers [ 'User-Agent' ] = 'SparrowRuntime/1.0.0' ;
233+
234+ // DNS rebinding protection: re-validate resolved IP before request
235+ const resolvedAddresses = await lookup ( new URL ( url ) . hostname , { all : true } ) ;
236+ for ( const addr of resolvedAddresses ) {
237+ const ip = ipaddr . parse ( addr . address ) ;
238+ if (
239+ ip . range ( ) === 'linkLocal' ||
240+ ip . range ( ) === 'loopback' ||
241+ ip . range ( ) === 'private' ||
242+ ip . range ( ) === 'reserved'
243+ ) {
244+ throw new BadRequestException (
245+ `Access to internal IP addresses is not allowed: ${ addr . address } ` ,
246+ ) ;
247+ }
248+ }
233249
234250 try {
235251 const response = await this . httpService . axiosRef ( {
You can’t perform that action at this time.
0 commit comments