Files
romm/backend/handler/streaming
Georges-Antoine Assi 26dff477d7 fix(auth): bound new client tokens by the caller's scopes and stop delegates removing admins (#5346)
* fix(auth): bound new client tokens by the caller's scopes and stop delegates removing admins

- Creating a client token, approving a device, and regenerating or pairing
  an existing token now check against the scopes of the credential making
  the request rather than the whole account's. A narrow client token can no
  longer mint, or recover the secret of, a broader one. Session and basic
  auth carry the account's scopes, so they behave as before.
- Deleting an admin requires the caller to be an admin, mirroring the
  existing rule for creating one, since users.write can be delegated.
- Editing another user requires the users.write scope on top of the admin
  role, so an admin's me.write-only token can't change other accounts.
- own_only is rejected (422) on grants and overrides for entities with no
  owner (platforms, roms, firmware, users, tasks, logs), where it silently
  meant "all". The catalog exposes the ownable entities and the permission
  matrices only offer "own" on those.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(permissions): keep owner-less own_only grants' access on save

Addresses Greptile review on #5346:
- An own_only delete grant on an entity with no owner allows nothing
  today (delete has no coarse scope and the fine check runs with
  owned=False), so it is now dropped from group grants, or turned into
  a revoke for overrides, instead of being saved as full delete access.
  The matrices show it the same way.
- The group dialog no longer saves when the permission catalog failed
  to load, which would have stripped every own_only grant.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(auth): require users.write in the credential to act on another user (pr-ready: code-review)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* refactor(auth): share client token effective scopes and canOwn (pr-ready: simplify)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(permissions): tighten grantEffect docstring and matrix comment (pr-ready: review-polish)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(auth): make user, token and streaming admin rules consistent

- Acting on another user (edit, delete, RA refresh) needs users.write in
  the credential, and only admins may target an admin or grant the admin
  role. One assert_admin_for_admin helper now backs add_user, invite
  links, update, delete and admin token revocation.
- Re-issuing a client token's secret (regenerate, pair) needs every scope
  it stores; deleting one needs every scope it currently grants, so a
  narrow token can't remove a broader sibling.
- Streaming admin overrides need users.read or users.write in the
  credential, not just the admin role.
- Migration 0154 rewrites stored own_only grants and overrides on
  owner-less entities to the access they already gave, so the frontend
  normalisation and the catalog save gate are gone.
- own_only is no longer rejected on revoke overrides.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-26 09:35:17 -04:00
..