This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import * as dns from 'dns';
|
||||
import { isIP } from 'node:net';
|
||||
import { isPrivateOrForbidden } from '../../../net/ssrf-strict.js';
|
||||
|
||||
// These delegate to the hardened range check in src/net/ssrf-strict.ts so that
|
||||
@@ -6,11 +7,13 @@ import { isPrivateOrForbidden } from '../../../net/ssrf-strict.js';
|
||||
// loopback, RFC1918, link-local + cloud metadata (169.254/16, fd00:ec2::),
|
||||
// CGNAT (100.64/10), 0.0.0.0/8, IPv4-mapped IPv6, NAT64, multicast, reserved.
|
||||
export function isPrivateIPv4(ip: string): boolean {
|
||||
if (isIP(ip) !== 4) return false;
|
||||
return isPrivateOrForbidden(ip, 4);
|
||||
}
|
||||
|
||||
export function isPrivateIPv6(ip: string): boolean {
|
||||
const normalized = ip.toLowerCase().replace(/^\[|\]$/g, '');
|
||||
if (isIP(normalized) !== 6) return false;
|
||||
return isPrivateOrForbidden(normalized, 6);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user