Repository navigation
fix(mcp): refuse token changes while impersonating; error on a token no company accepts - #528
Merged
Merged
Conversation
…no company accepts An impersonation session proves no sign-in method of the person's, so a personal MCP token regenerated under it was stored with an empty proof list. Every company was then filtered out and the token answered list_companies and list_projects with empty results, HTTP 200 and no error. Regenerating it also replaced the token the person's own clients were using. Regenerate and disable are now refused while impersonating, like password and sign-in method changes. A token whose proofs satisfy none of the user's active companies now gets an explicit tool error telling them to sign in and regenerate it, instead of empty lists. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Artem Petrov <[email protected]>
artempartos
added a commit
to Hitin/flow
that referenced
this pull request
Oct 21, 2026
* commit '2ecb0ecb': fix(admin): keep form fields dark after a Turbo visit (AixleHQ#533) feat(overview): rename Total Spend card to Token Cost (AixleHQ#532) fix(admin): preload company session limits on the companies index (AixleHQ#523) fix(board): keep the board settings gear on the toolbar row (AixleHQ#524) feat(capacity): give every AWS Marketplace company at least 3 workers (AixleHQ#531) fix(mcp): refuse token changes while impersonating; error on a token no company accepts (AixleHQ#528) feat(feature-flags): registry, resolver and Feature facade (1/7) (AixleHQ#526)
Merged
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.
Problem
A personal MCP token regenerated while a super admin was impersonating a user authenticated fine, but
list_companiesandlist_projectsreturned{"companies": []}/{"projects": []}with HTTP 200 and no error. Regenerating it again from the same session did not help. Signing in normally and regenerating did.Cause
impersonate_userstarts the impersonation session withsign_in(user, impersonator:)and no provider, so the session holds no sign-in proofs. The web gate lets impersonated requests through (company_auth_policy_satisfied?), so nothing in the UI hints at it.regenerate_mcp_tokenstorescurrent_user_session.proved_provider_ids, which is[], not NULL.User#mcp_token_proven_provider_idsfalls back to the password provider only for NULL.Auth::PolicyResolver.satisfied_company_ids(provider_ids: [])buildswhere(identity_provider_id: []). Rails treats that as a contradiction and returns[]without running a query. Every personal tool then scopes towhere(company_id: []).Production logs matched this exactly. Each regenerate from the impersonation session wrote an empty proof list. The
/mcpcalls made with that token ran only the token lookup, with no company or project query at all, so the failure left nothing in the logs. Regenerating also replaced the token the person's own clients were using.Fix
refuse_impersonationguards on passwords and sign-in methods. The fix deliberately does not make an impersonation-issued token work: that would give the operator a long-lived credential acting as the person, which outlives the impersonation and its audit trail.[], and tokens whose proofs only satisfy companies the user has since left.Not done: refusing to issue a token with an empty proof list. Through the web, a non-impersonated session without proofs never reaches the profile (
enforce_company_auth_policysends it to step-up, and super admins are redirected to/admin), so that guard would be dead code.Tests
test/integration/web/profile_controller_test.rb: an operator impersonating a user cannot regenerate or disable that user's token. The user's existing token keeps working and its proofs are unchanged.test/integration/personal_mcp_sign_in_policy_test.rb: a token issued with no proofs gets the explicit error fromlist_companiesandlist_projects.Both new tests fail without the fix. Locally (isolated container and DB), every test file that touches personal MCP, MCP tokens or impersonation ran: 394 runs, 0 failures. There were 7 errors, all
Vite Ruby can't find entrypoints/admin*from a stale localpublic/vite-testcopy; they render admin pages this change does not touch.rubocopandbrakemanare clean. The full suite is left to CI.🤖 Generated with Claude Code