GHSA-g3c2-rjq2-c763: esm.sh: web.NewHandler allows arbitrary file read via encoded dot-segment path traversal
- Source:
- OSV.dev
- Published:
- Fetched:
- Updated:
- Affects:
- github.com/esm-dev/esm.sh/web
https://osv.dev/vulnerability/GHSA-g3c2-rjq2-c763 ↗
esm.sh: web.NewHandler allows arbitrary file read via encoded dot-segment path traversal ### 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: ```go 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`: ```go 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: ```text 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 Affected: Go:github.com/esm-dev/esm.sh/web Fixed in: 0.2.0 References: https://github.com/esm-dev/esm.sh/security/advisories/GHSA-g3c2-rjq2-c763 https://nvd.nist.gov/vuln/detail/CVE-2026-102657 https://github.com/esm-dev/esm.sh/pull/1376 https://github.com/esm-dev/esm.sh/commit/468b6b2a4b4dfec334cf6b33b01fcd4e5cd93bed https://github.com/esm-dev/esm.sh/commit/fc3b345e73aeaa0b7a05b6f27d91c05fdf5f9b53 https://github.com/esm-dev/esm.sh https://github.com/esm-dev/esm.sh/releases/tag/v0.2.0 https://github.com/esm-dev/esm.sh/releases/tag/v137_7