Skip to content

Commit ebe0e22

Browse files
authored
Merge pull request #23 from Astitva877/astitva/ip-restrictions
fix: added private ipcheck before api call to bypass dnsrebinding [SPRW-1794]
2 parents 3a92bfe + 89c267e commit ebe0e22

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
@@ -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,

0 commit comments

Comments
 (0)