Skip to content

fix(kiloclaw): stop leaking /i/{instanceId} prefix in access gateway redirect#2150

Merged
pandemicsyn merged 5 commits intomainfrom
florian/throw-away
Apr 8, 2026
Merged

fix(kiloclaw): stop leaking /i/{instanceId} prefix in access gateway redirect#2150
pandemicsyn merged 5 commits intomainfrom
florian/throw-away

Conversation

@pandemicsyn
Copy link
Copy Markdown
Contributor

@pandemicsyn pandemicsyn commented Apr 7, 2026

Summary

buildRedirectUrl in the access gateway included /i/{instanceId}/ in the redirect path for instance-keyed instances. The OpenClaw SPA (which we don't control) derived its WebSocket URL from window.location, persisted it to localStorage, and reused it across instance switches — bypassing the cookie-based instance routing added in #1815.

When a user switched between personal and org instances, the SPA would connect its WebSocket to the stale /i/{old-instance-id} path, routing traffic to the wrong machine.

Fix: buildRedirectUrl now always redirects to /#token={token}. The kiloclaw-active-instance cookie (set before the redirect) handles catch-all proxy routing to the correct instance. The /i/{instanceId} prefix never appears in the redirect URL.

Also strips additional proxy headers (forwarded, x-forwarded-proto) in the controller WebSocket proxy so the gateway's isLocalDirectRequest check works reliably on 3.28 and beyond.

Verification

  • Manually tested personal instance open — redirects to /#token=..., cookie-routed correctly
  • Manually tested org instance open — redirects to /#token=..., cookie-routed to org machine
  • Verified all PR feat(kiloclaw): add org-scoped instance management + per-instance Fly apps #1815 cookie-routing commits survived the monorepo refactor (diffed against known-good 94fa6201)
  • Traced OpenClaw SPA source (~/projects/openclaw) to confirm localStorage scoping and WebSocket URL derivation behavior
  • Additional verification: fill in after testing

Visual Changes

N/A

Reviewer Notes

  • The bug existed since PR feat(kiloclaw): add org-scoped instance management + per-instance Fly apps #1815 — commit fbd62cf added the /i/{instanceId}/ redirect path, and commit 7751f77 added cookie routing but never updated the redirect to stop including the prefix.
  • Users with stale localStorage from before this fix will need to clear localStorage for claw.kilosessions.ai (or the dev host) once. New sessions will work immediately.
  • Single-cookie limitation: only one instance can be "active" at a time. Concurrent tabs to different instances are not supported by cookie routing.

Comment thread services/kiloclaw/controller/src/proxy.test.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Apr 7, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • services/kiloclaw/controller/src/proxy.test.ts

Reviewed by gpt-5.4-20260305 · 112,065 tokens

…redirect

buildRedirectUrl included /i/{instanceId}/ in the redirect path for
instance-keyed instances. This leaked the proxy prefix to the OpenClaw
SPA, which derived its WebSocket URL from window.location and persisted
it to localStorage — bypassing cookie-based instance routing entirely.

Always redirect to /#token={token} and let the kiloclaw-active-instance
cookie (set before the redirect) handle catch-all proxy routing.
@pandemicsyn pandemicsyn changed the title fix(kiloclaw): strip headers for +3.28 and later fix(kiloclaw): stop leaking /i/{instanceId} prefix in access gateway redirect Apr 8, 2026
The assertions for stripping these headers were passing trivially
because the incoming request never set them. Add them to the fixture
so the test actually exercises the delete logic. Fix indentation.
@pandemicsyn pandemicsyn requested a review from a team April 8, 2026 01:20
@pandemicsyn pandemicsyn merged commit ea57620 into main Apr 8, 2026
15 checks passed
@pandemicsyn pandemicsyn deleted the florian/throw-away branch April 8, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants