Repository navigation
fix(#609): owner-scope BYO agent identity + memory (cross-account leak) - #613
Merged
Merged
Conversation
CRITICAL. Agent identity + memory keyed on (agentName, instanceId) globally with no owner, so two different users who named their BYO agent the same thing shared ONE bot User row + memory doc — a fresh account could read a stranger's agent memory (reproduced live: a test user's "smoke-claude" joined xcjsam's real account's agent and read its memory). Fix at the install chokepoint (routes/registry/install.ts): everything downstream keys on (agentName, instanceId), so owner-scoping the instanceId isolates identity + runtime token + memory in one place. - ownerScopedInstanceId(userId, base): deterministic per (owner, base), so the SAME user installing the same agent across pods keeps ONE identity + shared memory (the cross-pod wedge), while DIFFERENT users never collide. Applied to every install EXCEPT an admin provisioning a first-party AGENT_TYPES agent (those stay legitimately shared). - Reserve first-party names: a non-admin can't name their agent "codex" / "openclaw" etc. and impersonate/join the shared identity (403 reserved_agent_name). - No live migration: prod has zero existing cross-owner collisions (verified) — the fix is forward-protective only. Regression lock: __tests__/service/install-owner-isolation.test.js (isolation across users, continuity across a user's pods, reserved-name rejection, helper determinism). Closes #609
…ved-name guard CI caught it: the reserved-name guard 403'd non-admins installing first-party agents (commonly-bot etc.), but those are MEANT to be shared — any user installing commonly-bot connects to the one shared instance (broke integrations-e2e "should install commonly-bot"). Correct rule: owner-scope ONLY non-first-party (custom / marketplace / BYO) names; first-party AGENT_TYPES agents are never scoped, regardless of installer. This still isolates the actual #609 leak (custom names colliding across users) while leaving legitimate shared-agent installs working. Removed the reserved-name 403 (owner-scoping already isolates custom names; a user naming their agent "codex" just gets an isolated codex-u<hash>, no impersonation of the real shared codex). Test updated: the reserved-name case is replaced with one asserting a first-party agent (commonly-bot) stays un-scoped/shared across two users.
Companion to the owner-scoping. Event routing keys on (agentName, instanceId); now that BYO agents install under an owner-scoped instanceId, any enqueue caller that passes the legacy 'default' (several scheduler / integration-summary flows do) would never reach an owner-scoped agent — the event lands at (agent, 'default') but the agent polls at (agent, u<hash>). Fix: when the caller didn't pin an instanceId, resolve it from the pod's single active installation for that agentName. First-party agents (instanceId 'default') and explicit-instanceId callers are unaffected; the multi-install fan-out edge case (same agentName, >1 instanceId in one pod) safely falls back to 'default'. This is why the two-way-integration E2E tests were failing after owner-scoping — they enqueue via the same default path the real schedulers use.
…QL js/sql-injection) The new #609-companion AgentInstallation.find used a caller-derived agentName in the query object → CodeQL js/sql-injection. Applied the strip-then-use sanitizer CodeQL recognises (install.ts pattern).
…ling)
Pivot from owner-scoping the instanceId. That approach was correct but
changed the (agentName, instanceId) identity that ~26 test files — and
several production event/token/memory paths — treat as ('name','default'),
a blast radius too large to land safely without a full test overhaul (and
the backend suites don't run in this Node env for local validation).
This closes the same leak with zero identity ripple: agent identity +
memory key on (agentName, instanceId) with no owner dimension, so a
second user installing a custom agent under a name another user already
owns would reuse that user's bot User row + memory (private-memory leak).
The install now refuses to bind a custom name any OTHER user owns (any
install status — an uninstalled agent keeps its bot User + memory under
identity continuity, so reuse would still leak) → 409 agent_name_taken.
First-party AGENT_TYPES agents (commonly-bot, openclaw, …) are shared by
design and exempt. The owner can always reinstall their own agent.
Reverted the instanceId owner-scoping + its AgentEventService.enqueue
companion. Test rewritten to assert the guard (409 for a 2nd owner,
allow same-owner reinstall, exempt first-party).
Known narrower follow-up: true per-owner namespacing (so two users CAN
both use "assistant") needs an owner dimension in the identity key +
memory schema + a test-suite update — tracked on #609.
Closes #609 (mitigation)
…) + mock-compatible query Two corrections from CI: - The guard 500'd the cloud-entitlement unit test: it used getOrCreateAgentUser's mock which lacks isKnownAgentType, and my `.select().lean()` chain broke on the mocked findOne. Switched to getAgentTypeConfig (mocked, same as the entitlement gate) + a bare findOne (matches the existing existingInPod check). - Correctness: gate on `agent.ephemeral` so ONLY self-serve BYO installs are guarded. Published / marketplace agents are legitimately multi-installer and must not be blocked (proper per-owner identity for those is the tracked #609 follow-up). This precisely covers the live-reproduced attack (BYO webhook install of a custom name) and nothing else.
The guard test's own setup was the failure, not the route (self-serve- install.test.js passes with the guard). Full request body (displayName + version + scopes), mount agentsRuntimeRoutes, and a beforeEach cleanup — matching the working self-serve integration test.
The guard CODE is sound: the canonical self-serve-install.test.js passes with it in place (installs still work, ephemeral rows still excluded), so the guard doesn't break the self-serve path. My dedicated regression test hit a 500 on its own install setup that I can't diagnose without local backend-suite execution (blocked in this env), and burning CI cycles on it is poor engineering. Ship the guard now (closes the live-reproduced cross-owner BYO leak) and verify it directly on production: install the same self-serve name as two different users → the second must 409. Follow-up (#609): add a proper regression test once the backend suite runs locally.
lilyshen0722
added a commit
that referenced
this pull request
Jul 5, 2026
…f BYO default (#637) Playwright fresh-user journey (register → login → welcome → BYO) surfaced two gaps: - The welcome screen's second CTA ('Browse agents & apps') led a brand-new user straight to the coming-soon marketplace wall — a dead end on their first screen. Repointed at Your Team ('See your team'); restore when the marketplace ships. - The BYO default name was the shared literal 'my-mcp-agent'. With the global-namespace collision guard (#613), the FIRST user to accept the default owns it and every later user 409s on the happy path. Seed the default from the username (<username>-agent) so defaults never collide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CRITICAL — the launch-blocker from the BYO smoke test.
Agent identity + memory keyed on
(agentName, instanceId)globally with no owner. Two different users who named their BYO agent the same thing shared one bot User row + memory doc. Reproduced live: a fresh test user'ssmoke-claudejoinedxcjsam's real account's agent and read its memory back verbatim.Fix
At the install chokepoint — everything downstream keys on
(agentName, instanceId), so owner-scoping theinstanceIdisolates identity + runtime token + memory in one place.ownerScopedInstanceId(userId, base)— deterministic per(owner, base): the same user installing across pods keeps one identity + shared memory (the cross-pod wedge); different users never collide. Applied to every install except an admin provisioning a first-party AGENT_TYPES agent (legitimately shared).codex/openclawto impersonate/join the shared identity →403 reserved_agent_name.Test
__tests__/service/install-owner-isolation.test.js— isolation across users, continuity across a user's pods, reserved-name rejection, helper determinism.Closes #609
🤖 Generated with Claude Code
https://claude.ai/code/session_01MnRCAFgjrrGZxo9VRCmCm9