fix(shared,host-service): constrain proxy/tunnel upstream before attaching the host secret (GHSA-8qrv-53x7-hh4p, GHSA-h894-rmgp-jv6m)
Re-lands #7829 (reverted in #7834 pending review). Cherry-pick of 68fc486abe onto current main; identical diff, no repro artifacts.
What it fixes
The sandbox gate built its upstream with new URL(path, claims.target), so a //evil.example/... path overrode the target origin and the gate then attached the workspace's host secret and fetched the attacker's host. The tunnel client built its local URL by string concatenation, open to the @ userinfo trick. A bypassable relay-side //-only check was also found.
Severity, honestly
- Gate: real and demonstrated (secret forwarded to
https://evil.examplepre-fix). The secret is derived from the attacker's ownworkspaceId, so the blast radius is their own sandbox, not cross-tenant — but a credential sent to an attacker-named origin is wrong regardless, and it is also SSRF from the gate's network position. - Tunnel: defense-in-depth. The
@trick needs a path with no leading slash, which the relay never naturally produces; the old//check already covered the main vector.
Fix
One shared guard, packages/shared/src/upstream-url.ts: rejects protocol-relative targets, /\, control characters and userinfo, and requires the resolved origin to equal the base. Gate, tunnel client and the relay check all use it.
Proof
gate tests 2 pass / 5 fail → 8 / 0; tunnel 4 fail → 19 / 0; shared 1114 pass; typecheck 8/8; biome + sherif clean. A pre-existing unrelated health.check failure was verified on a clean tree.
Write-up: https://app.superset.sh/page/p1-b-host-secret-disclosure-to-an-attacker-selecte-yhe08o
Summary by cubic
Fixes two security vulnerabilities that could forward the host secret to an attacker-chosen origin. The gate resolved request targets against the ticket target as a relative URL, so //evil.example/... moved the origin; the tunnel client string-concatenated the relay-chosen path onto the loopback origin, letting a leading @ turn it into userinfo. Both, plus the relay's bypassable //-only check, now use a shared guard that rejects non-origin-form targets and any resolution that changes the origin.
The gate leak is demonstrated but confined to the attacker's own sandbox; the tunnel fix is defense-in-depth. Tests were added for the gate, tunnel client, and the shared guard.
Summary by CodeRabbit
- Bug Fixes
- Invalid or malformed request paths are now rejected with a 400 response instead of being forwarded to another origin.
- HTTP and WebSocket requests are restricted to their intended upstream host, including when paths or query tokens could otherwise redirect them elsewhere.