Commit Graph

36 Commits

Author SHA1 Message Date
Georges-Antoine Assi
4159710e79 docs(api): document the error responses routes raise (#5693)
* docs(api): document error responses for roms routes

Describe every 4xx and 5xx the rom routes and their helpers raise in each
decorator's responses=, so the OpenAPI schema lists them. A hidden rom,
platform or file is described like a missing one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(api): document error responses for saves routes

Describe every 4xx/5xx the saves, states, screenshots, snapshots,
play-sessions and sync routes raise in their responses=, and rewrite the
states identifiers docstring that carried Args/Returns blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(api): document error responses for devices routes

Describe the 4xx/5xx statuses that the device, device auth, install,
client token, notification, notification channel, sync channel and
heartbeat routes raise, and fill the empty install route entries.
Rewrite the setup and heartbeat docstrings that published Args and
Returns blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(api): document error responses for streaming routes

Describe the 4xx and 5xx statuses the streaming, memory card and netplay routes raise in their responses= declarations, and replace the Args: blocks in route docstrings that FastAPI published verbatim.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(api): document error responses for admin routes

Describe the 4xx and 5xx statuses the config, permissions, user, auth,
tasks, logs, activity and export routes raise, and rewrite their
Args/Returns docstrings as plain operation descriptions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(api): document error responses for library routes

Describe the 400/403/404/409/500 statuses the collection, feed, firmware,
platform, music, playlist and search routes raise, and replace route
docstrings that carried Args/Returns blocks with plain sentences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(api): describe private collections and playlists as missing

Matches #5686, where another user's private collection or playlist
answers 404 and a play session on a hidden rom answers like a missing
one. The read routes drop their 403, and the write 403 now covers only
a public resource another user owns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(api): address Greptile review on route error docs

Fold the nine multi-paragraph route docstrings into one line, and keep
the device-scope 403 descriptions in utils/auth.py next to
resolve_device, which raises them, instead of in both saves.py and
states.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(api): plain-prose pass on route error descriptions

Spell out clipped error descriptions, replace internal slang (picked,
taken, live, moved past), name the parameter an ID comes from, and split
the long save conversion 400s into sentences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 09:11:20 -05:00
Georges-Antoine Assi
c0a67d674d fix(player): record the device that wrote a state and skip other devices' states at start (#5531)
* fix(player): boot another device's save over a state from the same quit

States record no device, so the start screen could not tell a state written
by another client's core (Argosy) from one this browser wrote. When the newest
save names a device other than this browser and the newest state was written
within a few seconds of it, default to the save. This browser's own Save and
Quit still resumes from its state.

Fixes #5199

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(player): keep the newer-save warning beside a same-quit state

Addresses Greptile review on #5531: skipping a state from the picked
save's quit returned no warning even when a newer save existed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(states): record the device that wrote a state

States now carry origin_device_id like saves. POST /states and
PUT /states/{id} take an optional device_id, and new content takes the
writer's device (or none when the client names none). The web player
sends this browser's device id with every state, including held ones.

The start screen no longer defaults to a state tagged with another
device. The same-quit timing rule stays only for untagged states, which
covers states stored before this change and clients that send no device.

device resolution moves from endpoints/saves.py to utils/auth.py so
both asset endpoints share it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(player): drop the same-quit timing rule for untagged states

The start screen and the newer-progress warning now go by the state's
recorded device alone: an untagged state counts as this browser's, and
a state tagged with another device is neither the default nor a reason
to warn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(player): cover untagged states beside another device's save (code-review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(player): simplify the resume fallback and repair a mis-collated state column (simplify)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(states): trim the origin device column comment (review-polish)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 07:58:51 -05:00
Georges-Antoine Assi
f66950551a fix(sync): bind device tokens to their device; dial only known push-pull hosts (#5460)
* fix(sync): bind device tokens to their device; dial only known push-pull hosts

A client token paired to one device could read, reconfigure, delete, sync
saves for and record play sessions as any other device of the same user.
Device CRUD, sync negotiate/complete, push-pull trigger, the save device
resolver and play-session ingest now treat another device as not found for
a bound token, through a shared require_token_device helper. GET /api/devices
lists only the bound device.

Push-pull let any user with devices.write point ssh_host at any host and
port, and the connection error surfaced through the sync session, so the
worker could be used to probe the internal network. The SSH handler now
refuses a host with no trusted key or CA in the admin's known_hosts before
dialling it, which keeps LAN handhelds working while nothing else is
reached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(device): revoke a deleted device's tokens; scope registration matches

Addresses Greptile review on #5460. Deleting a device now deletes the client
tokens paired to it, since the foreign key's SET NULL turned them into unbound
tokens that reach every device. Registration with a bound token only matches
its own device by fingerprint, so it can no longer reset syncs or overwrite
capabilities on another device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(sync): bind heartbeat, sync session and online reads; pin push-pull ports

pr-ready step 2 (code-review xhigh --fix).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(device): one require_device helper; parse known_hosts once

pr-ready step 3 (simplify).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(sync): narrow await_args before reading known_hosts

pr-ready step 4 (review-polish).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(sync): plainer comments on the push-pull allowlist and token revoke

pr-ready step 5 (humanizer).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(device): keep bound tokens off other tokens; cascade tokens with their device

A device-bound token can no longer create tokens, or regenerate, pair or
revoke a token of another device or an unbound one. The save session_id
counter only counts a session of the caller's bound device.

client_tokens.device_id now cascades on device delete (0159), so no path
can leave an unbound token behind, and deleting a device records a
client_token.revoke audit event for each token it takes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(env): drop the push-pull allowlist note from env.template

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 08:57:33 -05:00
Georges-Antoine Assi
0f75e6aaf4 fix(client-tokens): let a client token revoke itself without me.write (#5419)
* fix(client-tokens): let a client token revoke itself without me.write

A device that signs out or re-pairs had no way to revoke its own token
unless it held me.write, which also lets it mint tokens and approve
pairings. DELETE /api/client-tokens/{id} now skips the me.write check
when the id is the token authenticating the request.

Fixes #5274

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(client-tokens): code-review pass on self-revoke

Annotate raise_auth_error as NoReturn, trim the delete_token docstring, and
cover a me.write token revoking a sibling, the revoked token failing to
authenticate, and socket closure on self-revoke.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(client-tokens): revoke the calling token through DELETE /current

Self-revoke moves to an id-less route so a device never needs to know its
token id, and DELETE /{token_id} keeps me.write in its decorator and in
OpenAPI. The device-authorization token response now also returns token_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(client-tokens): simplify pass, reuse raise_auth_error for /current

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* revert(client-tokens): drop DELETE /current and the device-flow token_id

Self-revoke stays on DELETE /{token_id} with the in-handler check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(device-auth): return the issued token's id from the device token poll

A device paired through the device-authorization flow can now revoke its
own token with DELETE /api/client-tokens/{id}, as tokens from /exchange can.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Update docs/BACKEND_ARCHITECTURE.md

* docs: format client tokens table

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 19:05:52 -04:00
Georges-Antoine Assi
96e2c2ad42 refactor(backend): pr-ready follow-ups for device installs
- Replace the inline bytes-to-text decodes with redis_handler.as_text
- Add utils.auth.token_device_id for a request's token-bound device
- Look up a group's member tokens in one query and close them in one pass

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 15:04:56 -04:00
Sam Dornan
7c2b049b70 chore(mypy): drop warn_return_any and validate provider responses with strict JSON (#4826) 2026-09-26 20:13:55 -04:00
zurdi
d9d65d8b56 refactor(audit): apply the pr-ready simplify pass
- record() takes the request as its actor, and a target can be a
  function: the lookups that name it now run inside the recorder's error
  handling, and for downloads only once the dedupe lets them record.
  That also restores the minimal visibility query on the file route.
- One changed_fields/change pair for rom, user, collection and platform
  edits, one collection helper, AuditActor.anonymous, a shared
  count_in_window and current_device_id, one test helper for recorded
  events and one fixture for audit events.
- The describers share simple/counted/visibility builders and the
  eventData readers with notifications, join lists per locale, and treat
  any *.delete as unlinked.
- EventLog builds one item list with the phase folded in, keeps each
  event's sentence across pages, formats days once, and loads users
  through the users store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 02:45:12 +02:00
zurdi
01483dd715 fix: disconnect a session's sockets when it is revoked
A socket joins its user's room, and an admin's the admin room, once at
connect time, so logging out or revoking a user's sessions left their open
sockets receiving notifications and the log stream. Each socket is now
recorded against the login session that opened it, and removing a session
disconnects those sockets on whichever worker holds them.

The main server takes one disconnect handler, so it moves next to the
connect handler and runs the activity cleanup as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 14:23:39 +02:00
zurdi
78eef900b9 feat: update logs endpoint to require 'logs.read' scope and adjust related authorization checks 2026-06-20 09:55:10 +00:00
Georges-Antoine Assi
f107dc2752 changes from bot rview 2026-03-22 17:17:14 -04:00
Georges-Antoine Assi
c61f52ebed clean create web device 2026-03-15 20:25:38 -04:00
Georges-Antoine Assi
e1b07cacfc make devices actually unique 2026-03-15 20:09:33 -04:00
Georges-Antoine Assi
29112b4ddc create device on login web 2026-03-15 11:25:39 -04:00
Zurdi
4b9e76f550 backend structure refactor 2024-01-12 23:44:27 +01:00
Zurdi
eea7e41940 docstrings added to endpoints + organized imports + formatted code 2024-01-09 16:22:31 +01:00
Georges-Antoine Assi
3965ca1997 Add basic auth + fix tests and typing 2023-08-23 11:21:01 -04:00
zurdi
f4f936f624 user avatar and enable/disable user support added 2023-08-23 14:16:31 +02:00
Georges-Antoine Assi
92c505fcac First round of self cleanup 2023-08-18 21:12:31 -04:00
Georges-Antoine Assi
b92844ba80 Microfixes + get edit working 2023-08-18 10:03:34 -04:00
zurdi
5f598443eb starlette CSRFMiddleware import fixed 2023-08-18 12:17:43 +02:00
Georges-Antoine Assi
0b5a09d53f Add test for rom endpoint 2023-08-13 14:10:27 -04:00
Georges-Antoine Assi
6e87522f96 Add tests for platform 2023-08-13 12:44:23 -04:00
Georges-Antoine Assi
da4c318f6c Add tests for auth utils 2023-08-13 11:10:59 -04:00
Georges-Antoine Assi
9d0d7f7631 Fix bad jwt tokens 2023-08-12 22:15:24 -04:00
Georges-Antoine Assi
5943489f51 Oauth scheme and security list 2023-08-12 21:46:32 -04:00
Georges-Antoine Assi
8c39b8dbe6 Use random secrets for cors and middleware 2023-08-12 10:10:12 -04:00
Georges-Antoine Assi
590ea89972 Place auth behind flag 2023-08-11 13:42:16 -04:00
Georges-Antoine Assi
a5256dfe01 Move secret key to env variable 2023-08-11 13:02:13 -04:00
Georges-Antoine Assi
1b510d5499 Split oauth endpoint 2023-08-11 10:47:12 -04:00
Georges-Antoine Assi
8d41a87659 Add csrf token check 2023-08-11 09:47:10 -04:00
Georges-Antoine Assi
6cf6f6ca78 Implement refresh tokens 2023-08-11 00:30:30 -04:00
Georges-Antoine Assi
a8a402d250 Add scopes and roles 2023-08-10 23:37:05 -04:00
Georges-Antoine Assi
b2ca819c16 Add session middlware + redis back auth 2023-08-10 09:58:51 -04:00
Georges-Antoine Assi
cb306d3099 Working authentication via starlette 2023-08-10 00:06:25 -04:00
Georges-Antoine Assi
32a79ac52d Switch to cookie based auth 2023-08-09 22:48:38 -04:00
Georges-Antoine Assi
9c3bc6b842 Add jwt based auth 2023-08-09 22:15:05 -04:00