Skip to content

Commit 8b4a859

Browse files
committed
fix: added private ipcheck before api call to bypass dnsrebinding [SPRW-1974]
1 parent 3522605 commit 8b4a859

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/proxy/http/http.service.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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({

0 commit comments

Comments
 (0)