Summary
The ssrfcheck library, intended to block Server-Side Request Forgery (SSRF), fails to detect requests to private IP ranges when those addresses are supplied as IPv4-mapped IPv6 literals (for example, http://[::ffff:127.0.0.1]/).
Because Node.js's WHATWG URL parser normalizes these inputs before regex checks run, applications relying on isSSRFSafeURL() may unknowingly allow SSRF to internal services and cloud metadata endpoints.
Affected context
This vulnerability affects Node.js applications that:
- Use the ssrfcheck library (v1.3.0 and earlier) to validate user-supplied URLs
- Rely on
isSSRFSafeURL()as a primary or sole guard against SSRF - Construct server-side HTTP requests to arbitrary URLs after validation
The issue arises specifically when:
- User input is parsed using the WHATWG
URLimplementation in Node.js - Private IPv4 addresses are provided as IPv4-mapped IPv6 literals inside brackets
- The library's regex is written only for dotted IPv4 notation and never matches the normalized IPv6 form
Exploit preconditions
- Attack surface: Any server-side endpoint that accepts user-supplied URLs and uses ssrfcheck to decide whether to perform outbound HTTP requests.
- Required access: Ability to submit or influence URL input fields (e.g., web forms, API parameters, webhook configuration, URL fetch utilities).
- Trigger point: The application calls
isSSRFSafeURL()on a user-controlled URL, then proceeds to perform an HTTP(S) request if the function returns "safe." - Why exploitation is possible:
- Node.js's WHATWG URL parser normalizes IPv4-mapped IPv6 addresses (e.g.,
http://[::ffff:127.0.0.1]/→http://[::ffff:7f00:1]/). - The ssrfcheck regex only targets dotted IPv4 literals for private ranges and never matches compressed IPv6 notation.
- As a result, requests targeting internal/private IP ranges and metadata services can pass the check and be issued by the server.
Why this happens
The underlying bug is an improper input validation pattern (CWE-184) combined with an incomplete SSRF protection (CWE-918).
ssrfcheck assumes that private IP addresses will appear exclusively as dotted IPv4 literals and builds a regex-based filter around that assumption. In modern URL parsing environments, especially with the WHATWG URL standard, user-supplied hosts can be normalized or transformed into equivalent forms (such as IPv4-mapped IPv6 or compressed IPv6) before or during validation. Because the regex is aligned only with a single textual representation and not with the normalized address form, it never matches real-world input once parsed, effectively disabling the intended blocking logic.
Abstractly, this is a classic case where security checks are tightly coupled to a specific string representation rather than to a canonical, semantic interpretation of the data (e.g., resolved IP address). When URL parsing and normalization are delegated to a separate component, but validation logic remains unaware of these transformations, filters become brittle and can be bypassed via alternate encodings.
Potential impact
- Attackers could coerce the application into making HTTP requests to private/internal IP addresses (loopback, RFC1918 ranges).
- Requests to cloud provider metadata services (e.g.,
169.254.169.254) could expose credentials, tokens, or configuration secrets. - Internal HTTP-based administration panels, APIs, or debug endpoints could be accessed and potentially manipulated.
- SSRF could serve as a pivot for further attacks, such as data exfiltration, internal service enumeration, and secondary code execution vulnerabilities behind the perimeter.
- Logging or monitoring systems may inaccurately classify these requests as legitimate, because the validation function reports them as safe.
General mitigation guidance
Effective mitigation focuses on canonical address evaluation and defense-in-depth for outbound requests, rather than relying solely on string-based regex checks.
Pattern-based mitigations include:
- Performing IP-based SSRF checks on the fully parsed and resolved host:
- Resolve the hostname (or IP literal) to one or more IP addresses.
- Normalize to canonical IP representations before classification.
- Classify addresses into private, loopback, link-local, and public ranges using a robust IP-handling library rather than ad-hoc regex.
- Treating all non-hostname literals (including IPv6 and IPv4-mapped IPv6) as potentially sensitive and applying conservative blocking for internal ranges.
- Applying default-deny policies for server-initiated HTTP requests:
- Maintain an allowlist of explicit domains or networks that the server is permitted to reach.
- Block or heavily constrain direct access to link-local and metadata addresses.
- Separating user-controlled URLs from sensitive network paths:
- Route untrusted fetches through proxy layers that enforce strict network egress policies.
- Use network-level controls (firewalls, egress policies, service meshes) to prevent access to internal segments from application tiers.
- Designing SSRF protections to be resilient to different encodings and normalizations, rather than relying solely on textual pattern matching.
How teams detect issues like this
Detection should focus on both code-level anti-patterns and runtime behavior of outbound requests.
Code-centric strategies:
- Static analysis rules that flag:
- Reliance on regex-only validation for SSRF protection.
- Any security checks performed on raw URL strings before or instead of checking parsed/normalized hosts.
- Direct use of
isSSRFSafeURL()(or similar helpers) without follow-up checks on resolved IP ranges. - Code review checklists that explicitly ask:
- "How are outbound HTTP requests validated?"
- "Are internal and metadata endpoints blocked at both code and network layers?"
- "Is URL normalization or DNS resolution considered in the validation step?"
- Enforcement of internal guidelines or linting rules mandating:
- Use of shared, vetted SSRF-protection utilities.
- Prohibition of bespoke regex filters for IP classification.
Runtime and operational strategies:
- Monitoring and alerting on outbound traffic to:
- Private IP ranges (loopback, RFC1918).
- Link-local and metadata addresses (e.g., 169.254.169.254).
- Logging the effective destination host and IP for all server-initiated HTTP requests, with correlation to request originator code paths.
- Periodic security testing and SSRF-focused penetration tests, including:
- IPv4-mapped IPv6 payloads.
- Alternative encodings and normalization edge cases.

