Details
req := httptest.NewRequest(http.MethodGet, "http://dashboard.example:8008/api/v1/profile", nil)
rec := httptest.NewRecorder()
h.ServeHTTP(rec, req)
if rec.Code == http.StatusTeapot || rec.Body.String() == "dashboard handler reached" {
t.Fatalf("dashboard handler was reached despite claimed NAT host: code=%d body=%q", rec.Code, rec.Body.String())
}
fmt.Fprintf(os.Stdout, "positive: Host %s matched disabled member NAT id=%d and preempted dashboard handler with status=%d\n", req.Host, nat.ID, rec.Code)
controlReq := httptest.NewRequest(http.MethodGet, "http://other.example:8008/api/v1/profile", nil)
controlRec := httptest.NewRecorder()
h.ServeHTTP(controlRec, controlReq)
if controlRec.Code != http.StatusTeapot || controlRec.Body.String() != "dashboard handler reached" {
t.Fatalf("control host did not reach dashboard handler: code=%d body=%q", controlRec.Code, controlRec.Body.String())
}
fmt.Fprintf(os.Stdout, "control: Host %s missed NAT and reached dashboard handler with status=%d\n", controlReq.Host, controlRec.Code)
}
EOF
trap cleanup EXIT
GOPROXY=off go test ./cmd/dashboard -run TestNATDomainPreemptsDashboardHost -count=1 -v
Observed vulnerable output in this environment:
```text
=== RUN TestNATDomainPreemptsDashboardHost
positive: Host dashboard.example:8008 matched disabled member NAT id=1 and preempted dashboard handler with status=403
control: Host other.example:8008 missed NAT and reached dashboard handler with status=418
--- PASS: TestNATDomainPreemptsDashboardHost (0.11s)
PASS
ok github.com/nezhahq/nezha/cmd/dashboard 0.132s
Expected vulnerable output: the positive request for dashboard.example:8008 must not return the dashboard handler's 418 response; it should be intercepted by the disabled NAT profile and return the WAF/block status. The control request for other.example:8008 must reach the dashboard handler and return 418 with body dashboard handler reached.
Cleanup: the shell trap cleanup EXIT removes the temporary test file, temporary generated docs stub, and temporary embed placeholders. The SQLite database is created under t.TempDir() and removed by Go's test cleanup.
Final re-check: the reproduction above was run after source-to-sink analysis and before writing this draft; it passed with the exact output shown above.
Impact
A non-admin authenticated user can bind a global routing key that belongs to the dashboard operator. If the attacker sets enabled=false, all requests carrying the claimed dashboard Host are blocked before reaching dashboard API, frontend, or gRPC handlers. This can deny access to the dashboard for all users who use that Host.
If the attacker sets enabled=true and keeps the selected owned agent online, the matching requests enter ServeNAT: the dashboard sends a NAT task to that agent and streams the serialized original HTTP request into the NAT IO stream. Because utils.NewRequestWrapper serializes the original request with headers, dashboard requests that should have been processed locally can be forwarded to infrastructure controlled by the low-privileged user. The local proof avoids this stronger enabled-agent path, but the source path is direct in cmd/dashboard/rpc/rpc.go:142-204 and pkg/utils/request_wrapper.go:19-31.
Suggested remediation
Do not allow ordinary NAT profiles to claim dashboard-owned hosts. Recommended fixes:
- Canonicalize incoming Host values and NAT domain values consistently, including case and port handling.
- Add a server-side reserved-host check in both
createNATandupdateNATthat rejects the configured dashboard public host(s), listen host/port combinations, and any administrator-reserved domains. - Consider making NAT domain creation admin-approved unless the deployment can verify domain ownership for the requesting user.
- In the top-level mux, route dashboard/gRPC hosts before NAT when the Host is known to belong to the dashboard.
- Add regression tests covering create, update, cache reload, and mux behavior for dashboard-host collisions.
A useful regression test is the PoC above inverted: a member-created NAT with Domain equal to the configured dashboard Host should be rejected by the controller, and a request with the dashboard Host should continue to reach the dashboard handler.