Restrict ROM file deletion to the ROMS/DELETE grant. The new
DELETE /roms/{rom_id}/files/{file_id} route gated on ROMS_WRITE alone and,
unlike its manual/soundtrack/screenshot siblings, carried no category guard,
so a group holding write-but-not-delete could remove game files from disk
while whole-ROM deletion still required ROMS/DELETE.
Gate mutating streaming routes on ROMS_USER_WRITE instead of ROMS_READ,
matching the play-session routes. ROMS_USER_WRITE is always-on for
authenticated users, but absent from READ_SCOPES, which is all KIOSK_MODE
grants an anonymous visitor. Kiosk visitors all share user_id=-1, so session
ownership could not separate them and any visitor could claim sessions and
overwrite another's save states.
Restore the ENABLE_SCHEDULED_CLEANUP_ORPHANED_RESOURCES gate on the cleanup
task's cron_string. It was dropped in 06cafd4b1, whose message refers to
update_switch_titledb, leaving the documented opt-out inert and scheduling a
destructive task nightly. That commit also broke two of the task's own tests.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Several endpoints authorized cross-user access by the is_public flag (or
by scope alone for streaming) without re-checking whether the parent ROM
or platform is hidden from the caller. A user blocked from a ROM/platform
could still download a public save/state/screenshot attached to it, or
claim a streaming session for it, by supplying the asset/ROM id directly.
Route all four through the existing assert_rom_visible() 404-masking
helper, right after loading the record and before any file access or
broker launch, matching the ROM detail/content endpoints.
- saves.py / states.py / screenshots.py download_* : public sharing no
longer overrides the hidden-resource boundary.
- streaming.py claim_session : hidden ROM/platform can no longer be
launched via its id; broker is never contacted.
Regression tests cover hidden-ROM and hidden-platform cascade for each
endpoint, plus a positive control that public sharing still works when
the ROM is visible.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Per-platform slot capabilities were duplicated across the frontend store's
hardcoded platformCapabilities() map and the backend's pydantic Field bounds,
independent of the broker's own ceiling. Consolidate the RomM-side knowledge
into one _PLATFORM_CAPABILITIES table in the streaming endpoint:
- /config now ships each container's capabilities, and the frontend selector
reads them instead of keeping its own copy.
- The SaveState/LoadState request bounds derive from the table, and the routes
validate the exact per-platform ceiling before calling the broker (clean 422
instead of a broker 502).
The broker remains the ultimate enforcer; RomM no longer keeps two independent
hardcoded copies of its slot semantics.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Extract the repeated urllib request construction (URL, secret, payload,
headers, urlopen, parsing) shared by the six broker functions into
_broker_request and its best-effort _broker_request_safe variant. The
best-effort wrappers collapse to a few lines each and the nosec B310
annotation now lives in one place.
Slim the tests with a _streaming() context manager plus _auth/_claim_ok
helpers, removing the repeated cm.get_config patch boilerplate.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Address review findings on the streaming framework.
Backend (backend/endpoints/streaming.py):
- Session keys now carry a TTL (6h) so an abandoned session (broker
dead / backend crashed) eventually frees the container instead of
wedging it until an admin force-releases; control calls refresh the
TTL so active sessions never expire.
- _container_for_platform validates each entry has a scheme-bearing
host, skipping malformed ones (mirroring /config) so claim/control
return a clean 404 instead of a 500 KeyError on container["host"].
- _parse_host_url / _derive_broker_host reject schemeless hosts that
would produce the broken "//None:8000/..." broker URL and colliding
session keys; _broker_url raises a clear 502 when no usable host.
- save-and-exit with wait=false drains the session (short-lived key)
instead of deleting it outright, so a concurrent new claim can't
/launch on top of a not-yet-dead emulator and lose the in-flight save.
- New tests cover schemeless/missing-host skips, the claim TTL, and
the wait=false drain window.
Frontend:
- stores/streaming.ts: releaseSession/saveAndExit drop the local
session record only after the backend confirms, so a failed release
no longer leaves the user wedged behind their own still-held session.
- v2/views/Player/Stream.vue: disambiguate the 404 from claimSession
(ROM not found vs container not configured) so the message matches
the real failure; new stream-error-rom-not-found i18n key in all
18 locales.
Generated-By: PostHog Code
Task-Id: e091168f-69fd-4d4a-9f12-d473dd3f17c9
Add /api/streaming endpoints for session claim/release, ROM launch,
save states, volume control, and save-and-exit against per-platform
emulator broker containers. Sessions are stored in Redis with atomic
SET NX claims, owner-bound, and admin force-releasable. Config comes
from config.yml (streaming.enabled + containers list) with a
STREAMING_SAVE_TIMEOUT env override for slow-saving brokers.
Includes 19 endpoint tests covering auth scopes, claim races,
ownership, broker failure paths, and force-release.