[Bug]: Book resources and video font attachments are served as active content (stored XSS)

Aperta
#103 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend, security

Direzione di ricerca

Start at the two named sinks, src/books/mod.rs:144 and src/api/media.rs:188, and read whatever helper guesses the MIME type from the zip or MKV attachment name. Then read the middleware stack in src/api/mod.rs to see where COOP/COEP is added, since that is where a global X-Content-Type-Options: nosniff belongs. Done means SVG/HTML/XHTML from books or fonts come back as application/octet-stream with Content-Disposition: attachment and a sandboxing CSP on those routes, verified by a test asserting the response headers on a crafted EPUB entry.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

[!NOTE]
This issue was written by Claude (Claude Opus 5.5) from a code review session with @PhrolovaMoe. It was found by reading the code and hasn't been reproduced on a running server.

Version

0.40.0 (feat/desktop, 017a837b)

Area

Other

What happened?

/api/books/{id}/files/{*name} serves files from inside an EPUB with a MIME type guessed from the name in the zip (src/books/mod.rs:144). /api/media/{id}/fonts/{index} does the same with MKV attachment file names (src/api/media.rs:188). An .svg, .xhtml or .html inside a downloaded book or torrented MKV is served as image/svg+xml / text/html on the app's own origin, where scripts can use the signed-in user's session. No response sets X-Content-Type-Options: nosniff or a CSP; the global middleware only adds COOP/COEP (src/api/mod.rs).

Steps to reproduce
  1. Put an EPUB with OEBPS/x.svg containing <svg xmlns="http://www.w3.org/2000/svg" onload="alert(document.domain)"/> in a books library.
  2. Open /api/books/<id>/files/OEBPS/x.svg while signed in.
Expected behavior

Files from books and media attachments never run script on the app's origin.

Suggested fix
  • Serve fonts with a font MIME type or application/octet-stream, never one guessed from an arbitrary name.
  • For book resources, allow only image/font/CSS types the reader needs, and send everything else as application/octet-stream with Content-Disposition: attachment.
  • Add X-Content-Type-Options: nosniff globally and Content-Security-Policy: sandbox (or default-src 'none') on these file routes.
Lingua principale
TypeScript
Stelle
4
Fork
1
Merge medio
4h 49m
PR unite (30g)
5

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tinystream-dev/tinystream

Tutte le issue di tinystream-dev/tinystream

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.