Skip to content

fix: close the access-control holes found by the security audit (RANCH-8) - #258

Merged
maksymhryzodub-prog merged 13 commits into
mainfrom
fix/RANCH-8-audit-access-holes
Dec 1, 2026
Merged

maksymhryzodub-prog merged 13 commits into
mainfrom
fix/RANCH-8-audit-access-holes

Conversation

@maksymhryzodub-prog

Copy link
Copy Markdown
Contributor

Plane: RANCH-8 · Spec: specs/042-audit-access-holes/ · Release 0.3.130

Closes the five access-control holes the security audit found.

What changes

  1. Accounts made by a limited Admin get the creator's ceiling.
    • POST /users and create_user copy the creator's access lists in the same transaction.
    • When the creator lacks the assistant, the new account gets an exception that switches it off.
    • Changing the password or email of an account that reaches further than the Admin is refused, on the route and on the tool.
    • The admin console shows an amber warning directly above Create user. A limited Admin sees it; the Owner does not.
  2. Only a real sign-in speaks as a person in chat.
    • clientIdFromJwtPayload is now an allowlist: console session (sid), embed token, or the agent's own token.
    • Purpose tokens carry typ (vnc, ext-browser, ext-integration, open-link), and JwtAuthGuard refuses them.
    • A disabled or deleted account is refused on chat paths, and its sockets close when it is disabled.
  3. Stored secrets stay write-only through workspace files.
    • The WorkspaceFiles wrapper denies data/secrets/, data/channels/, data/channels.json and browser-state/ whatever the spelling, on every file surface, for the Owner too.
    • Export leaves those paths out and adds SECRET_STORES_NOT_EXPORTED.txt. Import never removes them.
    • The write-only census has a new section 6.
  4. An ability a limited Admin grants stays within that Admin's ceiling (C10).
    • AssistantAccountAccess.grantedById records the granter.
    • canManage checks at the time of use that the granter still reaches the agent. A gone, disabled or demoted granter gives nothing.
    • The refusal reason is not_covered. The console shows a note to a limited Admin in AccountRow and Advanced.
    • Any Admin save makes the pick theirs, including a switch toggle. The commit security review found that a limited Admin switching on the Owner's pick kept the Owner's reach.
  5. Only the Owner connects a tool server on the assistant or for someone else (C11).
    • start_mcp_oauth refuses anyone but the Owner on the Ranch assistant. Elsewhere it accepts only the caller's own subject (SUBJECT_NOT_YOURS).
    • The runtime route answers 403 on the assistant unless the subject is admin or a live Owner.
    • The callback re-checks who started the sign-in before exchanging the code.

Migration 20261201120000_audit_access_holes:

  • adds grantedById, backfilled from the last writer of each custom pick;
  • adds McpOauthState.startedById and startedVia;
  • deletes pending OAuth states. A sign-in already in progress has to be started again.

Checks

  • api jest, full suite, once: 6604/6619 tests passed. All 15 failures were fixtures with console tokens that lacked sid, which the allowlist now correctly refuses. After the fixtures were fixed, those 3 suites passed 349/349. The granter fix added 2 specs; assistantAccess passes 165/165.

  • Builds and generated clients: API build, generate:swagger and the regenerated admin/app SDKs all OK. nuxt typecheck exits 0 for admin and for app.

  • Script checks: locale:check and i18n:check are clean; test:scripts passes 245.

  • Audit reproductions against the local stack (postgres, API, fake runtime, both consoles). Each script failed on the old build and passes on this branch:

    • audit-accounts 37/37
    • audit-chat-credentials 48/48
    • audit-files 58/58
    • audit-grants 33/33
    • audit-signin 19/19
  • 032 regression set: 16 of 18 scripts pass. The 2 that fail are:

    • routes 37/40: GET /me/activity and POST /me/chats/seen are missing from the script's User-route list;
    • enforce 114/116: a 404 on POST /me/chats/seen after access is removed.

    Both involve CLEAN-285 routes this branch does not touch. They were not measured on main.

  • Gaps: there was no S3 locally, so file list, export and import for story 3 are covered by API specs only. There was no real OAuth provider, so an allowed sign-in was checked up to discovery.

Visual check

Passed at 390×844 and 1440×900, with no console errors and no failed requests.

  • Admin → Users → Create: the warning sits above Create user for a limited Admin and is absent for the Owner.
  • The assistant row and the custom-pick sheet show the grant note to a limited Admin only.

Twin consoles

  • admin: form warning, grant notes, regenerated SDK.
  • app: only the regenerated SDK. The app has no account form, no assistant editor and no file browser. Its chat sends only console or share credentials, which stay allowed, and the 032 app-console e2e checks pass.

🤖 Generated with Claude Code

maksymhryzodub-prog and others added 13 commits December 1, 2026 14:46
…NCH-8)

One migration: AssistantAccountAccess.grantedById (backfilled from the last writer of each custom pick), McpOauthState.startedById and startedVia, and every pending sign-in state dropped: none could be re-checked at its callback.

Co-Authored-By: Claude <noreply@anthropic.com>
…ANCH-8)

Audit §1. POST /users and create_user copy a limited Admin's lists onto the new account in the transaction that creates it, and withhold the assistant when the Admin does not have it. A password or sign-in email change on an account that reaches beyond the Admin is refused, on the route and the tool alike. Disabling an account tells the access lists, which close what it holds open (used by the chat surface).

Co-Authored-By: Claude <noreply@anthropic.com>
Audit §3. clientIdFromJwtPayload, which every chat surface asks, is an allowlist: a console session, an embed token, or the agent's own token. The browser-view link, both extension tokens and the file open link carry a purpose typ that their own endpoints accept (and none, for tokens from before) and JwtAuthGuard refuses. A disabled or deleted account's console session is refused on chat paths and its sockets close. Spec fixtures that stood for console tokens gain the sid every console token carries. auth.types also carries the RANCH-8 grant helpers (grantedBy, noteGrantNotCovering) used by the grant commit.

Co-Authored-By: Claude <noreply@anthropic.com>
…(RANCH-8)

Audit §2. Every caller-facing file surface holds WorkspaceFiles instead of the raw gateway: data/secrets/, data/channels/, data/channels.json and browser-state/ are left out of lists, refused on read, write, delete and open link however the path is spelled, skipped by folder deletes and exports (with a note in the archive) and never written or removed by an import. The census refuses a route or tool that holds the raw gateway unless filed.

Co-Authored-By: Claude <noreply@anthropic.com>
… (RANCH-8)

Owner decision C10. The custom pick in force keeps who stated it (grantedById); the MCP handler notes that granter and manageCaller carries it on the party. canManage's assistant line also asks granterReaches: the Owner's pick works on every agent the person reaches, an Admin's only on agents that Admin reaches at the time of use, and none once the Admin is gone, disabled or a User. Refused for that reason alone, the tool says the ability does not cover that agent (reason not_covered) and names nobody. A limited Admin's new account without the assistant gets an exception switching it off (withholdFor).

Co-Authored-By: Claude <noreply@anthropic.com>
…CH-8)

Owner decision C11. start_mcp_oauth refuses every non-Owner on the Ranch assistant, whatever the subject, and a subject that is not the caller's own anywhere. The runtime route lets through only the Owner's identity on the assistant. The state records who started it, and the callback asks again with that account as it is then, before the code exchange: a refused sign-in stores nothing.

Co-Authored-By: Claude <noreply@anthropic.com>
…grant (RANCH-8)

The new-account form shows a limited Admin an amber block directly above Create user: the account will reach only the agents they can see, and only the Owner can give it more. The assistant-access row and the custom-pick sheet say that abilities they tick work only on agents they can see. Both read the viewer's own row from the user store; nothing is shown to the Owner or an Admin with no lists.

Co-Authored-By: Claude <noreply@anthropic.com>
Route descriptions only; no DTO changed.

Co-Authored-By: Claude <noreply@anthropic.com>
…ing stack (RANCH-8)

audit-accounts, audit-chat-credentials, audit-files, audit-grants and audit-signin assert the fixed behaviour; against a build from before the fix their audit checks fail. accounts and grants also check the new admin copy at 390 and 1440 px. Registered in all.mjs.

Co-Authored-By: Claude <noreply@anthropic.com>
…e-only files (RANCH-8)

The feature dir of specs/042-audit-access-holes with its tasks. The CLEAN-254 text in specs/034 and specs/032 gets a RANCH-8 amendment: an Admin's pick works only within that Admin's current reach. docs/agent-tools.md: the granter clause, secrets kept in the workspace, the subject rule of the review checklist. docs/guides/auth.md: the accepted chat credentials and the purpose typs.

Co-Authored-By: Claude <noreply@anthropic.com>
A limited Admin turning the switch back on for a pick the Owner made kept
the Owner as its granter, so the User's abilities worked on every agent the
Owner reaches. Any Admin save now records the Admin as the granter; only the
Owner or a trusted party carries the earlier granter along.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@maksymhryzodub-prog
maksymhryzodub-prog merged commit 681a998 into main Dec 1, 2026
1 of 2 checks passed
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.

1 participant