Files
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
..