* feat(auth): use the OIDC picture claim as the user's avatar
On each OIDC sign-in, a user with no avatar, or one synced from the
provider earlier, gets the picture claim stored as their avatar. An
uploaded avatar is never replaced. The download goes through the
SSRF-guarded client (the configured provider's origin may reach a LAN
address), is capped at 5 MB, must sniff as a supported image, and any
failure is logged without blocking the sign-in.
Closes#4297
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(auth): address review on the OIDC avatar sync
Addresses Greptile's review on #5730:
- ask the UserInfo endpoint when the ID token has no picture claim
- keep an avatar uploaded while the picture downloaded
- allow only the OIDC provider's origins to reach private addresses
- trim docstrings and narrow await_args in the callback test
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(auth): type the OIDC avatar test helpers for mypy
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* pr-ready: code-review
Bound the OIDC picture download with an overall deadline, trust the
OIDC CA bundle, catch hostname encoding errors so sign-in never 500s,
and set the synced avatar with a conditional update so a concurrent
upload wins.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* pr-ready: simplify
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* pr-ready: review-polish
Type the pytest fixtures and helpers in the OIDC avatar tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* pr-ready: prose
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(auth): remove the synced OIDC avatar when the user uploads one
Once avatar_path points at the uploaded avatar.<ext>, the sync never
touches the user's avatar again, so the old oidc-avatar.<ext> file
would otherwise stay on disk for good.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix(auth): check a dummy hash when the username is unknown
Password sign-in skipped bcrypt for usernames with no account, so a
failed login answered far faster for an unknown name than for a real one.
Verify against a throwaway hash in that case so both take the same time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(auth): run the dummy bcrypt check for accounts without a usable hash
OIDC-provisioned and empty-hash accounts skipped bcrypt, so a failed
password sign-in for them answered faster than for an unknown username.
verify_password now falls back to the dummy hash whenever the stored one
is unusable, and the tests assert bcrypt ran on a valid hash.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix(auth): issue a new session id when the session changes identity
Logging in (password or OIDC) wrote the user into the session named by
the request cookie, so a session id set in the browser beforehand kept
working for whoever held it after the login. The session middleware now
writes the session under a fresh id whenever its user changes, and
deletes the previous record and closes its sockets.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(auth): leave the session cookie alone when a refresh finds it gone
A request still in flight on a session that a concurrent login rotated
away failed its refresh and answered with an expiring session cookie,
which wiped the fresh cookie the login had just set. A failed refresh
now sends no Set-Cookie at all.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* chore(coherence): adopt Coherence with specs, invariants and a PR report
Install @posthog/coherence as a frontend dev dependency and wire its
Claude Code hooks into the committed .claude/settings.json, so every
agent session in the repo gets the vocabulary, specs, journal and checks.
The hooks call the binary under frontend/ through $CLAUDE_PROJECT_DIR.
Declare 23 components and the entrances that carry outside trust, and
six invariants, each refuted with a deliberate break before it counted:
- every /api route requires auth and its scopes, except a named public
list (new route sweep in tests/endpoints/test_route_guards.py)
- a hidden rom, platform or firmware answers every id route exactly as
a missing id would (new sweep over every method of every id route)
- the unscoped save, state and screenshot fetches by id are reached only
from their own routers (chokepoints)
- validate_path never resolves outside its base folder
The PR workflow runs in comment mode: one report comment, failing only
when Coherence itself breaks. Trunk skips Prettier and markdownlint on
*.spec.md and *.practice.md, since Prettier escapes their globs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(routes): satisfy mypy in the route guard sweep
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(coherence): record the worktree test database enactment
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(roms): answer a hidden rom like a missing one on file routes; tighten route sweeps
Addresses Greptile's review on #5584.
The rom file delete and reading-progress routes answered "File not found"
for a hidden rom but "Rom with id N not found" for a missing one, so a
caller could tell them apart. They now raise the same not-found.
The route sweeps now reach the checks they claim to test: a protected
route with no scopes counts as public (its guard admits anyone), write
requests carry a body and upload name so validation can't answer first,
RomFile-keyed routes get a real file id, error bodies are compared with
the id normalized, and the rom routes are swept with the rom hidden
directly, through its platform, and by the unrated filter.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(coherence): tighten route guard sweeps and isolate oracle test databases (code-review)
- Count a route as protected only when its endpoint is the scope-checking
wrapper with non-empty scopes, not just when it declares the bearer scopes.
- Treat 401 and 403 like 422 as never reaching the visibility check, and
sweep /api/streaming/states/{rom_id}.
- Run pytest oracles with a per-run ROMM_TEST_DB_TAG unless one is set.
- Use the shared setup-frontend action and ubuntu-24.04 in the workflow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(tests): simplify route guard sweeps and path tests (simplify)
- Mark scope-guard wrappers with required_scopes so the auth sweep reads a
public attribute instead of the private closure.
- Derive the entity regex from one segment list, ask each missing id once,
and run the three hide scenarios through one sweep helper.
- Fold the new validate_path inputs into the existing valid, traversal and
absolute path tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(coherence): trim workflow comments (review-polish)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(filesystem): restore the validate_path property test the paths invariant cites
Filesystem.spec.md names test_validate_path_never_escapes_its_base as the
invariant's evidence, and Coherence selects it by name.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(coherence): run hooks from the local binary instead of npx
Each hook calls frontend/node_modules/.bin/coherence directly and exits 0
when it isn't installed, so sessions without frontend deps (fresh
worktrees, backend-only setups, cloud setup still installing) don't report
a hook error on every tool call, and no hook pays npx's startup.
Also commits the journal and run records left by earlier sessions, which
.coherence/.gitignore keeps as durable records.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(tests): share the bearer, user token and hide helpers
Tests built the same Authorization headers and HiddenEntity rows in about
40 local copies, and two modules imported private helpers from other test
files. They now use bearer, user_headers and hide from tests/auth_helpers.py.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(endpoints): one 404 for a missing or hidden rom, platform or firmware
Each route wrote the missing-row 404 and the hidden-row 404 separately and
had to keep them identical by hand. visible_rom_or_404,
visible_platform_or_404 and visible_firmware_or_404 take the lookup result
and raise one answer for both, either the standard not-found or a bespoke
detail. Re-reads after a write keep a plain not-found check, so an edit that
hides the row doesn't turn into a 404 after it succeeded.
The RomFile-keyed routes (/roms/{file_id}/files, .../files/content/{name},
/roms/{file_id}/patch) name their path parameter file_id instead of id, so
the route sweep reads which id a route takes from its path and drops its
hand-kept list. URLs are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(setup): develop inside WSL on Windows
@posthog/coherence installs only on Linux and macOS, so npm install in
frontend/ fails on native Windows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(coherence): record the whole-repo chokepoint run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(types): regenerate API types for the file_id patch route
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix(sync): cap play sessions on sync completion and require roms.user.write
The completion endpoint fed an unbounded play_sessions list to the same
ingest as POST /api/play-sessions, which allows 100 per batch and requires
roms.user.write. Apply both rules before the session is completed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(config): reject empty platform binding and version values
config.yml exits on load when a platforms or versions value is empty, so
the API must not write one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(collections): require smart collection criteria to be a JSON object
Any other JSON value was stored, then failed the response schema and broke
the smart collection list for every user who could see the collection.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(stats): require roms.read on /api/stats
Anonymous callers were served counts over the whole library, including
platforms and ROMs hidden from users. The UI only calls it after login.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(permissions): apply ROM visibility to filters, saves, play sessions and collection removal
/api/roms/filters aggregated facet values over the whole library, GET
/api/saves/{id} and GET /api/play-sessions returned the caller's own rows on
hidden ROMs, and removing ROMs from a collection could drop members hidden
from its owner. The facet visibility clauses move onto RomVisibilityFilter so
stats and filters share them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(webhooks): keep non-admin webhooks off the admin's internal metadata origins
The SSRF exception for a self-hosted Playmatch or Hasheous applied to every
request, so a user's webhook could reach any path on that private origin.
Non-admin webhooks now validate and connect with an empty allowlist.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(saves): bound total decompressed size when hashing zip archives
Zip content hashing capped each entry but not the archive, so many
entries each under the cap could still decompress and hash far more
than any real save or memory card holds. Budget the decompressed bytes
across the whole archive and cap the entry count; callers keep treating
an over-budget archive as an unknown hash.
The chunked, budgeted entry reader is shared with the memory card
archive check, and the RetroArch store path now hashes off the event
loop like its siblings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(psp): clamp LZ4 literal and match copies to the ZISO block size
The ZISO block decoder appended literals and copied matches for their
full encoded length before checking the output size, and an LZ4 length
can be extended without bound by 0xFF bytes. A small crafted block
could therefore expand far past the block size before being truncated.
Clamp each copy to the room left in the block, stop once it is full,
end the block on a truncated match offset, and copy matches with slices
instead of a per-byte loop (overlapping matches repeat their pattern).
Output for valid blocks is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(auth): revoke OAuth tokens when a user's credentials change
A password change, admin reset, reset-link reset or rename cleared the
account's web sessions, but its OAuth access tokens kept working until they
expired and its refresh tokens could still be exchanged at /api/token.
Revoking a user's credentials now also records a per-username revocation
time in Redis, kept for the longest token lifetime. Bearer validation and
refresh consumption reject any token whose iat is at or before it. OAuth
tokens now carry a sub-second iat, so a login right after the change still
works; a token without iat counts as older than any revocation.
The revocation is keyed by the token's sub, the same username sessions are
keyed by, so a rename revokes tokens issued under the old name even if
another account later takes it. Client (API) tokens are left alone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(api): reject local file URLs for user-supplied covers and manuals
file:// and launchbox-file:// URLs are meant for covers and manuals that
a scan records from gamelist.xml or LaunchBox metadata. The collection
create/update endpoints and the ROM update endpoint passed a user-supplied
url_cover (and url_manual) straight to the resource handler, which copied
whatever library file it named into the entity's resources. That let any
user with collections.write or roms.write pull files they cannot otherwise
read, including those of hidden platforms and ROMs.
These endpoints now answer 400 for a local file URL, unless it is the value
already stored, which the edit forms echo back on every save.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(resources): bound cover downloads and decodes
Remote covers, screenshots, manuals, badges and media files were streamed
to disk with no size limit, and a gzip-encoded body was read whole and
inflated in memory. Downloads now go through one helper that counts bytes
against MAX_ASSET_UPLOAD_SIZE_BYTES, inflates gzip incrementally under the
same cap, and aborts past it, so the partial file is removed and any
earlier copy kept.
Covers are also bounded once on disk: a still image whose header declares
more than MAX_COVER_PIXELS is discarded before it is decoded (and an
uploaded one is refused with a 400), and a DecompressionBombError while
deriving the small cover now discards the download instead of failing the
request and leaving the file behind.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test: fix mypy errors in the new tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix: address Greptile review on permission and input hardening
- Date OAuth tokens to before the credential check, so a password change
that lands during the check revokes the tokens it issues.
- Apply ROM visibility to play sessions in SQL, before the page slice.
- Reject truncated gzip bodies and inflate every gzip member.
- Shorten the zip budget comment; stream real httpx2 responses in tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix: apply code-review findings on permission hardening
Revoke OAuth tokens and sessions on user deletion, apply ROM visibility to
GET /states/{id}, validate update_collection rom_ids, run get_rom_filters off
the event loop, and reuse the shared httpx client factory for webhooks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor: apply simplify pass on permission hardening
Read the OAuth revocation stamp through the async cache, share the
play-session batch-size check, raise a plain OSError for oversized downloads,
and drop a dead slice in the LZ4 decoder.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* style: apply review-polish pass on permission hardening
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(play-sessions): filter rom_id and device_id on PlaySession after the visibility join
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* chore(deps): update backend dependencies
* fix: keep empty form values cleared under FastAPI 0.162
FastAPI 0.149 started parsing an empty form string as a missing field, so
the field's default (None) applied. Clients clear a user's email, a
collection's description or remote cover, and ROM fields by sending them
empty, and those updates were silently ignored. keep_empty_string restores
the submitted "" from the raw form.
The CSRF and session tampering tests set a cookie next to the one the
TestClient jar already held for the response domain; the client now sends
both and the original wins. Clear the jar first, as a browser would replace it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(deps): hold fastapi below 0.149
FastAPI 0.149 parses an empty value in a form model as a missing field, so
PUT /api/users/{id} with email="" kept the old address. Stay on 0.148 and
stop Renovate from proposing 0.149+ until the update endpoints can tell an
absent field from an empty one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(deps): hold fastapi at 0.146
FastAPI 0.147 started reading a missing bool field in a form model as
false, so PUT /api/users/{id} with only a role also disabled the account.
Keep the version master runs and cap Renovate below 0.147 until the update
endpoints tell absent, empty and false apart themselves.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* feat(oidc): add OIDC_AUTH_PARAMS for extra authorization request parameters
Lets admins send provider options such as prompt=select_account on the
OIDC login redirect. Authlib's authorize_params override its generated
state, nonce and PKCE values, so the parameters RomM manages are
rejected at startup.
Closes#5406
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(oidc): trim parse_oidc_auth_params docstring
Addresses Greptile review on #5431.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix(db): bump client token and device last-used timestamps without a prior read
update_last_used() and update_last_seen_debounced() read the row with
session.get() and then updated it in the same transaction. When two requests
with the same Client API Token ran concurrently and both passed the debounce
check, the second UPDATE hit MariaDB error 1020 (Record has changed since last
read), so a read-only GET returned HTTP 500. Make each a single conditional
UPDATE that only touches the row when the debounce window has passed.
Fixes#5379
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* test(db): code-review fixes for last-used race tests
Reuse the executed_statements fixture, scope race listeners to
sync_engine, add the device race test, drop an unused fixture, and
apply trunk fmt.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(db): simplify pass on last-used race fix
Share the race hook as tests/db_race_stubs.run_before_first, look tokens
up by id in tests, trim duplicated docstrings, and state the handler
comment as current behaviour.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(db): humanizer pass on last-used handler comments
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(db): run MariaDB and MySQL sessions at READ COMMITTED
MariaDB 11.6+ turns on innodb_snapshot_isolation, so at REPEATABLE READ any
transaction that reads a row and then writes it fails with error 1020
("Record has changed since last read") when another transaction committed
to that row in between. READ COMMITTED, PostgreSQL's default, takes a fresh
snapshot per statement and removes the whole class of failures.
A server logging binlog_format=STATEMENT refuses InnoDB writes below
REPEATABLE READ, so its sessions keep the default and log a warning once.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* perf(auth): skip last-used and last-active writes inside the debounce window
Client-token auth bumped the token, the device and the user on every
request, the user with an undebounced UPDATE plus a re-SELECT. The token's
loaded last_used_at now gates the token and device bumps, and
set_last_active checks the loaded last_active and bumps through a
debounced conditional UPDATE, so a request inside the window writes
nothing and takes no row lock.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
* fix(platforms): count only the roms the caller can see in rom_count and fs_size_bytes
Platform.rom_count and fs_size_bytes are column properties over every rom
row on the platform, and the platform endpoints only filter hidden
platforms. So the platform header's "In library" count and "On disk" size
included roms hidden from the caller (directly, or by an age limit), while
the gallery left them out. Server Stats was off the same way: its
per-platform metadata coverage divides /api/stats' visibility-filtered
match counts by the unfiltered rom_count, so a restricted user saw
coverage too low and platform counts and sizes too high.
For a restricted caller, the list, detail and update endpoints now subtract
the totals of the roms RomVisibilityFilter hides
(DBStatsHandler.get_hidden_rom_totals_by_platform, next to the other
per-platform aggregates). Direct hides are matched by primary key, so a
few hidden roms cost a few lookups rather than a pass over every rom on
the platform. Admins and other unrestricted callers keep the model's
values and skip the query.
On a generated library of 50 platforms and 100k roms (MariaDB), the
platform list takes ~44 ms; this adds ~4 ms with 100 roms hidden, ~44 ms
with 5,000, and ~60 ms with an age limit (min_age isn't indexed, so that
case scans the platforms' roms).
Fixes#5312
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(platforms): read the hidden roms' totals in the platform query
Addresses Greptile's review of #5313:
- Counts can become negative: the hidden totals came from a second query,
so a rom added between the two could be subtracted without having been
counted. They now come from a grouped subquery outer-joined into the
statement that computes the full totals, so both read one snapshot (on
PostgreSQL's READ COMMITTED too, which a shared transaction wouldn't
give).
- Counting rules live in endpoints: the endpoint helper is gone.
get_platform and get_platforms take the caller's RomVisibilityFilter
(unrestricted by default) and return platforms with the visible totals;
DBStatsHandler.get_hidden_rom_totals_by_platform is removed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(platforms): code-review fixes for visible platform totals
- Re-read rows with populate_existing so a shared session never subtracts twice
- Narrow the hidden-totals subquery to the one platform get_platform reads
- Re-read after update only for restricted callers, and 404 instead of leaking full totals
- Test the update endpoint's restricted totals and the shared-session read
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(platforms): simplify pass on visible platform totals
Gate the row clause in one condition with a why comment, fold the MariaDB
narrowing reason into the docstring, and drop restating comments.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(platforms): count only visible roms in /supported and RetroArch listings
- Move the hidden-ROM predicate into RomVisibilityFilter.hidden_on_visible_platforms_clause,
with the age rule spelled as ranges an index on min_age can serve
- get_platforms reads hidden platforms from the visibility filter instead of a
second hidden_platform_ids argument
- /api/platforms/supported lists a hidden platform as unmatched and counts only
the caller's ROMs on the rest
- RetroArch WebDAV skips a platform whose ROMs are all hidden from the caller
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* perf(roms): index platform_id, min_age, fs_size_bytes for age-limited totals
On a 73k-ROM copy of a real library (MariaDB 13), GET /api/platforms for an
age-limited user went from 208 ms to 55 ms: the hidden-totals aggregate is now
an index-only scan instead of a full scan of the wide roms rows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Georges-Antoine Assi <contact@me.gantoine.com>
When SMTP is off or sending fails, the reset link is logged so an admin
can read it from stdout and pass it on. LogStreamHandler copied that
record into the Redis buffer behind GET /api/logs and the log socket,
which any logs.read holder can see, and logs.read is not admin-only.
Records logged with extra=STDOUT_ONLY now skip LogStreamHandler, and the
reset link uses it. The invite flow already logs only the token id.
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(oidc): match any of the comma-separated groups in OIDC_ROLE_*
OIDC_ROLE_ADMIN/EDITOR/VIEWER were read as one raw string and checked
for membership in the roles claim, so a value like
"romm-admin,platform-admins" never matched and the login was rejected
with 403. Parse each variable into a set of stripped, non-empty values
and grant the role when it intersects the claim. A single-valued string
claim is matched whole rather than by substring.
Fixes#4302
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* test(oidc): reject a string role claim that only contains a mapped group
Addresses Greptile's review on #5203: the string-claim case only covered a
match, which the old substring check would also have passed.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(sync): keep RetroArch Cloud Sync from stalling the event loop
Basic auth ran its bcrypt check (~250ms) on the event loop for every
WebDAV request, and the manifest ran its queries there too, so parallel
RetroArch requests queued behind each other. Both now run in a thread.
Cloud Sync resolves every save and state to a ROM by fs_name_no_ext,
which no index led with; 0149 adds one so unmatched uploads fail fast.
The upload dialog now offers a core for saves as well as states, so a
manually uploaded save lands in the core folder RetroArch reads, and its
slot hint says only unslotted saves reach RetroArch.
Refs #5158
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* test(sync): cover manifest queries running off the event loop
Addresses Greptile review on #5171: trim the 0149 migration docstring to
its summary, annotate the new MockConnection constructor, and add
regression tests that build_manifest and list_manifest_paths query from a
worker thread.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(auth): mark Basic-auth users active off the event loop
pr-ready step 2 (code-review): run the user lookup, password check and
set_last_active in one worker-thread hop, and test that SaveDataTab offers
save cores and forwards the picked core on upload.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* test(v2): build SaveDataTab test saves and states from shared fixtures
pr-ready step 3 (simplify): replace the hand-cast UserSaveSchema and
UserStateSchema stubs with saveFixture/stateFixture plus toUserSave/toUserState.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* chore(sync): drop restating index comment and type the test spy
pr-ready step 4 (review-polish): remove the comment that only restated
idx_roms_fs_name_no_ext, and type the manifest test's get_saves spy so mypy
passes across the backend.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(auth): check the password grant's credentials off the event loop
The OAuth password grant ran bcrypt (~250ms) on the event loop, stalling
every other request the worker was serving.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(sync): run RetroArch WebDAV database work off the event loop
GET, PUT, DELETE and PROPFIND resolved ROMs, looked up and wrote save,
state and screenshot rows, and listed whole platforms synchronously inside
async handlers; the PSP bundle helpers did the same. Each now runs that
work in a worker thread.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(saves): keep another core's same-named save on upload
A slot-less upload matched an existing save by file name alone, so
uploading game.srm for a second core rewrote the first core's row to the
new folder and deleted its file. The lookup now only matches a save made
with the requested core. Clients that send no core still match any, so
device conflict detection is unchanged, preferring a save filed under no
core.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* feat(v2): file a save picked with a core out of the slots
RetroArch Cloud Sync only lists unslotted saves, so picking a core in the
upload dialog moves an untouched slot from autosave to "No slot", and
clearing the core moves it back. A slot the user picked is kept.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* revert(i18n): restore the original upload slot hint
Picking a core now files a save out of the slots, so the hint no longer
needs to explain RetroArch Cloud Sync.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Replace the hidden_platform_ids/hidden_rom_ids parameter pairs with one
RomVisibilityFilter that builds the WHERE clauses and checks loaded ROMs,
so a new visibility rule (the age-rating cap for #2013) lands in one place.
No behaviour change; the visibility-filtered queries send the same SQL.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Wc3NzFkv97CXavLyZg5kJE
Importing any handler.auth submodule ran the package __init__, which
built the auth handlers and so loaded authlib, joserfc and Socket.IO.
models.user imports handler.auth.constants, so every process that
touched the models paid for the whole auth stack. The handler
instances now live next to their classes in handler.auth.base_handler.
utils.context imported fastapi only for annotations; that import now
sits under TYPE_CHECKING.
An idle RQ worker drops from about 118 MB to 89 MB RSS. Each job's
forked work horse now imports a little more on its own, about 0.2s
on an x86 host.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gh1SRMfuK7BZmf6YxMqSyT
* test(backend): build test ROMs through one make_rom factory
Tests created Rom rows by hand in dozens of places, each spelling out the
same slug and filename fields and deriving the slug inline. Production never
computes a slug from a name, so this was test-only filler duplicated across
files.
tests/factories.py adds make_rom(platform, name, *, fs_stem, fs_extension,
**overrides), which fills the slug and filename columns and persists through
db_rom_handler.add_rom. The shared conftest fixtures, scan_stubs.add_rom and
the local helpers and inline constructors across 35 test files now use it.
Each test keeps its filename shape (underscored stems in the FULLTEXT search
tests, spaced "Name (USA)" stems in the sibling tests), and fixtures shared
across files keep their exact slugs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(backend): keep extensionless filenames intact in scan_stubs.add_rom
rpartition(".") on a name with no dot returned an empty stem and the whole
name as the extension, so make_rom stored ".README" for "README".
os.path.splitext leaves such names whole.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(backend): build test saves, states and screenshots through factories
Tests built Save, State and Screenshot rows by hand across about 20 files,
each spelling out file_name_no_tags, file_name_no_ext and file_extension
although BaseAsset already derives them from file_name.
tests/factories.py adds make_save, make_state and make_screenshot. Each sets
the rom and user ids, the file name, and a default file_path under the rom's
platform, applies overrides last, and persists through the matching db
handler. The conftest asset fixtures and the persisted constructors and local
helpers now use them. Rows a test observes keep their file_path, emulator,
slot, size and hash, and a filename part stays an override wherever it
differs from what the model derives.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(backend): ban direct add_* persistence in tests via ruff TID251
The factories only stay the one home for test rows if nothing routes
around them. Ruff's banned-api rule now flags db_rom_handler.add_rom,
db_save_handler.add_save, db_state_handler.add_state and
db_screenshot_handler.add_screenshot anywhere under tests/ except
tests/factories.py. Production code is unaffected.
The remaining add_rom calls move onto make_rom: the unique-path, soundtrack
and id-index tests in test_roms_handler.py, the scan tests in
test_fastapi.py, physical and missing rows in the feed, download and model
tests, and the name=None exporter rows. Scan tests keep a filename-derived
placeholder as the name, which scan_rom treats the same as no name. Three
calls keep a noqa: the tests of how add_rom merges a partial scanned row,
and the rescan test that persists scan_rom's output as a scan does.
The backend skill and the architecture doc now point at tests/factories.py.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(backend): move the firmware and client-token factories into tests/factories.py
The add_firmware and add_device_token conftest fixtures returned a builder,
unlike the importable make_* functions. They become make_firmware and
make_device_token alongside them, with the same defaults, and their callers
import them rather than requesting a fixture. make_device_token now draws the
raw credential from auth_handler.generate_client_token, so it carries the
real rmm_ prefix instead of restating it, and the hand-built client tokens in
the auth tests use it too.
The ruff TID251 ban now also covers db_firmware_handler.add_firmware and
db_client_token_handler.add_token under tests/.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs: point at every test factory, not just the ROM and asset ones
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- Match on (issuer, sub) with exact collation, so subjects from another
provider or differing only in case never match.
- Refuse a login whose email is linked to another subject at the same
issuer instead of rebinding the account; relink only across issuers.
- Check the account is enabled before saving identity changes.
- Keep the old email when it is claimed between the check and the write.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Store the provider's `sub` on a new nullable users.oidc_sub column, look users
up by it first and fall back to email, backfilling the sub on the next login. A
user matched by sub gets their stored email updated, unless another account
already holds it.
Fixes#1690
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Keep email_verified tied to the email it came with, and fall back to the
ID token claims when provider discovery fails as well.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Providers like Authelia follow OIDC Core 5.4 and return scope claims
(email, preferred_username, groups) only from the UserInfo endpoint.
When any claim RomM reads is absent from the ID token, fetch UserInfo
with the access token, check that its sub matches, and merge it under
the ID token claims.
Fixes#1927
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* perf(backend): pipeline multi-command Redis writes
- upload_chunk records a chunk with SADD, EXPIRE and SCARD in one
transaction instead of three round trips, so a failure between them
can no longer leave the chunk set without a TTL.
- bind_to_login_session does its SADD and EXPIRE in one transaction for
the same reason.
- close_login_sessions reads and deletes a session's socket set in one
transaction, so a socket binding in between is not dropped unseen.
- Logout deletes the session and removes it from the user's set in one
pipeline.
- complete_chunked_upload reads the chunk set once instead of SCARD then
SMEMBERS; cancel and invalidate_filter_values_cache delete their keys
in one call.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2WxB8t3Shv4TZmHFdSMHv
* fix(backend): refuse a socket bind that lands after its session's revocation
- bind_to_login_session checks the login session still exists in the
same transaction as its SADD. Revocation deletes the session before it
reads the socket set, so a bind that finds it gone removes itself and
authenticate treats the socket as anonymous.
- complete_chunked_upload keeps its SCARD fast path and reads the
members only to name the missing chunks.
- cancel_chunked_upload removes the temporary files before touching
Redis.
- Tests check each pipelined write executes as one MULTI/EXEC.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2WxB8t3Shv4TZmHFdSMHv
* fix(backend): close an upload session before removing its files on cancel
A chunk PUT that passes the session check after the temporary directory
is gone fails with a 500; deleting the session first turns it into a 404.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2WxB8t3Shv4TZmHFdSMHv
* fix(backend): answer a chunk write cut short by a cancel with 404
A PUT that passed the session check before the cancel removed its
directory fails writing; it now re-reads the session and returns the
same 404 as a PUT that arrives after the cancel, instead of a 500.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2WxB8t3Shv4TZmHFdSMHv
* chore(backend): remove a stray Redis snapshot
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T2WxB8t3Shv4TZmHFdSMHv
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* chore(mypy): switch to strict mode with listed exceptions
Replace the hand-picked flags with `strict = True`, turning off only the
four flags that aren't clean yet (disallow_any_generics,
warn_return_any, disallow_untyped_calls, disallow_untyped_decorators).
Any other strict flag, including those future mypy releases add to the
preset, is on by default.
That turns on no_implicit_reexport, strict_equality and extra_checks:
- Import each name from the module that defines it. About 240 test
sites patched a dependency through the module that imported it
(`scan_module.fs_rom_handler`); they now import the same object from
its source, so every patch targets what it did before. Tests that
replace a module attribute are unchanged.
- handler.streaming.memory_cards re-exports store_memory_card_version
explicitly, since endpoints call it there and tests patch it there.
- mutagen gets implicit_reexport, as it re-exports without __all__.
- Test comparisons build typed values (CoverResult, a typed expected
dict, enum .value) and the CORS lookup casts for its identity check.
- One ss_handler ** spread keeps a coded ignore: extra_checks wants its
NotRequired dump_* keys spelled out, and the media dict never has them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
* chore(mypy): give every generic its type arguments
Drop disallow_any_generics from the strict-mode exceptions and fix the
347 bare generics it reports, 230 of them in app code.
- Bare `dict` becomes `dict[str, Any]`: update payloads, raw provider
JSON and endpoint bodies map string keys to mixed values, so the Any is
real and now written down. The OpenAPI document is unchanged.
- Rom query filters take and return RomSelect; _music_facet_joins and
_exclude_hidden are generic over the Select they're given, and
_build_hash_selects returns id-only selects.
- Redis clients are typed by what they return: the decoding caches are
Redis[str], the RQ connection and binary cache Redis[bytes].
- The rest get explicit parameters: Row, Pattern, ColumnElement,
QueryableAttribute, SpooledTemporaryFile, Task, Future and friends.
Precise types reached callers that had been getting Any, which surfaced:
- The LaunchBox cache writer is fed binary-cache pipelines.
- The flashpoint and IGDB request helpers return raw JSON of varying
shape, not always a dict.
- The rom search endpoint returned dicts under a list[SearchRomSchema]
annotation; it now validates them into that schema.
- The audit filter's id subquery selects strings.
- In tests the binary cache is the non-decoding fake shared with
async_cache, so it is cast to Redis[bytes] rather than changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
* test(upload): assert cleanup against the patched upload directory
The 409 test checked config's ROM_UPLOAD_TMP_BASE while the fixture patches
the endpoint's copy to tmp_path/uploads, so it passed even if cleanup failed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
* chore(mypy): keep the row type through the ROM filter helpers
filter_roms and its helpers also receive select(Rom.id) membership queries,
so they now take and return the caller's Select type instead of narrowing to
RomSelect. merged_ra_metadata mixes scalar and list values.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PLzXae5up2pYXRoBjfjn2G
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
is_system was true exactly when system_key is set, so 0137 now drops it
after backfilling the key, and downgrade rebuilds it from the key. The
group API returns system_key instead, and the admin UI reads it for the
system tag and edit warning.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
HybridAuthBackend runs inside Starlette's AuthenticationMiddleware, so an
HTTPException raised while validating a JWT bearer token (expired, bad
signature, garbage) or parsing a malformed Basic header bypassed FastAPI's
exception handlers and surfaced as a 500 on every endpoint, including
/api/heartbeat. Return None instead, matching the rmm_ client token path:
public endpoints respond normally and protected ones return 401.
Fixes#4788
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Tests, fixtures and the e2e seed found the seeded groups by display name,
which an admin can edit and this PR just changed. A unique system_key
column (viewer/editor), added and backfilled by 0137, identifies them
instead, and get_system_group() replaces the name lookups.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Master already chains 0135 and 0136 onto 0134, so the rename becomes
0137 revising 0136_deleted_assets to keep a single alembic head. Also
dedupe the migration filename in tests, rename tests that still said
legacy, and drop em-dashes and a long docstring.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Bind netplay sockets to their login session, keying the socket set per
channel so revoking a session closes sockets on both servers.
- Read the room password from the top-level field EmulatorJS sends, and
compare it in constant time.
- Namespace Socket.IO room names so a room id cannot collide with a sid.
- Refuse a duplicate player id on join, and leave the current room before
opening or joining another.
- Coerce client-supplied maxPlayers and names, and store the resolved ROM id.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Every install showed "Viewer (legacy)" and "Editor (legacy)" as the built-in
groups, which reads as deprecated. 0092 already shipped in 5.3.0, so a new
revision renames the untouched system rows and drops the "pre-upgrade"
framing from their descriptions. It skips a group whose target name an admin
already took, and keeps a description the admin edited.
Fixes#4678
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xdb9FnfhEqP6ectkSZ2T3F
The previous commit carried only the renames of this change, when staging
the rest failed on a path the rename had already moved. This is the change
itself.
A reset link only ever went to the server log, for an admin to pass on. It
now goes to the user's email address when SMTP is set up, the user has one
and ROMM_BASE_URL is shareable, falling back to the log otherwise or when the
server refuses the message. The link is built from ROMM_BASE_URL alone, never
the request's Host, so a forged header can't aim it at another server; it
goes out after the response, so its timing doesn't reveal whether the
username exists; and a user's inbox gets at most one a minute.
The SMTP sender moves from the notification channels to
handler/email_handler.py now that it has a second caller. The v2 reset form
says the link is on its way when the server sends email.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
OIDC-provisioned accounts hold a placeholder rather than a bcrypt hash.
passlib raises on one it cannot identify, so a login against such an
account turned a 401 into a 500 that marked it as OIDC-backed.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Revoking only before the write left a wider hole than the one it closed: the
old password stays good until the write commits, so a login starting in that
window authenticates and writes a session unconditionally, having no existing
id for the `XX` guard to refuse. Revoking only after the write cannot abort a
change Redis was unreachable for. Doing both keeps each property.
What remains is a login that read the old hash before the first pass and
writes after the second, which needs the per-user revocation generation rather
than an ordering change.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NouZquWDxNBqxYyu2E2GF8
`update_user` cleared only the caller's session, so an admin resetting a
compromised account left every attacker session on it live. It now revokes the
sessions of the account the change was applied to, keyed on the username the
account held before the update, and still clears the caller's own session when
they are that account. `set_user_new_password` already did this; the update
endpoint was the gap.
A revocation could also be undone by any request already in flight: the session
middleware rewrote its copy unconditionally on the way out. An existing session
now refreshes with `SET ... XX`, so a record deleted mid-request is not
recreated, and the response clears the cookie instead.
`clear_user_sessions` also builds its delete keys from decoded members. The
configured clients pass `decode_responses=True`, so this changes nothing in
production, but the key is now right for any client, and the whole set goes in
one `delete` rather than a call per session.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NouZquWDxNBqxYyu2E2GF8
Registering `a-user-2` when `a-user` exists silently hands the provider's
user a name they did not choose. Fail the login with a 409 instead.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A provider name already at the column's length left no room to append
`-2` to, and the log said the name was invalid even when all that happened
was a collision. Both now come from the one helper that knows which it was.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`preferred_username` was stored verbatim, so a provider that issues
`first.last` created an account whose username RomM's own rules reject.
The account works for login but cannot be edited afterwards: every write
through the users endpoints re-runs `validate_username` on it.
Coerce the name to the allowed charset at registration, falling back to
the email local part when nothing usable survives, and suffix it until it
is free since the column is unique.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Logging in failed once with a CSRF error and succeeded on retry.
`_csrf_tokens_match` validates the user id embedded in the token against
the current request's user. A browser holding a token bound to user N,
whose server-side session is gone (container restart, session expiry,
Redis flush), makes an anonymous login POST. N != None, so the request is
rejected. The rejection response then rotates the cookie, which is why the
second attempt works.
Keep the double-submit check and the cookie/header user agreement
unconditionally, and enforce the caller binding only when there is a
caller. An anonymous request cannot be forged this way regardless: an
attacker cannot read the cookie cross-origin, so it cannot produce the
matching header.
This is the mirror of #3420, which fixed the authenticated direction by
rotating the cookie on safe requests. That path is untouched here, and
test_authenticated_user_binding_still_enforced pins it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
KIOSK_MODE stripped every non-READ grant from all non-admins after group
and override resolution, so a logged-in user with "Saves & States: Write"
still got a 403 from POST /api/states|saves|screenshots. The permission
UI saved grants the server then silently discarded.
The cap now applies only to the synthetic guest KIOSK_MODE hands out
(User.is_kiosk_guest). It has to stay for the guest: with no permission
group of its own it falls back to the server default group ("Viewer
(legacy)" = WRITE_SCOPES), so dropping the cap outright would let
anonymous visitors upload assets and edit collections.
Fixes#4044
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Collapse the Role enum from viewer/editor/admin to two kinds (admin/user);
non-admin access now comes entirely from permission groups + overrides.
Backend:
- Role -> StrEnum {USER, ADMIN}, VARCHAR-backed (native_enum=False); Role.coerce
maps legacy/unknown strings (incl. in-flight invites) to USER.
- Resolver: group-less users fall back to the default group (dropped the
role-based legacy fallback); kiosk caps all non-admins to read-only.
- OIDC editor/viewer claims both map to USER (env var names unchanged).
- Migration 0092 converts the native enum to VARCHAR and normalizes
ADMIN->admin, VIEWER/EDITOR->user.
- Updated endpoints, conftest fixtures, role/oidc/parity/db-handler tests, tools.
Frontend:
- v2 + v1 user management now use admin/user (dropdowns, defaults, getRoleIcon).
- Regenerated types (Role = 'user' | 'admin'); added role-user i18n to all locales.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Added new permission handling in `backend/handler/auth/dependencies.py` to support fine-grained, DB-backed permission checks.
- Enhanced user role update logic in `backend/endpoints/user.py` to prevent demotion of the last admin.
- Introduced `hidden_platform_ids` and `hidden_rom_ids` parameters in various database handlers to manage visibility based on admin settings.
- Created new endpoints for managing permission groups, user memberships, and hidden entities in `backend/tests/endpoints/test_permissions_admin.py`.
- Added tests for permissions visibility and CRUD operations in `backend/tests/endpoints/test_permissions_visibility.py` and `backend/tests/endpoints/test_permissions_me.py`.
- Updated archive handling in `backend/utils/archives.py` to improve error logging and timeout management during extraction.