Repository navigation
Description
Problem
Using a Tower through Codev Cloud fails with Unauthorized on every page and API call, even though registration succeeds (post-#1570) and the tunnel is connected. Tower log (3.3.2, 2026-09-02):
[WARN] 401 GET / — disallowed Host "cloud.codevos.ai"
[WARN] 401 GET /api/projects — missing or invalid key
This is the second half of the #1421 regression (Tower API authentication, shipped in 3.3.1): the first half blocked the OAuth callback (#1570, fixed in 3.3.2); this half blocks every request that arrives through the tunnel. It went unnoticed because connecting was broken first, so nobody reached this step until 3.3.2.
Root cause (proven from code, packages/codev/src/agent-farm/lib/tunnel-client.ts)
- Host is forwarded verbatim.
proxyHttpRequestcopies every non-pseudo, non-hop-by-hop inbound header into the localhost request — includingHost: cloud.codevos.ai.isAllowedHost()(server-utils.ts) rejects it. The WebSocket CONNECT path (handleWebSocketConnect, ~line 737) explicitly setsHost: localhost:<port>and its comment claims "the HTTP proxy path already lets Node default Host to localhost" — false whenever an inboundhostheader is present, which it always is. - No key is stamped. Tunnel-borne requests carry no
codev-tower-key, and Tower'sisRequestAllowed()gives the (unforgeable, stripped-and-restamped)x-codev-tunnel-proxymarker no exemption — the marker is only used for/api/tunnel/*rejection and log attribution (tower-tunnel.ts:319). So even with Host fixed, every keyed route 401s.
Trust model (arch.md §Tower API Authentication, unchanged): the cloud edge (codevos.ai) authenticates the remote user; the local key authenticates local actors to their own Tower. TunnelClient runs inside the Tower process and is a local actor — it legitimately possesses the key.
Fix (prescribed)
In proxyHttpRequest (mirror what handleWebSocketConnect already does):
- Rewrite Host: drop any inbound
hostand setHost: localhost:<localPort>. Fix the misleading comment on the WS path. - Stamp the local key: strip any inbound
codev-tower-key/ legacycodev-web-key(anti-forgery, same pattern asstampProxyMarker), then setcodev-tower-keyto the local key (getExpectedKey()/ensureLocalKey()from server-utils — same process, same file). Do this in the same helper as the proxy marker so the two stamps cannot drift. - WebSocket path: verify the browser-supplied
Sec-WebSocket-Protocol: codev-key.<KEY>subprotocol survives the H2 CONNECT → localhost upgrade untouched (the remote dashboard shell is served by the local Tower with the key injected, exactly as for a local browser, so subsequent API/WS calls carry it themselves). Add a test if none pins it. - Keep the existing
/api/tunnel/*refusal for tunnel-borne requests exactly as is — the key stamp must NOT let a cloud actor reach management routes (test it).
Out of scope: rotating/scoping the key for remote sessions (the remote browser receives the same injected key a local browser does — no worse than pre-#1421, when tunnel access was fully unauthenticated locally; a per-session remote credential is a design follow-up for @amrmelsayed's trust-model read).
Testing
- Unit: a proxied request with
Host: cloud.codevos.aiand no key reaches the local handler withHost: localhost:<port>and a validcodev-tower-key; an inbound forged key/marker is replaced, not passed through;/api/tunnel/disconnectthrough the tunnel is still refused. - Existing tunnel suites stay green.
- Field (architect-driven, post-release): open the Tower through cloud.codevos.ai → dashboard loads, workspace list populates, a terminal WebSocket attaches.
Release
Ride the 3.3.3 hotfix with #1584 — cloud access is fully broken on every released version since 3.3.1 without it.
cc @amrmelsayed — author of #1421; please sanity-check the stamp-in-tunnel-client shape against the advisory's threat model (it keeps the key check as the single choke point and adds no Tower-side exemption).
Refs: #1421 (source), #1570/PR #1571 (first half), #1374 (tunnel-borne management refusal).
Activity
waleedkadous commentedon Sep 2, 2026
On it! Working on a fix now.
Fix #1586: stamp Host + local key on tunnel-proxied requests
Fix #1586: pin the fail-closed branch of the tunnel header stamp
[Bugfix #1586] docs: record tunnel-client Host + local-key stamping i…
Merge pull request #1588 from cluesmith/builder/bugfix-1586
waleedkadous commentedon Sep 3, 2026
Completion stats
Fixed in PR #1588, merged 2026-09-03 11:21 UTC by @amrmelsayed.
tunnel-client.ts: +46 / −13, one filebugfix-1586-tunnel-auth.test.ts: +220, 6 testsRoot cause
Two independent failures in
proxyHttpRequest, either alone fatal:Hostforwarded verbatim. The header loop copiedHost: cloud.codevos.aiinto the localhost request.isAllowedHost()rejects it — and becauseisRequestAllowed()runs the Host guard ahead of the public-route allowlist, even the keyless dashboard shell atGET /401'd, not just the API. ThehandleWebSocketConnectcomment claiming the HTTP path "already lets Node default Host to localhost" was false: Node only defaultsHostwhen none is supplied, and the cloud edge always supplies one.x-codev-tunnel-proxymarker carries no auth exemption — it exists only for/api/tunnel/*refusal and log attribution — so keyed routes had nothing to check.Reproduced against a live Tower before any code was written: cloud Host + valid key → 401; localhost + no key → 401; localhost + key → through.
Fix
stampProxyMarker→stampLocalHeaders(headers, localPort): strips any inboundhost,codev-tower-key,codev-web-keyandx-codev-tunnel-proxy, then stampsHost: localhost:<port>, the marker, andgetExpectedKey(). All three set in one helper called by both proxy paths, so they cannot drift; stripping first means a cloud-side actor can neither forge nor suppress any of them.Trust model unchanged — no Tower-side exemption was added, the key check stays the single choke point, and the
/api/tunnel/*refusal is untouched.Tests
bugfix-1586-tunnel-auth.test.tsruns the realisRequestAllowedin the local server, pinning authorization end-to-end rather than by header shape. Three of six fail without the fix; three are invariants, green both ways:/api/tunnel/*refused through the tunnel — root and workspace-scoped formcodev-key.<KEY>subprotocol survives the H2 CONNECT → localhost upgradeNotes
[Bugfix #1586] docs: record merge outcome and stranded porch commits …
[Bugfix #1586] docs: record merge outcome and stranded porch commits …
Merge pull request #1601 from cluesmith/records/1586-porch-records