GHSA-2rx5-2g7j-2659 Cosmos-Server has an authentication bypass via forward-auth header smuggling on Constellation tunnel
SummaryThe Constellation-tunnel bypass branch in `tokenMiddleware` at `src/proxy/routerGen.go:53-66` returns to the upstream handler before the request's `x-cosmos-user`, `x-cosmos-role`, `x-cosmos-user-role`, and `x-cosmos-mfa` headers are stripped at lines 68-72, and before the `AdminOnlyWithRedirect` gate at lines 109-117 runs. Any holder of a valid Constellation device API key sends `x-cosmos-user: admin` to a proxied backend; the documented forward-auth integration treats the caller as admin with no JWT cookie, password, or MFA.PreconditionsCosmos is deployed with Constellation enabled and at least one device enrolled.Attacker holds a valid `x-cstln-auth` API key for an enrolled device.Attacker reaches Cosmos over the Constellation Nebula tunnel.Target proxy route has `AuthEnabled=true`; upstream trusts the `x-cosmos-user` forward-auth header.DetailsThe branch was written for tunneled-cluster traffic where an upstream Cosmos instance has already authenticated the user and signed the `x-cosmos-user` header itself. The branch condition reads the header before the strip block runs at lines 68-72, so any client can open the branch by sending the header. The Constellation IP and API-key checks then gate progression, but a Constellation device holder satisfies both: the API key was issued by the admin when the device was enrolled, and the tunnel terminates with the device's Constellation IP as the TCP source. Once the branch is taken, the original `x-cosmos-user` value flows to the backend untouched, and `AdminOnlyWithRedirect` is never invoked. Backends configured per Cosmos's documented forward-auth integration (the standard pattern for "Cosmos in front of an app that reads identity from a header") treat the attacker's chosen string as the authenticated identity.The Constellation network is sold as a way for an operator to invite family and friends without exposing ports. Those invited members hold device API keys but are not Cosmos administrators - the trust boundary this bug crosses is exactly the "invited member -> admin role on a proxied app" line.Proof of conceptEnvironment used to reproduce:Version: `master` branch, audited 2026-05-13 (module `github.com/azukaar/cosmos-server`)Deployment: `docker run azukaar/cosmos-server:latest` (or the `docker-compose.yml` from the project README)Setup steps:Complete initial setup via `/cosmos-ui/`; promote the operator account to admin.Enable Constellation: Settings > Constellation > Create lighthouse.Enrol a device under a non-admin user: Constellation > Devices > Create. Save the device profile and the displayed API key.Configure one proxy route with `Host=admin-app.example`, `Mode=PROXY`, `Target=http://internal-app:port`, `AuthEnabled=true`, `AdminOnly=true`. Upstream must trust the `x-cosmos-user` header (the documented Cosmos forward-auth integration, e.g. an internal admin panel that reads identity from that header).Attacker connects to the Nebula tunnel with the issued device profile, so the request's TCP source is the device's Constellation IP.A second request demonstrates cross-user impersonation on the same backend by changing the asserted identity:Impact**AuthN:** bypasses Cosmos JWT login, password, and MFA for any holder of a Constellation device key.**AuthZ:** skips the per-route `AdminOnly` gate, unlocking admin-only proxied backends.**Confidentiality:** caller reads every admin-only proxied app as `admin` from one curl.**Integrity:** caller performs any admin-tier write the backend exposes via the forward-auth identity.**Affected population:** every Cosmos deployment with Constellation enabled, at least one enrolled device, and one or more proxy routes integrated via the documented `x-cosmos-user` header.Suggestions to fix_This has not been tested - it is illustrative only._Strip the identity headers unconditionally at function entry so they cannot open the bypass branch, and keep the `AdminOnly` gate on the Constellation path. The branch should only fire for routes that are explicitly `AuthEnabled=false` - on auth-required routes the JWT path must always run so the proxy itself is the sole authority that writes `x-cosmos-user`.Defence in depth: document that backends downstream of Cosmos must not accept `x-cosmos-user` over an untrusted hop. Bind the trust to a mutual TLS leg or a shared HMAC over `<x-cosmos-user, request-id, timestamp>` injected by the proxy and verified by the backend.Regression test: add a unit test against `tokenMiddleware` asserting that a request bearing `x-cosmos-user: admin` and a valid `x-cstln-auth` reaches the next handler with `r.Header.Get("x-cosmos-user") == ""` whenever `route.AuthEnabled == true`.
CVSS v3.1 score: 6.1