security(#283): sniff artwork content type from bytes, remove serve-side ?contentType= reflection
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 5s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 8m33s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 10m40s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 5s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 8m33s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 10m40s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
S4 stored-XSS + S9 upload-size DoS from the #197 cold API review. The artwork path trusted client-supplied content types at both ends: upload validated only the declared multipart Content-Type (never decoded the bytes), and serving reflected a client `?contentType=` straight into the response Content-Type on unauthenticated GET sinks (/iptv/logos, /artwork/watermarks). Chain: upload <script> bytes as image/png -> GET ...?contentType=text/html serves them as HTML in-origin. nosniff (#279) does not help because the server explicitly declares text/html. - Upload: derive the content type from the bytes via SkiaSharp SKCodec (header-only, no decode -> no decompression-bomb path); reject non-images 422. New ErsatzTV.Core/Images/ImageContentTypes as the single allow-list source. Dropped the untrusted declared Content-Type from the UploadArtwork command. - Serve: removed the ?contentType= reflection structurally -- dropped ContentType from GetCachedImagePath and the [FromQuery] binding on GetImage/GetWatermark; the handler always sniffs the file, defaulting application/octet-stream. ArtworkContentTypeModel.UrlWithContentType is now the bare path; SPA previews no longer append the query. - Defense-in-depth: channel-logo / watermark {path, contentType} DTOs run through ArtworkContentTypeModel.Sanitized(), blanking non-allow-listed types on write. - S9: Kestrel MaxRequestBodySize from ETV_MAXIMUM_UPLOAD_MB rejects oversized bodies during read (controller file.Length check kept as friendly-error backstop). Both serve sinks are IgnoreApi, so no OpenAPI change. Tests: byte-sniff accept/ reject, Sanitized() allow-list, Location no longer carries ?contentType=. Docs: api-conventions §4a + decisions.md 2026-07-12. Refs #283 #197 #66 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -216,6 +216,22 @@ Do **not** reuse the Application-layer Mappers used by Blazor (e.g. `MediaCards`
|
||||
mappers) for new API DTOs — those still return the old Blazor-convention relative paths. Map from
|
||||
the domain/VM directly and root the path yourself, following the PR #181 pattern.
|
||||
|
||||
### 4a. Artwork content type is sniffed, never client-supplied (issue #283)
|
||||
|
||||
The uploaded-artwork surfaces (channel logo, watermark) must never trust a client-declared content
|
||||
type — doing so was a stored-XSS chain (upload `<script>` as `image/png`, serve it back as
|
||||
`text/html`). The contract:
|
||||
- **Upload**: `POST /api/artwork/uploads` derives the content type from the actual bytes via
|
||||
`ErsatzTV.Core/Images/ImageContentTypes.DetectContentType` (SkiaSharp header sniff — no full
|
||||
decode), rejecting non-images 422. That helper (`Accepted` set + `IsAccepted`) is the **single
|
||||
source of truth** for which image types are allowed — reuse it, don't re-list content types.
|
||||
- **Serve**: the image routes derive the served `Content-Type` from the stored file; there is **no**
|
||||
`?contentType=` query parameter. Never add one back — a client must not be able to choose the
|
||||
`Content-Type` of an unauthenticated response.
|
||||
- **Persisted `{path, contentType}` DTOs** (logo/watermark) run their content type through
|
||||
`ArtworkContentTypeModel.Sanitized()` before storage, blanking anything outside the allow-list.
|
||||
See `docs/decisions.md` 2026-07-12 (#283) for the fuller rationale.
|
||||
|
||||
## 5. OpenAPI regeneration — commit both generated artifacts
|
||||
|
||||
After any controller/DTO change:
|
||||
|
||||
Reference in New Issue
Block a user