mirror of
https://github.com/storytold/artcraft-services.git
synced 2026-11-22 02:10:59 +01:00
## 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 -->