Summary
esm.sh's /http(s) fetch route contains a server-side request forgery (SSRF) flaw that allows external users to coerce the CDN backend into making HTTP(S) requests to internal services.
Because localhost and internal access controls rely only on hostname string checks, they can be bypassed via DNS alias domains, enabling access to services not directly exposed to the internet.
Affected context
This vulnerability affects deployments of esm.sh up to and including version 137 that expose the /http(s) fetch route to untrusted or public clients.
The issue manifests when esm.sh is allowed to resolve and connect to arbitrary hostnames provided by users, while the protection against localhost or internal destinations is implemented using simple hostname string filtering rather than network- or IP-aware validation.
Environments where the esm.sh server has network visibility into internal APIs, metadata services, admin panels, or other non-public endpoints are particularly at risk.
Exploit preconditions
- Attack surface: Public or externally reachable
/http(s)fetch endpoint on esm.sh - Required access: Ability to issue HTTP requests to the esm.sh instance (no privileged authentication assumed)
- Trigger point: Supplying a crafted URL whose hostname resolves to an internal or localhost IP, but whose literal hostname string bypasses the basic blocklist
- Why exploitation is possible: The access control logic checks only the textual hostname against disallowed patterns (e.g.,
localhost,127.0.0.1) without resolving the hostname and validating the resulting IP and network, allowing DNS aliases to internal addresses
Why this happens
The core bug is an incomplete and trust-without-verification pattern for outbound requests initiated on behalf of users.
The /http(s) route accepts user-supplied URLs and attempts to prevent internal access by filtering hostnames using simple string comparisons.
This maps to CWE-918: Server-Side Request Forgery (SSRF), where a server-side component performs network requests based on untrusted input without robust target validation.
Because the system does not resolve the hostname and enforce restrictions on the actual IP address, attackers can leverage DNS aliases or crafted domain names that appear benign in string form but ultimately route to internal resources.
Potential impact
- Unauthorized HTTP(S) access to internal services reachable from the esm.sh server
- Interaction with internal admin panels, monitoring dashboards, or APIs not exposed to the public internet
- Access to instance or cloud provider metadata endpoints, which may lead to credential or token disclosure
- Use of esm.sh as a network pivot to map internal services, ports, and response behaviors
- Potential data exfiltration from internal APIs, subject to response visibility to the attacker
General mitigation guidance
Effective mitigation focuses on hardening how user-controlled URLs are handled and reducing the network trust zone of the service:
- Enforce IP- and network-based deny lists: resolve hostnames and block requests to localhost ranges, private IP ranges, link-local, and metadata service addresses, rather than relying on string checks.
- Consider an allowlist model: restrict outbound requests to a curated set of domains or IP ranges that are known to be safe for proxying.
- Isolate network access: run the esm.sh server in a network segment with minimal access to sensitive internal services and metadata endpoints.
- Normalize and strictly validate URLs: ensure consistent parsing, reject ambiguous or malformed URLs, and avoid following redirects into internal networks.
- Apply least-privilege to outbound connectivity: limit the protocols, ports, and destination ranges available to the fetch component.
How teams detect issues like this
High-level detection can combine code-centric review with operational monitoring:
- Static analysis and code review to flag any code paths where user-supplied URLs are fetched server-side, especially where filtering is based on hostname strings instead of resolved IPs or CIDR checks.
- Security review of proxy or fetch endpoints to ensure they do not provide arbitrary open proxy capabilities or direct access into private networks.
- Logging and monitoring of outbound requests initiated via the
/http(s)route, including destination hostnames, resolved IP addresses, and unusual patterns such as access to internal IP ranges. - Network-level controls and IDS/IPS rules that alert on unexpected requests from the esm.sh infrastructure to internal address spaces or metadata services.

