Commit Graph
15357 Commits
Author SHA1 Message Date
Dylan M. Taylor c1325af209 ci: verify the actions lockfile in CI
Fails the build when .github/workflows/actions.lock stops matching the
workflows, or when a locked pin no longer verifies upstream, so a stale or
tampered lockfile cannot go unnoticed between dependency updates.
2026-11-12 07:22:41 -05:00
Dylan M. Taylor e938767d26 ci: lock workflow actions through an actions.lock lockfile
Mutable action tags are a supply-chain risk: a moved tag runs different code
without a diff. Every workflow action is now pinned through
.github/workflows/actions.lock, and CI verifies the lockfile so an out-of-sync
or tampered one fails instead of running.
2026-11-12 07:19:43 -05:00
github-actions[bot]anddylanmtaylor 4c72ed5437 chore: update Craft Launcher and app release versions (#391)
## Summary

Automatically synchronize the Craft Launcher and Crafting Apps
versions with the latest stable published releases in their
respective GitHub repositories.

## Changes

- Update versions from published stable releases only.
- Ignore prereleases, drafts, and tags outside vX.Y.Z.
- Validate all required release assets before updating the catalog.
- Preserve catalog entries explicitly set to null.
- Support pinned versions for intentional rollbacks.
- Keep the existing release asset configuration unchanged.

Generated by the `Update Craft Release Versions` workflow.

Co-authored-by: dylanmtaylor <277927+dylanmtaylor@users.noreply.github.com>
2026-11-12 05:13:17 +00:00
github-actions[bot]anddylanmtaylor 294a566c93 chore: update Craft Launcher and app release versions (#390)
## Summary

Automatically synchronize the Craft Launcher and Crafting Apps
versions with the latest stable published releases in their
respective GitHub repositories.

## Changes

- Update versions from published stable releases only.
- Ignore prereleases, drafts, and tags outside vX.Y.Z.
- Validate all required release assets before updating the catalog.
- Preserve catalog entries explicitly set to null.
- Support pinned versions for intentional rollbacks.
- Keep the existing release asset configuration unchanged.

Generated by the `Update Craft Release Versions` workflow.

Co-authored-by: dylanmtaylor <277927+dylanmtaylor@users.noreply.github.com>
2026-11-12 03:15:13 +00:00
Mateusz Paluszkiewicz b08ef44a86 ci: don't fail release sync when the Studio version is already current (#387)
## Summary

The hourly `Update Craft Release Versions` workflow has failed every run
since 2026-11-07 with:

```
Error: Could not find ARTCRAFT_STUDIO_VERSION in github_download_links.ts.
```

The declaration exists. The workflow decided it was missing by comparing
`github_download_links.ts` before and after the replace. #352 set
`ARTCRAFT_STUDIO_VERSION = "0.41.1"` by hand, and 0.41.1 is the latest
Studio release, so the replace is a no-op and the check throws.

The run stops before updating the launcher or any Crafting App. That
freezes `crafting-app-releases.ts` and everything built from it,
including the Flatpak OCI index at `/index/static`. Right now the index
still serves Craft Launcher 0.15.0, but 0.19.0 is published to GHCR as
`stable-x86_64`.

Related: #361 (that issue's original missing-assets error was fixed by
#371, which exposed this one).

## Change

Test for the declaration with the pattern, as the launcher and app
updates already do, then replace.

## Verification

I ran the workflow's `github-script` body locally against live release
data from `gh api`:

- Before the change: fails with the error above.
- After the change: completes and bumps the launcher to 0.19.0 and every
Crafting App to its latest release.
- With the `ARTCRAFT_STUDIO_VERSION` line removed: still fails with
"Could not find ARTCRAFT_STUDIO_VERSION".


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Fixed release version updates so an already-current version is
recognized correctly. The update process now reports an error only when
the version declaration is actually missing, preventing a false failure
when no change is needed.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-12 03:38:57 +01:00
Dylan M. Taylor e585d12bfd ci: use StepSecurity's maintained actions (#382)
Each third-party action that StepSecurity publishes a secure drop-in
replacement for now uses that replacement, pinned to a commit with its
version as a comment. Versions follow what we used: the newest
StepSecurity release in the same major, or the closest major they
publish. dtolnay/rust-toolchain refs that named a toolchain (stable,
nightly, 1.76) become the replacement's `toolchain` input.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Chores**
* Updated the automation integrations used for pull request creation and
container registry sign-in.
* Existing workflow settings and registry credentials remain unchanged.
Some container build workflow steps remain inactive.
* These maintenance updates do not change the app’s features or
behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 14:57:19 -05:00
Dylan M. Taylor 4c9f1b98f5 fix: refuse to show desktop-login approval inside a frame (#266)
## What was wrong

The desktop-login consent page (`/login/desktop`,
`DesktopLoginApproval`) could be rendered inside a cross-origin frame.
The webapp's `netlify.toml` sends no `frame-ancestors` or
`X-Frame-Options` for it, and the component did not check for framing.
An attacker can start a login challenge for their own desktop, embed the
verification URL in a page they control, hide the frame under decoy
content, and steer the signed-in victim's click onto "Approve desktop
login". The backend then issues the victim's session to the attacker's
device-token holder (clickjacking, CWE-1021).

## What changed

- `apps/artcraft-webapp/netlify.toml`: `/login/desktop` and
`/login/desktop/*` are served with `Content-Security-Policy:
frame-ancestors 'none'` and `X-Frame-Options: DENY`. This is scoped to
the approval route so other webapp pages are unaffected.
- `libs/login/.../desktop-login-approval.tsx`: if `window.self !==
window.top` (or that check throws), the component renders "Open this
login link directly in your browser to approve it." It does not fetch
the review and `decide` is a no-op. This covers deployments that do not
send the headers.
- New webapp test: a framed render shows no Approve button and makes no
API call.

## Blast radius

Only the desktop-login approval route. Opening the link top-level
(browser, QR code) behaves as before. Any legitimate flow that frames
`/login/desktop` would stop working; none exists in this repo.

## Checks run

- `NODE_OPTIONS=--no-experimental-webstorage npx vitest run --root
apps/artcraft-webapp src/pages/login`: 20/20 pass, including the new
framed case. Under Node 26 the flag is needed, or jsdom's
`sessionStorage` is shadowed and every test in this file fails, before
and after this change.
- `npx vitest run --root libs/login`: pass.
- `netlify.toml` parses as TOML.

## Checks not run

- `tsc -p libs/login/tsconfig.lib.json`: only the pre-existing TS6305
errors for the unbuilt `@storyteller/api` `dist`.
- Netlify deploy preview header verification.

Addresses CodeRabbit security findings (CWE-1021).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Desktop login approval pages displayed inside a frame now instruct
visitors to open the link directly in a browser. The page does not load
or submit a login challenge, or offer approval or decline actions.
* Browser security headers prevent desktop login pages from being
displayed within frames, including when framed pages involve
cross-origin access.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 12:11:01 -05:00
Dylan M. Taylor 9101e4e9d7 fix(webapp): restrict onboarding redirect_to to same-origin paths (#289)
## What was wrong
`onboarding.tsx` decoded the `redirect_to` query parameter and passed it
straight to `navigate()`. A protocol-relative value such as
`//evil.example` (or its encoded form) made the router fall back to a
full browser navigation, so an onboarding link could send a freshly
signed-up user to an external site (open redirect, CWE-601).

## What changed
- `redirect_to` is decoded once (a malformed encoding is kept as-is
instead of throwing) and validated with the existing
`safeAuthReturnPath` from `lib/login-bridge-context`; anything that is
not a same-origin path becomes `/`.
- Both navigation paths and the status text use that validated value.

## Blast radius
Onboarding page only. Real values (`/checkout/success`,
`/checkout/cancel`, `/pricing`, `/`) pass through unchanged.

## Checks run
- `tsc -p apps/artcraft-webapp/tsconfig.app.json`: no new errors
compared with `main`.

## Checks not run
- No new test: the change only calls the existing `safeAuthReturnPath`,
which already has coverage in `desktop-login.spec.tsx`.
- Manual walk through the onboarding flow.
2026-11-11 12:10:54 -05:00
Dylan M. Taylor f13f35644d ci: run Harden-Runner on every job (#381)
Adds step-security/harden-runner (audit, pinned to v2.22.4 like
craft-common-actions) as the first step of each job that did not have
it,
so every workflow in the org's public repos reports its egress to
StepSecurity. Audit, not block: block-mode allow lists come from each
job's observed traffic.
2026-11-11 12:09:05 -05:00
Dylan M. Taylor 3d75db28e3 fix: parse Forwarded for= nodes and match disabled endpoints on the routed path (#322)
What was wrong: (1) the Forwarded fallback returned the whole first list
element (e.g. `for=1.2.3.4;proto=http`), so exact IP bans never matched.
(2) The disabled-endpoint filter compared the raw URI path while actix
routes on the percent-decoded path, so an equivalent encoded spelling
bypassed it.

Change: Forwarded values are parsed per RFC 7239 (first for= node,
quotes/brackets/port stripped); X-Forwarded-For is unchanged. The filter
now checks request.match_info().as_str(), the path actix routes with.

Blast radius: crates/lib/actix_helpers (ban filter and disabled-endpoint
middleware).

Behavior changes: requests using a Forwarded header now yield a bare IP;
encoded spellings of a disabled path are now blocked.

Checks run: cargo test -p actix_helpers (new Forwarded test).
Checks not run: clippy -D warnings (91 pre-existing errors in this crate
on main); no integration test of the middleware against an encoded URI.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Forwarded IP addresses are now read from the first `for` parameter,
including quoted values and IPv6 addresses. Other supported IP headers
retain their existing parsing behavior.
* Disabled-endpoint checks now use the matched route rather than the raw
request path, improving checks for requests handled through routed
endpoints.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 12:03:28 -05:00
Dylan M. Taylor 094a662fba fix: hide job result locations the caller may not read (#277)
## What was wrong

`GET /v1/jobs/job/{token}` is public and joined the job's result media
by token alone. A known job token kept disclosing the result's media
token, bucket path and CDN links after the creator made the result
private or it was soft-deleted.

## What changed

For `media_file` results the handler now resolves the session and
re-reads the media through `get_media_file` (moderators see deleted
rows, others do not). `maybe_result_details` is dropped from the
response unless the media is readable by the caller: not private, or the
caller is the creator (user token or anonymous visitor token), or a
moderator. Status, progress and failure fields are unchanged, so polling
keeps working for everyone.

## Blast radius

One handler; one extra media lookup per status poll of a completed
media-file job. Legacy TTS / voice-conversion result types are not
affected.

## Checks

- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web` (exit 0).
- Not run: the job status tests need a live MySQL.
2026-11-11 12:03:09 -05:00
Dylan M. Taylor ffc4c469ad fix: require read access to the source image before background removal (#276)
## What was wrong

`POST /v1/generate/image/remove_background` looked up the
caller-supplied `media_file_token` and submitted its CDN URL to Fal
without checking the media's visibility. Anyone who knew another user's
**private** image token could run background removal on it and collect
the derivative through the job the handler created for them.

## What changed

After the media lookup, the handler now requires that the source is
readable by the requester: not `Private`, or the requester is its
creator (session user token, or the anonymous visitor token for
anonymous uploads), or a moderator
(`can_delete_other_users_tts_results`, the convention the media read
handlers use). Otherwise it returns `NotFound`, so a private token's
existence is not confirmed.

## Blast radius

One handler. Public and hidden sources behave as before; only private
sources belonging to someone else are now rejected.

## Checks

- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web` (exit 0).
- Not run: the handler tests need a live MySQL.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Background removal requests now check access to the source image
before processing. Non-private images remain accessible. Private images
are available to moderators and their creator, or to a visitor
presenting the matching anonymous visitor credential when no creator
credential is present. Requests without the required access receive a
not-found response.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 12:02:52 -05:00
Dylan M. Taylor b72e0e26cb fix: check cover image access when setting and serving covers (#267)
## What was wrong

`POST /v1/media_files/cover_image/{token}` (and the model weight
equivalent) accepted any image token as a cover after checking only that
it was an image. Listings then joined the cover by token alone and
returned its bucket path and CDN links. A user could attach another
user's **private** image as the cover of their own media and read its
storage location from any listing of that media. Covers that were later
deleted or made private also kept being served.

## What changed

- New helper `media_files/helpers/may_use_as_cover_image.rs`: a private
image may be used as a cover only by the user who created it. Public and
hidden images behave as before. Both cover setters
(`set_media_file_cover_image_handler`,
`set_model_weight_cover_image_handler`) use it and answer `NotFound` on
refusal, the same as a missing token.
- Every media-file cover join in `mysql_queries` (get, batch get, list,
featured, for-user, session, project, batch-generated, source job, tags,
files-without-folder, Elasticsearch backfill) now joins the cover only
when it is live and either not private or owned by the same creator as
the media file it decorates. Existing bad associations stop leaking
without a data migration.
- `.sqlx` entries for the 16 changed `query!` macros were regenerated
against a local schema built from `_database/sql/migrations`. Column
metadata was kept from the existing MySQL entries; only the query text,
hash and parameters changed.

## Blast radius

- Public and hidden covers, and a creator's own private covers on their
own media, render as before.
- A cover that is deleted, or private and owned by someone other than
the media's creator, now comes back as no cover.
- Not changed: the `batch_get_media_files_by_tokens` and folder-listing
cover joins (those files are touched by #227/#229 and the folder PR, so
they are left to avoid conflicts), and the model-weight cover joins in
the weights list queries. The setters now block new associations there;
read-time checks for those queries are a follow-up.

## Checks run

- `SQLX_OFFLINE=true cargo test -p mysql_queries --lib --no-run`:
compiles against the updated `.sqlx` cache
- `SQLX_OFFLINE=true cargo test -p storyteller-web --features
skip_database_tests --bin storyteller-web -- may_use_as_cover_image`:
builds the full crate, 2 new tests pass
- Every changed query was described successfully by sqlx against a local
MariaDB 11.8 loaded with all migrations

## Checks not run

- `cargo sqlx prepare` against production-equivalent MySQL (sqlx-cli is
not installed and only MariaDB was available. Please re-run it if the
cache flags differ.)
- Endpoint integration tests against MySQL

Addresses CodeRabbit security findings (CWE-863).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
  * Deleted cover images are no longer displayed.
* Private images are used as covers only when they belong to the same
creator as the media file; public and hidden images remain eligible.
* Cover-image selection in media and model-weight workflows now respects
private-image access rules.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 12:02:34 -05:00
Dylan M. Taylor a083615cd3 fix: keep other users' private media out of folders (#254)
## What was wrong
Folder bulk-add and bulk-move only checked that each media token existed
and wasn't deleted. A user who knew another user's private media token
could put it in their own folder, and the folder list (`GET
/v1/folders/media_files/{folder}`) and folder thumbnails
(`last_media_thumbnails`) then returned that file's CDN URLs and
metadata.

## What changed
- `filter_existing_media_file_tokens` takes `viewer_user_token` and only
keeps private files created by that user. Bulk add and bulk move pass
the session user.
- `batch_get_media_file_thumbnails_by_tokens` takes an optional
`maybe_restrict_private_to_creator`. Folder thumbnails pass the session
user, so memberships that already exist (or files made private later)
stop showing. The Elasticsearch thumbnail-version lookup passes `None`;
it returns no URLs.
- `list_folder_media_files_handler` re-checks private rows on each page
and drops the ones the viewer didn't create. The pagination cursor is
still taken from the unfiltered page.

All new SQL uses `QueryBuilder` with bound parameters, so no `.sqlx`
metadata changes.

## Blast radius
Folders are owner-only. Behaviour changes: another user's private file
can no longer be added to a folder (it is silently skipped, as missing
tokens already are), and such files already in a folder no longer appear
in its listing or thumbnails. A page of the folder list can be shorter
than the limit when rows are hidden.

## Checks
- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web -p db-cleanup
--tests`.
- Not run: endpoint/query tests; they need a live MySQL.

Addresses CodeRabbit security findings (CWE-862).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Folder listings now hide private media files that the viewer cannot
access, while preserving access to their own private files and eligible
non-private files.
* Folder thumbnails no longer reveal private media belonging to another
user.
* Adding or moving media into folders silently skips private files the
viewer cannot access.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 12:02:16 -05:00
Dylan M. Taylor 75361b0560 fix: hide unreadable context media on prompt reads (#231)
> Stacked on **#228** → **#229** (merge in that order). This PR needs
`MediaReadScope` and `media_read_policy` from those branches; it rebases
onto `main` cleanly once they land.

## Summary

`GET /v1/prompts/{token}` lists the prompt's context items (reference
images, style images, uploads) and built a CDN link and media token for
each from `list_prompt_context_items`, which selects storage locations
only. The media's own visibility was never consulted, so reading a
prompt — including a prompt that was shared or public — exposed the
storage URLs and tokens of another user's **private** media.

The handler now resolves the context media through the shared read scope
and drops items the requester may not read. The prompt still renders its
readable context; private media referenced by it stays private and is no
longer linkable through the prompt.

## Notes

- Moderation goes through `can_ban_users`, matching the existing
moderator-fields logic in this handler.
- `maybe_user_session` is now borrowed rather than moved, since the
scope needs it after the moderator check.
- One extra media query per prompt read (only when the prompt has
context items).

## Checks

- `SQLX_OFFLINE=true cargo check -p storyteller-web` — finished clean,
exit 0.
- No tests run: the prompt endpoint tests need a live MySQL.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Prompt responses now include context media only when it is readable
under the current session’s media access policy. Failed media lookups no
longer prevent a response from being returned.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 12:01:57 -05:00
Dylan M. Taylor a6b5f738af fix: enforce private media visibility on token batch reads (#228)
## Summary

`GET /v1/media_files/batch` takes a list of media tokens and returned
every matching record — storage paths, titles, transcripts, original
filenames — to any caller. The session was read only to decide whether
deleted records were visible; it played no part in authorizing private
ones.

The handler now keeps only records the requester may read:

- private records are returned to their creator and to moderators,
- private records are **dropped** for everyone else, rather than the
request failing, so a batch of guessed tokens discloses neither content
nor which token matched.

The rule lives in a new shared helper,
`util/lookup/media_read_policy.rs::ensure_may_read_media`, returning
`NotFound` for a private record the caller may not read. It matches the
check in `get_weight_handler.rs` and is intended for the other media
read paths too, so the policy is not re-derived per endpoint.

## Blast radius

`batch_get_media_files` has exactly one caller (this handler), so the
endpoint is fully covered. Public and hidden media behave as before;
response order is preserved for the remaining records, and the `results`
array may be shorter than the requested token list.

## Checks

- `SQLX_OFFLINE=true cargo check -p storyteller-web` — finished clean.
- No tests run: the media endpoint tests need a live MySQL, which this
environment does not provide. Worth adding a case for anonymous callers
requesting another user's private token before merging.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Batch media requests now omit private media that the viewer is not
authorized to access. Private media remains available to its creator and
moderators, while other viewers receive no indication that the
restricted item exists.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 12:01:06 -05:00
Dylan M. Taylor ec461047a5 fix: enforce private media visibility for reads and batch lists (#226)
## Summary

Two endpoints returned private media records without comparing
`creator_set_visibility` against the requester, so knowing a token was
enough to read another user's private media, including its storage
locations and transcripts.

**Single-file lookup** (`media_files/get/get_media_file_handler.rs`)
- The handler now passes the viewer's `user_token` into both lookup
branches.
- A shared `ensure_may_read_media` helper returns `NotFound` for
`Visibility::Private` records unless the viewer is the creator or a
moderator. The same policy now applies to the legacy `TR:` TTS emulation
branch, which previously had no check at all.
- `NotFound` rather than `NotAuthorized` avoids confirming that a
private token exists. This mirrors the check in `get_weight_handler.rs`.

**Batch listing**
(`media_files/list/list_media_files_by_batch_token_handler.rs`)
- The endpoint hard-coded `ViewAs::Author` with a "this is wrong, but
gotta go fast" TODO, so any caller holding a batch token received every
record in the batch regardless of visibility.
- Scope now derives from the session: `Moderator` for moderators,
`Author` for other logged-in users, `AnotherUser` for anonymous callers.
- `maybe_creator_user_token` is selected with the page so private
records are dropped for anyone who is neither the creator nor a
moderator.

## Notes

- Public and hidden media behave as before; only private access changes.
- For non-moderators the batch page can be shorter than `page_size`, and
`total_page_count` still counts records the caller may not read, because
filtering happens after the query. Fixing that properly needs
visibility-aware SQL and is left for a follow-up.
- Verified with `SQLX_OFFLINE=true cargo check -p storyteller-web`
(finished clean). No tests were added or run: the media endpoints are
covered by integration tests that need a live MySQL, which is not
available here.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Private media files are visible only to their creator or a moderator.
Other viewers will not see private files in batch listings, and direct
requests return not found.
* Access rules apply consistently to standard media files and legacy
text-to-speech results.
* Viewer identity is recognized from an authenticated session or a
viewer token, allowing creators to access their private media without
signing in.
  * Public media remains accessible according to existing permissions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:59:51 -05:00
Dylan M. Taylor dc36ccb6ba fix: stop generation from reading other users' private media (#229)
> **Stacked on #228**, which adds `util/lookup/media_read_policy.rs`.
Merge that first; this PR then rebases onto `main` cleanly.

## Summary

Every generation endpoint takes media tokens from the request
(`start_frame_media_token`, `reference_image_media_tokens`, inpainting
sources, image-to-3D inputs, …) and resolved them through
`batch_get_media_files_by_tokens`, which only filtered on existence and
soft deletion. Possession of a token therefore authorised use of the
record: another user's private image could be submitted as a generation
input, and several paths (`lookup_image_urls_as_map`,
`lookup_image_urls_as_optional_list`,
`lookup_media_files_as_cdn_url_list_and_map`) handed back a CDN URL for
it too.

## Changes

- `batch_get_media_files_by_tokens` (all three wrappers) takes a
`MediaReadScope { viewer_user_token, is_mod }` and adds, for
non-moderators:
`AND (m.creator_set_visibility <> 'Private' OR
m.maybe_creator_user_token IS NULL OR m.maybe_creator_user_token = ?)`
Records with no creator are system intermediates that generation depends
on; they are not anyone's private data, so they remain readable. Tokens
are still bound, not interpolated.
- The five lookup helpers forward the scope;
`fetch_reference_video_sources` and the query wrappers take it as a
parameter.
- Call sites supply the requester: `scope_for_session` for cookie
sessions (so moderators keep their access), `scope_for_user_token` for
API-key/SSO callers, `MediaReadScope::ANONYMOUS` for the two genuinely
unauthenticated paths (the cost-quote duration probe and the curated
pinned-media list).
- `get_character_handler` previously read no session at all; it now
resolves one so a creator can still see their own private uploads while
anonymous callers cannot.

## Behaviour changes worth reviewing

- A generation request naming someone else's private token now fails as
"media not found" rather than generating from it.
- Private media can no longer be used as a generation input, even by a
logged-in non-owner. That is the point of the fix, but it is a real
behaviour change for any client that reused tokens across accounts.
- Anonymous callers no longer resolve private media for pinned lists or
cost quotes.

## Checks

- `SQLX_OFFLINE=true cargo check -p storyteller-web` — finished clean,
exit 0.
- No tests run: the media query and endpoint tests need a live MySQL,
which this environment does not provide. The 58-file diff is almost
entirely one added argument per call site; a reviewer should spot-check
the two `ANONYMOUS` sites and the `get_character_handler` session
addition.
2026-11-11 11:58:17 -05:00
Dylan M. Taylor b8b09b5990 fix(db-cleanup): include concrete image types in anonymous image cleanup (#253)
## What was wrong
`db-cleanup`'s `delete_all_anonymous_user_images` listed only media
files with the legacy coarse `Image` type, then re-checked
`MediaFileType::Image` before deleting. Anonymous uploads made through
`POST /v1/media_files/upload/image` are stored with a MIME-derived type
(`Jpg`, `Png`, `Gif`, `Webp`), so the cleanup skipped them and they
never got the moderator-deletion marker.

## What changed
- The listing filter now includes every type `MediaFileType::is_image()`
accepts (`Image`, `Jpg`, `Png`, `Gif`, `Webp`).
- The per-record check uses `is_image()`, so the filter and the check
agree.
- Small unit test that the selected set matches `is_image()`.

## Blast radius
Operator CLI only. Running the command now also soft-deletes (as
moderator) anonymous images with concrete types, which is what the
command says it does. Files with a creator are still skipped.

## Checks
- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web -p db-cleanup
--tests` (combined with the other fixes in this batch).
- Not run: the command itself against a database.

Addresses CodeRabbit security findings (data retention policy gap).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Anonymous-image cleanup now recognizes JPEG, PNG, GIF, and WebP files
alongside legacy image files, so these formats are included when
cleaning up images without a creator token.
  * Non-image files are skipped during cleanup.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:22:39 -05:00
Dylan M. Taylor d4033df996 fix: enforce the bucket request timeout, cap debug sleeps, fix db-cleanup batch paging (#324)
What was wrong:
- LegacyBucketClient called Bucket::set_request_timeout, which rust-s3
(tokio backend) ignores: the HTTP client is built in the constructor. A
storage peer that stalled a response held a worker forever.
- The video-style-transfer, face-fusion and
video-style-transfer-workflow jobs slept for a request-header-supplied
number of milliseconds with no maximum, parking a worker.
- db-cleanup delete_user_files advanced an offset over a listing that
shrinks as files are deleted, so it skipped every other batch.

Change: when a timeout is configured, the bucket is rebuilt with
with_request_timeout (it applies to the whole request, including body).
Debug sleeps go through debug_sleep_duration, capped at 60 s. db-cleanup
always reads offset 0 (deleted files are excluded from the listing).

Blast radius: cloud_storage, inference-job (3 call sites), db-cleanup.

Behavior changes: callers that pass Some(timeout) (jobs default to 5 min
via BUCKET_TIMEOUT_SECONDS, web 60 s-ish via env) now actually get that
limit per request, so very large transfers longer than the configured
value will fail instead of running unbounded. Debug sleeps above 60 s
are clamped.

Checks run: cargo check -p cloud_storage -p db-cleanup -p inference-job;
cargo test -p inference-job --bin inference-job debug_sleep.
Checks not run: fmt/clippy, db-cleanup against a database,
incomplete-download file cleanup on timeout (not changed).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* File cleanup now processes remaining files in batches without relying
on page offsets.
* Debug delays in face-fusion and video-style-transfer jobs are capped
at 60 seconds, preventing excessively long waits.
* Cloud storage bucket requests now apply a timeout only when one is
configured, with client setup errors propagated.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:22:32 -05:00
Dylan M. Taylor 3577dda534 fix: enforce owner TTS delete permission, case-insensitive reserved usernames, escape log values (#323)
What was wrong:
- delete_tts_model: the owner branch ignored the session's
can_delete_own_tts_models permission, so a role denying owner deletion
could still delete.
- create_account: reserved usernames were checked on the submitted text
before the lowercase/trim applied when the account is stored, so e.g.
"Admin" passed.
- list_media_files_for_user (v1/v2) and upload_url_to_media_file logged
request-supplied username/URL with {} so CR/LF could forge log lines.

Change: owners must have can_delete_own_tts_models (moderators
unaffected); is_reserved_username trims and lowercases itself; the log
arguments use {:?}. User-visible URL error strings are unchanged.

Blast radius: three handlers plus is_reserved_username (only used by
account creation validation).

Behavior changes: owners whose role lacks can_delete_own_tts_models now
get NotAuthorized; mixed-case/space-padded reserved names are now
rejected.

Checks run: cargo check -p storyteller-web (exit 0).
Checks not run: handler/unit tests (need MySQL; a new unit test for
case-insensitive reserved names was added but not executed), fmt/clippy.
2026-11-11 11:22:24 -05:00
Alex72-py cc6d88e10d fix: extract OBJ from Fal ZIP packages (application/zip) (#155)
## Summary

Fixes https://github.com/storytold/artcraft/issues/1327

Handle single-OBJ ZIP packages on the Fal mesh-upload path by storing
the **extracted raw OBJ**, not ZIP bytes under an OBJ extension. Stored
size, SHA-256, `model/obj` MIME, `.obj` extension and
`MediaFileType::Obj` all describe the same extracted bytes.

The original incident's producing endpoint/output remains unknown; this
is **not a verified reproduction** of #1327.

## Scope and safeguards

Exactly **seven files**:
- Four Fal mesh-path Rust files: `mod.rs`, `download_mesh_file.rs`,
`resolve_mesh_file_metadata.rs`, and `process_model_mesh_payload.rs`.
- Two `mysql_queries` files: `get_media_file_storage_metadata.rs` and
its `get/mod.rs` declaration.
- One matching `.sqlx` cache entry.

**No workflow files are included in this PR.**

Preserved ZIP safeguards include safe enclosed paths, backslash
rejection, rejection of symlinks/special files, a 1,024-entry maximum,
the existing companion-extension allow-list, exactly one nonempty OBJ,
and nested/disguised-format rejection.

Limits are:
- **256 MiB** total declared uncompressed package size.
- **128 MiB** actually extracted OBJ bytes.
- A separate **256 MiB actual streamed mesh-download bound**, including
after gzip decompression—not merely `Content-Length`. Both initial
download and retry are bounded.

Non-ZIP metadata precedence and the shared/non-mesh downloader remain
unchanged. Typed rejection reasons retain actionable logging, including
unsupported MIME diagnostics.

The DB test remains compiled under `#[cfg(test)]`, with individual
`#[cfg_attr(feature = "skip_database_tests", ignore)]` gating. Its
size/checksum query now uses a `sqlx::query_as!` helper in
`mysql_queries`, backed by genuine matching MySQL-generated `.sqlx`
metadata—not fabricated cache data.

## Intentional appearance limitation — maintainer decision requested

Only raw OBJ is retained. Accepted MTL/texture companions are
deliberately discarded, with a warning reporting the actual
discarded-file count when nonzero.

**Materials/textures and their appearance are not retained.** Existing
`mtllib` references can remain unresolved; the OBJ bytes are not
rewritten to repair them. Explicit maintainer acceptance of this
geometry-only storage policy is still requested.

## Validation

Current PR head: `3a7d6dce7246653f4f42b4d43bb5b5c51c677043`.

[Current validation run
42058895273](https://github.com/Alex72-py/artcraft-services/actions/runs/42058895273)
completed **SUCCESS**. Its log records
`PR155_CHECKED_OUT_SHA=3a7d6dce7246653f4f42b4d43bb5b5c51c677043`—the PR
source commit, not the separate runner head.

Verified on that exact source:
- `cargo check -p storyteller-web --tests` and `cargo check -p
mysql_queries` passed with `SQLX_OFFLINE=true`.
- **21 resolver + 8 downloader tests on each of three binaries**, plus
**1 MySQL uploader/query integration test**: **30 unique targeted tests,
88 executions, zero failures or ignored tests**.
- **Four-file rustfmt, including the uploader**, and `git diff
--exit-code` passed.

Full-crate fmt and strict clippy were intentionally skipped in validate
mode; the limitations below remain applicable. This is targeted backend
validation, not the full workspace test suite.

The [previous verified functional run,
42052717146](https://github.com/Alex72-py/artcraft-services/actions/runs/42052717146),
checked out `18a2b23786414f6b6c0883c798699ed2a7e64732` and passed:
- Backend/test-target and query-crate offline checks.
- **21 resolver + 8 downloader tests on each of three binaries**, plus
**1 MySQL uploader/query integration test**: **30 unique targeted tests,
88 executions, zero failures or ignored tests**.
- Its then-three-file rustfmt check and final git-diff check.

That integration test verifies raw stored OBJ bytes and consistent
database metadata using isolated MySQL and a test bucket—not live
Fal/browser end-to-end coverage.

**Broader lint limitations:** Full-crate fmt on
[18a](https://github.com/Alex72-py/artcraft-services/actions/runs/42053921289)
and
[main](https://github.com/Alex72-py/artcraft-services/actions/runs/42053962625)
failed, exposing PR uploader formatting alongside shared baseline drift.
Follow-up `3a7d6dc` applies all **18 actual uploader rustfmt hunks**,
formatting only; other baseline files were not cleaned.

Strict clippy failed on both sources with the **same 28 vendored
Symphonia errors**, blocking completion of the backend lint assessment.
It was **not rerun on `3a7d6dc`**; clippy is not claimed clean.

## Authentic Fal evidence limit

#1327 provides only the error and a sign-in-required Rootly alert,
without a model/output sample.

The inspected Hunyuan2.1 fixture ZIP contains three
OBJs—`white_mesh_remesh.obj`, `demo_textured.obj`, `demo.obj`—and two
GLBs—`demo_textured.glb`, `demo_textured_pbr.glb`—plus companions.
Normal dispatch prefers the GLB and skips its mesh ZIP. It is **neither
the original reproduction nor evidence of an accepted single-OBJ Fal
ZIP**.

The Rapid fixture is raw OBJ with separate companions. The original
producing endpoint and authentic single-OBJ ZIP for the affected mesh
path remain unknown.

## Outstanding upstream gate

The separate backend-CI workflow PR is
[#349](https://github.com/storytold/artcraft-services/pull/349). Its
[workflow run
42267776142](https://github.com/storytold/artcraft-services/actions/runs/42267776142)
is waiting for maintainer approval (`action_required`); it has not run
and has zero jobs.

**Manual fork runs are supporting technical evidence only. They do not
satisfy reviewer request 1's upstream, current-head backend-CI gate.**
That gate and the appearance-policy decision remain outstanding; this
description does not claim approval or merge-readiness.
2026-11-11 11:22:16 -05:00
logs 5a01d59775 Keep bookmark counts in step with each user's bookmarks (#225)
`entity_stats.bookmark_count` drifts away from the real number of
bookmarks during normal use. Both the create and delete handlers decide
whether to change the count from a bookmark that
`get_user_bookmark_transactional_locking` looks up, and both lookups can
return the wrong bookmark.

- **Create:** the lookup by entity isn't filtered by user (`WHERE
b.entity_type = ? AND b.entity_token = ?` with `fetch_one`). Once anyone
has bookmarked an entity, every later user finds that live bookmark, and
the handler skips the increment.
- **Delete:** the lookup by bookmark token joins the bookmark against
every bookmark of the same entity (to lock them), but selects the
columns from the joined row, so it returns an arbitrary bookmark of that
entity. The handler then decrements whenever that row is live. That
includes when the token belongs to someone else, in which case the
delete itself (`WHERE token = ? AND user_token = ?`) matches nothing.

## How to trigger it

1. User A bookmarks a media file: the count becomes 1.
2. User B bookmarks it: the count stays 1, with 2 bookmarks.
3. B removes their bookmark: the count drops to 0, while A's bookmark is
still there.

Separately, `POST /v1/user_bookmarks/delete/{token}` with someone else's
bookmark token (the entity bookmark list returns tokens) lowers the
count without deleting anything.

The count is shown in the media file and weight responses
(`stats.bookmark_count`).

## Fix

- **Create** keeps the same entity-wide `SELECT ... FOR UPDATE`, adding
`ORDER BY (b.user_token = ?) DESC LIMIT 1` so that only the caller's
bookmark comes back. If the caller has none, the row returned is someone
else's and is discarded. Sorting on an expression makes MySQL read, and
so lock, every bookmark of the entity before applying the limit. I
checked with `performance_schema.data_locks` that the lock set is
identical to `main`'s: all of the entity's bookmark records plus the
next gap, and its `entity_stats` row.
`BookmarkIdentifier::EntityTypeAndToken` becomes
`UserAndEntity(user_token, entity_token)`, and the lookup takes a named
args struct.
- **The lookup by token** selects the requested bookmark (`b1`) instead
of the joined row. The self-join and locking are unchanged.
- **Delete** only decrements when the bookmark is live and belongs to
the caller.

The response bodies and status codes are unchanged. Deleting someone
else's bookmark still returns `success: true`, as before; it just no
longer changes the count. The two changed queries have new `.sqlx`
entries, generated by sqlx from a migrated database, in place of the
stale ones.

## Tests

`application_routes/user_bookmarks_endpoint_tests.rs` drives the real
create, delete and media file routes with signed sessions against the
test database, and reads the stored count back through `GET
/v1/media_files/file/{token}`:

- `each_users_bookmark_is_counted`
- `deleting_a_bookmark_removes_only_that_users_count` (it also deletes
the same bookmark a second time)
- `deleting_someone_elses_bookmark_does_not_change_the_count`
- `repeated_bookmark_and_delete_count_once`

The first three fail on `main` and pass with this change. The last one
is a regression check for repeated create and delete calls, and passes
on both.

These tests take `acquire_serial_test_lock()`, which goes beyond the
lock's documented use, so here is why. When they ran in parallel, InnoDB
deadlocks turned a bookmark request into a 500 (seen with `SHOW ENGINE
INNODB STATUS`):

- two `INSERT INTO user_bookmarks` waiting on each other's gap lock in
`index_entity_type_entity_token`;
- separately, two `entity_stats` `INSERT ... ON DUPLICATE KEY UPDATE`
statements doing the same.

Both come from the existing locking, which this change keeps as it was.
A `FOR UPDATE` lookup that finds no rows locks a gap, and the following
insert goes into that gap. In the nearly empty test tables, unrelated
new entities share the same gaps. In production the same deadlock is
possible when two entities that are adjacent in the index get their
first bookmark at the same moment.

- MySQL 8.0.45, `cargo test -p storyteller-web`: 698 passed, 12 failed,
8 ignored. The 12 failures are the login challenge and user media
endpoint tests, which use `IsolatedTestDatabase`. It connects only
through the Homebrew socket `/tmp/mysql.sock`, which doesn't exist on
this machine. None of them touch bookmarks.
- `SQLX_OFFLINE=true cargo test -p mysql_queries`: 81 passed, 0 failed,
14 ignored.
- `cargo clippy --no-deps --all-targets` reports nothing on the changed
lines.

## After deploying

Counts that have already drifted stay wrong. Until they are recounted, a
delete by a user who was never counted can push a count to 0, and
`ABS(bookmark_count - 1)` then bounces it back to 1. A one-off recount
of live rows per entity from `user_bookmarks WHERE deleted_at IS NULL`
would correct them.

## Not fixed here

When a user bookmarks something they had bookmarked and removed before,
`upsert_user_bookmark` revives the existing row but returns a newly
generated token that was never stored. Deleting with that token returns
404. I left that out to keep this change to the counts.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Bookmark updates now correctly distinguish bookmarks by both the user
and the bookmarked item.
* Deleting a bookmark only changes the item’s bookmark count when it
belongs to the signed-in user and has not already been deleted. Repeated
deletions no longer reduce the count again.
* Repeatedly bookmarking the same item counts only once, and deleting
and recreating a bookmark updates the count correctly.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:22:08 -05:00
Dylan M. Taylor de764c9d81 fix: persist the requested visibility when importing TTS and voice conversion models (#326)
What was wrong: the download job processors (tacotron, VITS, RVC v2,
So-VITS-SVC, SoftVC) hard-coded Visibility::Public ("TODO: All models
default to public") instead of the creator's queued choice, and
insert_tts_model_from_download_job /
insert_voice_conversion_model_from_download_job accepted
creator_set_visibility but never wrote it. A model imported as Private
or Hidden became public.

Change: both INSERTs now write creator_set_visibility, and the
processors pass job.creator_set_visibility (the hifigan vocoder
processors already did). The two changed sqlx::query! statements have
updated .sqlx offline entries (old entries removed; written by hand from
the same describe data, one extra bind parameter, hash = sha256 of the
new text, and verified by an offline compile).

Blast radius: two mysql_queries insert functions, five download-job
processors. The model_weights inserts already persisted the field.

Behavior changes: imports queued as Private/Hidden are now stored that
way instead of Public. Imports queued as Public are unchanged.

Checks run: cargo check -p download-job (SQLX_OFFLINE=true).
Checks not run: DB tests (need MySQL), fmt/clippy, `cargo sqlx prepare
--check` (no database; entries not regenerated by tooling).
2026-11-11 11:22:00 -05:00
Dylan M. Taylor 9cd544adef fix: bound decoded downloads, linear tag recount, ban/ownership checks on legacy handlers (#316)
## What was wrong
- `http_download_url_to_bytes` enabled gzip and collected the whole
decoded body with `bytes()` and no size limit, so a small compressed
response from an attacker-chosen media origin could exhaust memory.
- `apply_tags` merged previously linked tag tokens into a growing `Vec`
with `contains` per token (quadratic CPU on attacker-accumulated
history, inside a transaction).

## What changed
- The downloader reads chunks and returns a new
`DownloadFileToBytesError::TooLarge` once decoded bytes pass 1 GiB
(generous headroom over legitimate media). Error-status bodies are
bounded the same way.
- `apply_tags` uses a `HashSet` for membership; resulting order and
contents are identical.

## Behavior changes
Downloads larger than 1 GiB now fail. Nothing else for valid input.

## Checks
- run: `cargo check -p storyteller-web --tests`
- not run: DB-backed tests (need MySQL); clippy -D warnings (fails on
unmodified main in `enums`); no test for the 1 GiB cap (would need to
serve that much).


## Second part: authorization fixes
### What was wrong
- The five legacy text-to-image handlers (flux 1 dev/schnell, flux pro
1.1/ultra, gpt-image-1) accepted any valid session, including banned
accounts.
- `terminate_inference_job_handler` only compared owners when the caller
also had a session; omitting the cookie made an account-owned job fall
back to IP equality, so anyone behind the same IP could cancel it.
- `change_media_file_engine_category_handler` returned category-specific
errors (existence/engine details) before checking the caller may edit
the file.

## What changed
- Banned sessions get `NotAuthorized` in those five handlers.
- Account-owned jobs require the owning session; the IP rule remains
only for anonymous jobs.
- Creator-or-moderator check moved directly after loading the record.

## Behavior changes
Banned users lose access to those routes (intended); a signed-out caller
can no longer cancel an account-owned job from the same IP; non-owners
now get NotAuthorized instead of validation messages.

## Checks
- run: `cargo check -p storyteller-web --tests`
- not run: handler tests (need MySQL); clippy -D warnings (fails on
unmodified main in `enums`).


Findings: 46338003, 44b859e9, 56186c57, 1f1f2f34, 5456374d
Not touched: media-lookup/mesh dedup (09045369, 0355e215; files in #229)
and the missing wallet deduction on legacy Flux Dev/Hunyuan (owner).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Banned accounts can no longer submit text-to-image generation
requests.
* Terminating an inference job now requires a matching signed-in session
when the job has a creator. IP-based checks remain for jobs without a
creator.
* Media-file engine category changes now check permissions before
validating category selections.
* URL downloads follow up to 10 redirects and are limited to 1 GiB;
oversized downloads are rejected. Non-success responses continue to
report the response details.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:21:52 -05:00
Dylan M. Taylor ab32c3aec6 fix: bound decompressed bytes when extracting studio-shot frames (#303)
## What was wrong

The studio-shot upload extracts frame images from a ZIP into a temp
directory with an unbounded `std::io::copy`. The 8,000-file cap limits
entry count, not decompressed size, so a small, highly compressible
archive could expand to many gigabytes of temp writes and decompression
work inside the request.

## What changed

Each member is copied through `copy_within_budget`, which reads at most
one byte past the limit and fails with a new
`ExtractFramesError::TooLarge` when a frame exceeds `MAX_FRAME_BYTES`
(64 MiB) or the upload exceeds `MAX_TOTAL_EXTRACTED_BYTES` (4 GiB). The
handler maps it to an error response like the other extraction errors.
The constants sit next to the existing `TOO_MANY_FILES_COUNT`.

## Checks

- Run: `cargo test -p storyteller-web extract_frames_from_zip` (3
passed: a frame exactly at the limit, one byte over, and the running
total); `SQLX_OFFLINE=true cargo check -p storyteller-web` (exit 0).
- Not run: the upload endpoint test (needs a live MySQL).
- Not done: moving extraction off the request worker (the finding's
second suggestion).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* ZIP uploads now reject frames larger than 64 MiB and combined
extracted frames exceeding 4 GiB, with a clear error message when
archive contents are too large.
* Errors while reading or writing extracted frames are reported as
extraction failures.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:21:44 -05:00
Dylan M. Taylor 11242401eb fix: reject expired web sessions (#230)
## Summary

`get_api_or_web_session_user_by_session_token` is the lookup behind
cookie authentication. It joined `user_sessions` and filtered on
`deleted_at` and the user's own deletion state, but never compared
`expires_at`. The signed cookie payload carries no expiry claim either,
so an expired session row kept authenticating every request — a hijacked
or long-lived cookie stayed valid until someone deleted the row.

The lookup now also requires:

```sql
AND (user_sessions.expires_at IS NULL OR user_sessions.expires_at > UTC_TIMESTAMP())
```

The `IS NULL` arm keeps any legacy row without an expiry non-expiring
rather than silently logging everyone out; if `expires_at` is `NOT NULL`
in production it is simply dead.

## Note on the `.sqlx` cache

`sqlx::query!` is compile-checked against `.sqlx/`, and this environment
has no MySQL, so `cargo sqlx prepare` could not run. I generated the
replacement cache entry the way `prepare` does (same column metadata,
`hash = sha256(query)`), and the crate compiles offline against it.
**Please run `cargo sqlx prepare` against a real database before
merging** to confirm the entry matches what the tool would produce.

## Checks

- `SQLX_OFFLINE=true cargo check -p storyteller-web` — finished clean,
exit 0.
- No tests run: `mysql_testing` fixtures (including
`expire_user_session`) need a live MySQL. A regression test that expires
a session and expects a 401 would be worth adding here.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Expired sessions are no longer accepted during session lookup,
including sessions that expire at the current time.
  * Sessions without an expiration time remain eligible for lookup.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:21:36 -05:00
Dylan M. Taylor a3f7204180 fix: reject passwords longer than bcrypt's 72-byte input (#302)
## What was wrong

bcrypt only uses the first 72 bytes of a password. Account creation,
password change and password reset accepted longer passwords and hashed
them, so everything after byte 72 was silently ignored. A user who
changed only the tail of a long password hadn't really changed it, and a
long passphrase was weaker than it looked.

## What changed

- `password` crate: new `BCRYPT_MAX_PASSWORD_BYTES = 72`.
`bcrypt_hash_password` returns a new
`PasswordHashError::PasswordTooLong` instead of truncating (with a unit
test at 72 and 73 bytes).
- `validate_passwords` (account creation, password change) rejects
longer passwords with a clear 400 message.
- Password reset redemption rejects them with a new `PasswordTooLong`
400 error.

Login (`bcrypt_confirm_password`) is unchanged, so existing accounts
with longer passwords can still sign in; they just can't set a new one
over 72 bytes.

## Checks

- Run: `cargo test -p password` (6 passed); `SQLX_OFFLINE=true cargo
check -p storyteller-web` (exit 0).
- Not run: endpoint tests (need a live MySQL).
2026-11-11 11:21:29 -05:00
Dylan M. Taylor 80440b43fe fix: answer password reset requests before doing account-dependent work (#312)
## What was wrong

`POST /v1/password_reset/request` returns the same body whether or not
the account exists, but not in the same time. For unknown accounts it
returned right after the lookup. For real accounts it first created the
reset record, inserted the email job, and awaited the external Resend
email send. The response time difference (often hundreds of ms) lets
anyone enumerate registered emails and usernames.

## What changed

After the lookup, the account-dependent work moves unchanged into
`issue_password_reset`, which runs on a spawned task
(`actix_web::rt::spawn`). The handler returns the success response
immediately in both cases. Failures in the background task are logged
(`error!`) instead of returned. Callers couldn't act on them anyway, and
unknown accounts already got a plain success.

## Blast radius

One handler. A reset email that fails to send no longer produces a 500
for the requester; it shows up in logs instead. #217 touches the lookup
lines above this change; any rebase is trivial.

## Checks

- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web` (exit 0).
- Not run: endpoint tests (need a live MySQL and email provider).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Password reset requests now return the same success response whether
or not the account exists.
* Requests for known accounts are acknowledged immediately while the
reset email is processed in the background. Processing failures do not
change the response.
* When reset processing is at capacity, requests still receive the same
success response.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:21:21 -05:00
Dylan M. Taylor 147f9a7fa7 fix: revoke existing sessions when a password reset is redeemed (#310)
## What was wrong

Redeeming a password reset changed the password (and bumped
`password_version`) but left every existing session valid, and session
checks don't look at `password_version`. Someone who already had a
session on the account (the reason for recovering it, often) kept access
after recovery and could even change the password again.

## What changed

`change_password_from_password_reset` now also soft-deletes all of the
user's live `user_sessions` rows inside the same transaction as the
password update, rolling back if that fails. The redeem handler already
creates a fresh session for the person who completed the reset, after
commit.

It's a runtime `sqlx::query` (no new `.sqlx` offline entry needed).
Sessions already cached in Redis expire within the cache TTL
(`REDIS_CACHE_TTL_SECONDS`, 60s by default).
- A password login now creates its session with one conditional insert:
it succeeds only if `password_version` still matches the version the
password was verified against, under a row lock on the user. A login
that races a reset is answered as invalid credentials instead of leaving
a live session behind.


## Checks

- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web` (exit 0).
- Not run: the reset flow tests (need a live MySQL).
- Not changed: ordinary password changes (`change_password_handler`)
still keep other sessions.


## Review round (ed360d5dc)

- Session listing, revoke and the conditional insert are one query per
file, each with an Args struct (`list_live_session_tokens`,
`revoke_all_user_sessions`, `create_user_session_if_password_version`).
No behavior change.
- Every session insert that verifies no password is now ordered against
a reset under the same `users` row lock: Google SSO uses the conditional
insert with the version read inside the statement; impersonation login
and the login-challenge bridge session inserts became `INSERT ... SELECT
FROM users ... FOR UPDATE` (runtime queries; their stale `.sqlx` entries
removed). `create_account_handler`, billing `user_creation_case` and the
redeem handler's post-commit session are unchanged.
- Redis cache-fill race: after the first purge, the redeem handler
purges the revoked sessions' cache keys again after 5 s. A fill that
started before the commit and lands later than that is still bounded by
the cache TTL (60 s default); the session checker was not redesigned.
- Checks run: `cargo check -p storyteller-web`, `cargo check --tests -p
storyteller-web -p mysql_testing` (both pass); unit test
`purges_both_cache_entries_for_every_revoked_session` passes. Not run:
DB tests (no MySQL), clippy/full fmt (repo has pre-existing fmt diffs).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Security**
* Active sessions are revoked after a password is changed through a
password reset. If revocation fails, the change is rolled back.
* Revoked sessions are also removed from the session cache when
possible.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:21:13 -05:00
Dylan M. Taylor 28e7caa573 fix: reject other users' private images as Veo 2, Veo 3 Fast and Kling 2.1 Master sources (#319)
## What was wrong
The legacy image-to-video handlers for Veo 2, Veo 3 Fast and Kling 2.1
Master loaded the caller-supplied source image by token without checking
visibility, so anyone holding another user's private image token could
send it to the provider and receive derived output.

## What changed
Same check as #283 (Veo 3): a Private source is usable only by its
creator or a moderator (`can_delete_other_users_tts_results`); otherwise
`NotFound`, so existence is not confirmed.

## Behavior changes
Using someone else's private image as a source now returns 404.
Public/unlisted and own images unchanged.

## Not covered
fcdeb392 also lists Kling 1.6 Pro, Kling 2.1 Pro, Seedance 1.0 lite/pro
and the Beeble edit handler; they load media through different code
paths (batch lookup / video sources) and are left open for a follow-up.
Veo 3 is #283.

## Checks
- run: `cargo check -p storyteller-web --tests`
- not run: handler tests (need MySQL); clippy -D warnings (fails on
unmodified main in `enums`).

Finding: fcdeb392 (partial)
2026-11-11 11:21:05 -05:00
Dylan M. Taylor 2394ab8070 fix: refuse another user's private image as a weight cover (#318)
## What was wrong
Both weight cover setters (`set_model_weight_cover_image_handler` and
the `cover_image_media_file_token` branch of `update_weight_handler`)
authorized the weight but only checked that the chosen media file exists
and is an image. A weight owner who knew another user's private image
token could make it the cover and publish its storage links.

## What changed
A Private image that the caller did not create is rejected with
`NotFound` (same rule as the cover-image read paths in #267: not
private, or same creator). Own private images and any non-private image
still work.

## Behavior changes
Setting someone else's private image as a cover now returns 404.

## Checks
- run: `cargo check -p storyteller-web --tests`
- not run: handler tests (need MySQL); clippy -D warnings (fails on
unmodified main in `enums`).

Findings: 58119149, 2490367c
2026-11-11 11:20:58 -05:00
Dylan M. Taylor 307026f29b fix: hide unreadable results on batch and Omni API job status (#309)
## What was wrong

Three job-status reads return a completed job's result media token,
bucket path and CDN links to anyone holding the job token, without
checking the result media's current visibility or deletion:

- `GET /v1/jobs/batch` (public, cookie session optional)
- `GET /v1/omni_api/job_status/{token}` and the Omni API batch route
(API-key authenticated, but the authenticated user was discarded)

So results the creator later made private, or deleted, stayed reachable
through any known job token.

## What changed

New shared helper `util::lookup::hide_unreadable_job_results` takes the
job records, the viewer's user token and moderator flag, loads all media
results in one `batch_get_media_files_by_tokens` query (deleted rows
only for moderators), and clears `maybe_result_details` for results that
are deleted, or private and not the viewer's. Status, progress and
failure fields are untouched.

- Web batch: viewer from the cookie session; moderators via
`can_delete_other_users_tts_results`.
- Omni API single and batch: viewer is the API key's user
(`require_api_key_user` already returned it).

The single web job route (`/v1/jobs/job/{token}`) is handled in #277.

## Notes for review

- #229 adds a read-scope parameter to `batch_get_media_files_by_tokens`.
Whichever merges second needs a one-line update here (passing
`MediaReadScope` or keeping `can_see_deleted`).
- Anonymous (visitor-token) creators of private media aren't matched
here; private results are normally owned by logged-in users.

## Checks

- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web`; `cargo test
-p storyteller-web hide_unreadable_job_results` (1 passed, covers
public/hidden/private, creator, other user, moderator, missing creator).
- Not run: endpoint tests (need a live MySQL).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Job status responses now hide media results that the viewer isn’t
permitted to access, while retaining other status information.
* Private media results are shown only to their creator or a moderator.
Public and hidden media results remain visible, and missing media
results are hidden.
* If media lookup fails, result details are hidden rather than exposing
potentially inaccessible results.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:20:50 -05:00
Dylan M. Taylor eff0b1e676 fix: check access to job inputs before enqueueing legacy media jobs (#271)
## What was wrong

The legacy enqueue routes took media tokens from the request and queued
them without checking who owned them:

- `/v1/conversion/enqueue_fbx_to_gltf`
- `/v1/animation/face_animation/create`
- `/v1/animation/rerender/create`
- the live portrait / face mirror routes
- the face fusion route
- the studio and VST workflow routes
- `/v1/workflow/comfy/create`
- the GPT-SoVITS model download (cover image)

The workers download those objects with the service's bucket credentials
and publish the result under the requester. Anyone holding another
user's private media token could therefore get a converted, animated or
restyled copy of it. With GPT-SoVITS, they could attach it as a model
cover that anyone can read. The live portrait worker also reads deleted
inputs.

## What changed

- New `util::job_input_access`. It allows an input only when it exists,
is not deleted, and is either non-private or created by the requester.
Moderators (`can_ban_users`) are allowed. Records with no creator user
follow the same rule as the batch media read policy in #229.
- Every route listed above now checks each input token before inserting
the job. A media-file, media-upload or voice-conversion-result token
that fails the check gets a not-found or bad-input response.
- New query `media_uploads::get_media_upload_access_info`. Legacy media
uploads need their creator token for this check, and existing queries
don't return it. It is a runtime query because
`maybe_creator_user_token` on that table has no offline cache entry.
Swap it for `query_as!` after the next `cargo sqlx prepare`.

## Blast radius

Only callers who name media they cannot read are affected. Their jobs
are no longer enqueued. Jobs on your own media, public media or hidden
media are unchanged.

## Not covered here

- The workers do not recheck access before downloading. Any job already
in the queue, or any job inserted by another path, is still processed.
- The video style transfer worker follows `original source` references.
That lookup is not rechecked.
- The weight read path still serves the cover links that are already
stored on weights.

Addresses CodeRabbit security findings (CWE-639).

## Checks run

- `SQLX_OFFLINE=true cargo check -p storyteller-web -p mysql_queries`
- Unit tests for the visibility rule (`job_input_access`) are included;
results to follow in a comment once the shared build host frees up.

## Checks not run

- Handler and query tests against a live MySQL.
- End-to-end worker runs. They need GPUs and the bucket.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Job submissions now check whether referenced media, uploads, and
voice-conversion results are available to the requester before creating
a job.
* Public and hidden items are usable by any requester. Private items are
usable by their creator or a moderator; private items without a creator
are also usable by any requester.
* Missing, deleted, or inaccessible inputs are rejected as not found.
Access-check errors are reported as server errors.
* Checks cover animation, workflow, conversion, and model-download
submissions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:20:42 -05:00
Dylan M. Taylor d1c203236f fix: hide private and deleted media from public bookmark lists (#257)
## What was wrong
`GET /v1/user_bookmarks/list/user/{username}` is public. Its query joins
`media_files` for media bookmarks and returned the bucket hash, prefix,
extension and creator for every bookmarked file, regardless of the
file's visibility or deletion state. Anyone could list another user's
bookmarks and get CDN URLs for private (or deleted) media.

## What changed
- `list_user_bookmarks_by_maybe_entity_type` takes
`maybe_viewer_user_token` and `viewer_is_moderator`.
- For non-moderators, rows that join a media file are kept only if the
file is not deleted and is either non-private or created by the viewer.
Non-media bookmarks are unaffected. The count query uses the same
filter, so page counts stay consistent.
- The handler resolves the optional session; moderators
(`can_delete_other_users_tts_results`, as in `get_media_file_handler`)
see the list unfiltered.
- Unit tests on the generated SQL.

## Blast radius
Public bookmark lists lose private/deleted media entries for anonymous
and non-owner viewers. Model-weight bookmarks are not filtered by weight
visibility here.

## Checks
- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web -p db-cleanup
--tests`.
- Not run: the new `mysql_queries` unit tests and endpoint tests (need
MySQL for the latter).

Addresses CodeRabbit security findings (CWE-862).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Bookmarked media now follows visibility and deletion rules: private or
deleted media is hidden from viewers who aren’t allowed to see it.
* Creators can still see their own private bookmarked media, and
moderators can view bookmarks without these filters.
* Bookmark lists and totals reflect the viewer’s access, with anonymous
viewers handled without a signed-in session.
* If session lookup fails, bookmark lists can still be shown without
signed-in access.
* Bookmark responses are marked as private and are not stored in caches.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:20:34 -05:00
Dylan M. Taylor 357d4705b9 fix: don't use a private imageref as the cover of a shared result (#256)
## What was wrong
For mesh/splat results with no thumbnail, the FAL webhook attaches the
prompt's first image reference as the result's cover
(`try_to_attach_prompt_imageref_cover`). It never looked at the
reference's visibility, so a private source image could become the cover
of a public result, and every response that shows the result's cover
then exposed the private image's bucket path and URL.

## What changed
Before attaching, the helper loads the imageref and the target media
file:
- non-private imageref: attach as before;
- private imageref: attach only if the result is also private and has
the same creator;
- any lookup error or missing row: skip (the helper already fails open
on the webhook, closed on the cover).

Unit tests cover the decision table.

## Blast radius
Webhook cover fallback only. Results generated from a private image now
get no cover unless they are private too. Covers attached before this
change are not cleaned up, and cover links in media responses still
don't apply the cover's own visibility.

## Checks
- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web -p db-cleanup
--tests`.
- Not run: the new unit tests (the crate's test build is heavy here) and
a webhook replay (needs MySQL).

Addresses CodeRabbit security findings (CWE-863).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Prompt image covers are now displayed only when their visibility is
compatible with the result. Private images appear only on private
results created by the same person.
* Covers are skipped when image details are unavailable or cannot be
checked, preventing potentially restricted images from appearing.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:20:27 -05:00
Dylan M. Taylor 5569669446 fix: confine the Comfy workflow output path to the job's output directory (#246)
## What was wrong

`POST /v1/workflow/comfy/create` accepts `maybe_output_path` from the
caller. The inference worker:

- joined it onto the Comfy output directory,
- copied the input video to it (`SKIP-PROCESS-VIDEO`),
- deleted it, or the directory, during cleanup,
- and spliced it into `bash -c` command lines for audio restoration
(`FfmpegAudioReplaceArgs`) and watermarking.

Because of this, an absolute path or `..` escaped the output directory
(CWE-22), and shell metacharacters ran commands as the worker (CWE-78).

## What changed

`check_and_validate_job` now rejects any output path that is not made
only of plain relative segments of `[A-Za-z0-9._-]`. That means no
empty, `.` or `..` segments, no leading `/` or `-`, and at most 255
bytes. The check runs before the job does any work. The default path
`vid2vid/SparseUpscaleInterp_00001.mp4` and the paths legacy clients
send still pass.

## Blast radius

Only jobs from the legacy Comfy route that send unusual output paths are
affected. Those jobs now fail validation instead of running. Studio and
VST jobs do not set an output path, so they are unchanged.

Addresses CodeRabbit security findings (CWE-22, CWE-78).

## Checks run

- `cargo test -p inference-job --bins check_and_validate_job` (new unit
tests for traversal, absolute paths and shell metacharacters)

## Checks not run

- An end-to-end worker run. It needs ComfyUI, a GPU and the bucket.
- Replacing `bash -c` with direct process arguments in `CommandRunner`.
That would be a wider refactor of the deprecated worker. With this
change the paths it receives are already inert.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

- **Bug Fixes**
- Output paths for video style transfer jobs are now checked for valid
format and length. Invalid paths—including absolute paths, traversal
segments, unsupported characters, and paths that are too long—are
rejected with an error identifying the path. Valid relative paths
continue to be accepted.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:20:19 -05:00
Dylan M. Taylor c92c0a61c4 fix: pass download URLs to the downloader as arguments, not shell text (#241)
## What was wrong

`GoogleDriveDownloadCommand::download_file` and
`download_file_with_file_name` put the download URL into a shell string
(`--url "<url>"`) and ran it with `sh -c`. Double quotes do not stop
`$(...)` or backticks, so a URL submitted to the generic download
enqueue routes or the GPT-SoVITS model download route could run commands
on the download/inference worker. The Docker variant nested the same
string inside `bash -c "..."`, which had the same problem.

## What changed

- The URL and output filename are no longer part of the shell source.
The script is now `<download_script> --url "$1" --output_filename "$2"`
and the values are passed as positional parameters to `sh -c`, so the
shell expands them as plain data. The configured script, venv activation
and working directory (operator config) keep working as before.
- With Docker, the command is built as an argument vector with a new
`DockerOptions::to_command_args`. The URL and filename go to the
container shell as `$1`/`$2`, and no host shell is involved.
- The two methods now share one `run_downloader`/`build_command` helper
instead of duplicating the logic.

## Blast radius

Deprecated download_job, tts_download_job and inference_job upload paths
(GPT-SoVITS, SD/LoRA, workflow uploads). The public method signatures
are unchanged. `DockerOptions::to_command_string` is unchanged, and its
other callers are not affected.

## Checks run

- `cargo test -p google_drive_downloader -p subprocess_common` passed.
New tests: a hostile URL containing `$(...)`, backticks and quotes
reaches the downloader as one literal argument (run through a real
`sh`), the generated shell source never contains the URL, and the Docker
argument vector keeps positional arguments separate.

## Checks not run

- No end-to-end run of the download workers (they need the Python
downloader script, Docker, and a job queue).
- `cargo check` was not run on the dependent job binaries
(`download_job`, `tts_download_job`, `inference_job`). The public API
they use is unchanged.

Addresses CodeRabbit security findings (CWE-78).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Downloads now pass the URL and output filename separately, so
characters in these values are preserved rather than interpreted as part
of a command.
* Docker-based downloads retain support for configured environment
variables, bind mounts, and GPU options.
* Failed downloads continue to report error details when available, with
a fallback message when the error output cannot be read.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:20:12 -05:00
logs 1066e7662c Clear mod_deleted_at when a moderator undeletes a weight (#224)
`DELETE /v1/weights/weight/{token}` with `set_delete: false` and
`as_mod: true` calls `undelete_weights_as_user`, which only clears
`user_deleted_at`. A weight that a moderator deleted (`mod_deleted_at`)
therefore stays hidden after a moderator undeletes it, while the
endpoint returns 200. `undelete_weights_as_mod` exists but was never
called.

## How to trigger it

As a moderator, send `DELETE /v1/weights/weight/{token}` with
`{"set_delete": true, "as_mod": true}`, then the same with
`{"set_delete": false, "as_mod": true}`. Both return 200, but `GET
/v1/weights/weight/{token}` still returns 404 for everyone else.

## Fix

Call `undelete_weights_as_mod` in the moderator branch. That is the
inverse of the delete branch, which already calls
`delete_weights_as_mod`, and it matches what the media file and TTS
model delete handlers do.

One behaviour change follows from this. Before, a moderator undelete
cleared `user_deleted_at`, so a moderator could restore a weight that
its owner had deleted. Now it clears only the moderator deletion and
leaves the owner's deletion in place. If moderators are meant to be able
to restore owner-deleted weights, that should be its own explicit
option.

## Tests

`application_routes/weights_delete_endpoint_tests.rs` drives the real
weight routes against the test database. A moderator deletes and then
undeletes a fresh weight, and a logged-out `GET` must return 404 and
then 200. On `main` the second `GET` returns 404. This adds a
`mysql_testing::fixtures::model_weights::create_test_model_weight`
fixture, and uses the seeded `mod` role via `set_user_role`.

- MySQL 8.0.45, `cargo test -p storyteller-web`: 695 passed, 12 failed,
8 ignored. The 12 failures are the login challenge and user media
endpoint tests, which use `IsolatedTestDatabase`. It connects only
through the Homebrew socket `/tmp/mysql.sock`, which doesn't exist on
this machine. None of them touch weights.
- `cargo test -p mysql_testing`: the 12 unit tests pass.
`user_media_library` fails for the same socket reason.
- `cargo clippy --no-deps --all-targets` reports nothing on the changed
lines.

While writing the test I also noticed that a weight's owner can't undo
their own delete through this endpoint. The handler looks the weight up
with `can_see_deleted` set only for moderators, so the owner's undelete
request gets a 404 before it reaches the `AsUser` branch. That may be
intended, so I've left it alone.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Fixed an issue where moderators restoring a deleted voice-conversion
model could be treated as regular users. Moderator restorations now
follow the appropriate permissions, while user restorations remain
unchanged.
* Restored models are again available through public routes, and deleted
models remain unavailable there until restoration.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:20:04 -05:00
logs 7d64ee3300 Match password reset lookups case-insensitively, like login (#217)
`POST /v1/password_reset/request` looks up the account using exactly
what the user typed, after trimming it. Every account path stores
usernames and emails trimmed and lowercased: `create_account`,
`edit_email`, `edit_username`, and Google SSO. The `users` table uses
`utf8mb4_bin`, so the lookup is case-sensitive. Any capital letter in
the input therefore finds no account. The handler then returns `success:
true` (so it doesn't reveal whether the account exists) and sends no
email.

`/v1/login` lowercases its input, so the same text works for login but
not for password reset.

## How to trigger it

For an account with the email `alice@example.com`, request a reset for
`Alice@example.com`. Phone keyboards capitalize the first letter, so
this is easy to do by accident. The response says success, but no reset
row is created and no email is sent.

## Fix

The input is now trimmed and lowercased before the lookup, the same way
the account creation paths normalize it. The reset email is still sent
to the address stored on the account, not to the typed input. The
request and response format is unchanged.

## Tests

`password_reset_request_handler::tests` covers the normalization.
`lowercases_email` and `lowercases_username` fail on `main` and pass
with this change.

- `SQLX_OFFLINE=true cargo test -p storyteller-web --features
skip_database_tests`: 572 passed, 0 failed, 145 ignored (the database
tests).
- `cargo clippy -p storyteller-web --no-deps` reports nothing on the
changed lines.

I don't have MySQL here, so the database fixture tests were skipped. A
handler-level database test isn't practical because the handler sends
the email through Resend.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Password-reset requests now ignore leading and trailing whitespace and
treat usernames and email addresses as case-insensitive.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:19:56 -05:00
logs e5366d8dc5 Remove the old downvote when a rating changes from negative to positive (#215)
When a user changes their rating on an entity from negative to positive,
`set_user_rating_handler` maps the change to
`RatingsAction::NeutralToPositive`. That action adds one to
`ratings_positive_count` but leaves `ratings_negative_count` alone, so
the old downvote is never removed. `RatingsAction::NegativeToPositive`
already exists in `upsert_entity_stats_on_ratings_event` and does both;
it just wasn't used.

## How to trigger it

As one user, `POST /v1/user_rating/rate` the same entity with
`rating_value` set to `negative`, then `positive`, then `negative`, then
`positive`, and so on. Each negative-to-positive switch leaves
`entity_stats.ratings_negative_count` one higher than the number of
users who currently rate the entity negatively. The count keeps growing
with every cycle.

## Fix

- Map `(Negative, Positive)` to `NegativeToPositive`.
- Move the transition table out of the handler into a small
`ratings_action_for_change` helper below it, so it can be unit tested
without a database.

The other eight transitions are unchanged.

## Tests

`set_user_rating_handler::tests` covers all nine transitions.
`changes_from_negative` fails on `main` and passes with this change.

- `SQLX_OFFLINE=true cargo test -p storyteller-web --features
skip_database_tests`: 573 passed, 0 failed, 145 ignored (the database
tests).
- `cargo clippy -p storyteller-web --no-deps` reports nothing on the
changed lines.

I don't have MySQL here, so the database fixture tests were skipped.
This change doesn't touch any SQL.

Counts that are already inflated stay wrong after this change. If they
matter, a one-off recount from `user_ratings` would correct them.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Rating statistics now reflect changes from negative to positive
ratings correctly. Leaving a rating unchanged no longer triggers a
statistics update, and transitions between rating values are handled
consistently. These updates keep displayed rating statistics aligned
with users’ latest rating choices without changing the available rating
options or how users submit ratings.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:19:48 -05:00
Dylan M. Taylor 581b4e38d0 fix: enforce the Google sign-in issue-time cutoff against the token's iat (#288)
## What was wrong

`decode_and_verify_token_claims` accepts a `VerificationOptions` whose
`reject_before` is meant to refuse tokens issued before a cutoff. The
pinned jwt-simple compares `reject_before` with the **current clock**,
not the token's `iat`, so once the cutoff is in the past every older
token passes and the caller's policy silently does nothing.

## What changed

`decode_and_verify_token_claims_with_key` notes `reject_before` before
verification and, after the signature checks out, requires the verified
`issued_at` to be at or after it. A token without `iat` is rejected when
a cutoff is set. Callers that don't set `reject_before` see no change.

## Checks

- Run: `cargo test -p google_sign_in` (8 passed, including a new test
with the fixture token: a cutoff equal to its `iat` passes, one second
later fails).
2026-11-11 11:19:40 -05:00
Dylan M. Taylor 1e17f43913 fix: grant author media listings by user token, not cached username (#286)
## What was wrong

`GET /v1/media_files/list/user/{username}` (and the v2 handler) decided
author access by comparing the path username with the username in the
cached session. Usernames can change and be reassigned while an old
session cache still holds the previous name, so the old owner of a
released username could list the new owner's private media.

## What changed

Both handlers resolve the path username to its user token
(`get_user_token_by_username`) and grant author access only when that
token equals the session's user token. The listing query is unchanged.

## Blast radius

Two handlers; one extra indexed lookup per request. Users listing their
own media and moderators are unaffected.

## Checks

- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web` (exit 0).
- Not run: endpoint tests (need a live MySQL).
2026-11-11 11:19:31 -05:00
Dylan M. Taylor 1bbf69e0f5 fix: refuse saved-scene overwrites when ownership can't be verified (#301)
## What was wrong

The legacy saved-scene upload (replace an existing scene's stored file)
checks ownership with `check_creator_tokens`. When neither the record
nor the request carried a user or visitor token, the result was
`InsufficientInformation`, which fell through as "allowed" (marked with
a TODO saying it should be a 401). An unauthenticated caller who knew
such a scene's token could replace its contents.

## What changed

`InsufficientInformation` now returns `NotAuthorizedVerbose("cannot
verify ownership of this scene")` before anything is uploaded. Matching
user or visitor tokens behave as before.

## Blast radius

Scenes created with no user and no visitor token can no longer be
overwritten in place by anyone; saving to a new scene still works. That
is the TODO's intended behavior.

## Checks

- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web` (exit 0).
- Not run: endpoint tests (need a live MySQL).
2026-11-11 11:19:22 -05:00
Dylan M. Taylor a392b59d7c fix: drop plaintext legacy origins from the production CORS policy (#305)
## What was wrong

The production CORS policy (credentialed) allowed nine plaintext
`http://` origins for the legacy `storyteller.stream` and
`create/obs/ws.storyteller.ai` hosts, with a TODO to remove them. A
network attacker who can rewrite one of those HTTP pages can make a
visitor's browser call the API with their cookies and read the
responses, including the MCP session tokens returned by
`create_mcp_session_handler`.

## What changed

`add_legacy_storyteller_stream` now allows only the HTTPS variants in
production. The rows for the removed origins are dropped from
`allowlist_regression_tests`, and a new test asserts that each removed
origin is rejected while `https://create.storyteller.ai` is still
allowed.

## Not changed

The `devproxy.fakeyou.com` / `devproxy.storyteller.ai` HTTP origins
(finding 7020bef5) are also allowed in production, but the regression
table pins them as intentional (`Both`), presumably for developers
proxying to the production API. Removing them is a product call, so it's
left out here.

## Checks

- Run: `cargo test -p actix_cors_configs` (79 passed).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Security**
* Storyteller production and staging origins, including legacy create,
OBS, and WebSocket hosts, no longer accept plaintext HTTP connections.
* HTTPS connections to the configured production origins remain
available.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:19:13 -05:00
Dylan M. Taylor 446980fa67 fix: invalidate pending password resets when the email changes (#258)
## What was wrong
A password reset is bound to the user's `password_version`, not to the
address it was emailed to. Redeeming it sets `email_confirmed = true` on
whatever address the account has *now*. Changing the email
(`update_email`) did not invalidate pending resets, so a user could
request a reset at a mailbox they control, change the account to an
address they don't own, then redeem the reset and have the unverified
address marked confirmed.

## What changed
`update_email` also bumps `password_version` in the same `UPDATE`.
`lookup_password_reset_request` already requires
`pw.current_password_version = u.password_version`, so every reset
issued before the change stops working. `password_version` is used only
for reset binding (checked with a grep), so this does not sign anyone
out.

`.sqlx` metadata for the changed query was written by hand (query text +
SHA-256 hash; the describe block has no columns and 4 parameters, same
as before). The old entry is removed. Please run `cargo sqlx prepare`
against a database to confirm.

## Blast radius
User and moderator email changes. Outstanding reset links stop working
after an email change; users request a new one, which goes to the new
address.

## Checks
- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web -p db-cleanup
--tests` (validates the offline metadata entry is found).
- Not run: `cargo sqlx prepare --check`, and reset/email flow tests
(need MySQL).

Addresses CodeRabbit security findings (CWE-640).
2026-11-11 11:19:06 -05:00
Dylan M. Taylor 2fa9ad41d3 fix: reject banned callers when setting user roles and creating comments (#242)
## What was wrong

Banning an account leaves its role and its live sessions in place.

- `POST` set-user-role
(`deprecated_endpoints/moderation/user_roles/set_user_role.rs`) only
checked `can_ban_users`. A banned staff account with a live session
could still change other accounts' roles, for example to hand its
privileges to an account that is not banned.
- `create_comment_handler` only checked that a session existed, so a
banned user could keep posting comments.

## What changed

- `set_user_role_handler` now uses `require_user_session`, which rejects
banned callers.
- `create_comment_handler` returns `NotAuthorized` when
`user_session.is_banned`.

## Blast radius

Only banned accounts are affected. They get 401 on these two routes.
Behaviour for everyone else is unchanged.

Addresses CodeRabbit security findings (CWE-863).

## Checks run

- `SQLX_OFFLINE=true cargo check -p storyteller-web`

## Checks not run

- Handler tests. They need a live MySQL. Separately, revoking sessions
on ban, as the finding also suggests, is not part of this change.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Comment submissions from signed-in users marked as banned are now
rejected before the comment is processed.
* Requests to change a user’s role now apply standard session
validation, including handling for callers marked as banned. This makes
access checks more consistent across comment creation and role changes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:18:58 -05:00
Dylan M. Taylor 0cae43fe39 fix: report logout failure when the session could not be revoked (#259)
## What was wrong
`delete_user_session` dropped the result of its `UPDATE user_sessions
SET deleted_at = ...`, and `logout_handler` ignored the helper's return
value anyway. If the update failed, logout still returned `success:
true` while the session stayed valid in the database, so a copied
session cookie kept working.

## What changed
- `delete_user_session` propagates the database error. An unknown or
already-revoked session is still not an error.
- `logout_handler` returns a 500 when revocation fails, instead of
reporting success.

## Blast radius
Only `POST /v1/logout`. On a database failure the client now sees an
error (and the cookie isn't cleared), so it can retry or tell the user
the session may still be active.

## Checks
- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web -p db-cleanup
--tests`. The query text is unchanged, so no `.sqlx` change.
- Not run: endpoint tests (need MySQL).

Addresses CodeRabbit security findings (CWE-613).
2026-11-11 11:18:50 -05:00
Dylan M. Taylor ce6281de6e fix: purge the session cache after revoking the session on logout (#299)
## What was wrong

`logout_handler` purged the Redis session cache *before* revoking the
session in MySQL. A request carrying the same cookie that arrived in
between re-read the still-valid session from MySQL and re-cached it, so
the session kept working after logout until the cache TTL ran out.

## What changed

The cache purge now runs after `delete_user_session`, so anything cached
afterwards reflects the revoked row. Nothing else changes.

## Notes

#259 changes the same few lines (it makes the revocation error fatal).
The two changes are compatible; whichever merges second needs a trivial
rebase.

## Checks

- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web` (exit 0).
- Not run: endpoint tests (need a live MySQL).
2026-11-11 11:18:43 -05:00
Dylan M. Taylor 7890fb6a86 fix: refuse Google sign-in for banned accounts (#298)
## What was wrong

Password login refuses banned accounts (`login_handler` checks
`is_banned`), but Google sign-in resolved the local account and created
a session without that check. A banned user with a linked (or
email-matched) Google identity could sign in again and use any endpoint
that doesn't re-check the ban.

## What changed

After resolving the local user and before
`create_user_session_with_transactor`, `google_sso_handler` looks the
account up with `lookup_user_for_moderation_by_token` and returns
`NotAuthorized` if it is banned. No session is created.

## Blast radius

One handler, one extra indexed lookup per Google sign-in. Non-banned
users are unaffected.

## Checks

- Run: `SQLX_OFFLINE=true cargo check -p storyteller-web` (exit 0).
- Not run: endpoint tests (need a live MySQL).
2026-11-11 11:18:35 -05:00