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

Open
#103 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
backend, security

Research direction

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.

Written by the indexing model from the issue text.

Description

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.
Dominant language
TypeScript
Stars
4
Forks
1
Avg merge
4h 49m
Merged PRs (30d)
5

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tinystream-dev/tinystream

All issues in tinystream-dev/tinystream

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.