Skip to content

Compress only routes that opt in, share one rate limiter and one guarded art fetcher - #558

Merged
KodeStar merged 7 commits into
mainfrom
burndown/srv-harden
Nov 22, 2026
Merged

KodeStar merged 7 commits into
mainfrom
burndown/srv-harden

Conversation

@KodeStar

Copy link
Copy Markdown
Owner

Security hardening from #270, #219 and #260.

Compression fails closed (#270). A route compresses only when it opts in at registration. Every JSON read that compressed on main still does, and that was checked live on all 123 GET routes: no encoding differences, apart from two intended ones. A read-along request with Range is now identity, as is a request carrying Upgrade. These never compress:

  • streams, covers, media and websocket upgrades;
  • credential routes (/auth/* responses, GET /auth/tokens, the calendar link);
  • Bridge routes.

HEAD sends the same headers as GET with no body.

One rate limiter, one art fetcher (#219).

  • internal/quota is the one token bucket for the API and podcast limits. Every budget and key is unchanged, including server#553's per-Bridge-token 2,000/s with a 20,000 burst (unproved tokens pay the address bucket first) and the 10-wrong-codes lockout (429, Retry-After 900).
  • Community covers and podcast artwork share one guarded fetcher (internal/media/remoteart.go, netguard.Transport). It refuses a non-public dial, including after redirects and DNS names that resolve to private addresses, and uses no proxy, with size and time caps. It now also refuses URLs carrying user info (main sent those credentials) and caps response headers at 64 KiB.

Cancelled scope reads (#260). A scope read the client cancelled no longer logs a warning: 1,404 warnings on main became 0 in a live run of 4,000 dropped reads. Real failures still log. Cancelled list reads that go through writeCatalogError still warn, as on main; that is a follow-up.

Verified live against main:

  • compression on all GET routes;
  • the lockout, a paired Bridge's 500-request burst after its address bucket was drained, and discovery's 429;
  • every art refusal (loopback, metadata IP, 10.x, nip.io names, user info, redirect to loopback, more than 64 KiB of headers), with real LibriVox and iTunes art still loading;
  • the player and console pages: 0 console errors, 0 CSP violations.

Gates green on both SQLite engines, and the wire goldens are untouched.

…ded art fetcher, and stop warning on a cancelled scope
Community covers and podcast discovery each built their own netguard-dialled transport, so a change to the dial guard or the no-proxy rule had to land twice. netguard.Transport now owns the guarded dialer, the nil proxy and the idle pool; discovery only adds HTTP/2. A cover URL is checked with the meta package's absoluteHTTP rule, and discovery's artwork fetch is bounded by its own per-fetch context again instead of a second, fixed client timeout.

Part of #219.
Scope reads, search and the upcoming reads each repeated the context.Canceled test that keeps a cancelled request out of the warning log. requestGaveUp is that rule in one place.

Part of #260.
CONVENTIONS still described the deleted compression deny list (compressExcluded), the old limiter and the podcast quota package, and code comments still named a compress middleware. They now describe compressJSON at registration, internal/quota and media.ArtFetcher. Two test rows that registered a plain handler like the new-route row, and so proved nothing about streams or upgrades, are gone.

Part of #270 and #219.
These four admin GETs were gzipped before compression became a per-route opt-in, and none returns a credential, but they were registered without compressJSON: a Logs page of up to 1000 entries or a large library export went out uncompressed. They opt in again, and TestCompressExclusions now checks GET and HEAD for every route that stays out.

Part of #270.
netguard.Transport left MaxResponseHeaderBytes at net/http's 10 MiB
default, so only the body was capped: a hostile cover, artwork or
directory host could make each fetch slot hold megabytes of headers
before the body cap applied. Both guarded transports now read at most
netguard.MaxHeaderBytes (64 KiB).

Part of #219.
CONVENTIONS said every compressJSON route sits inside requireAuth or
requireAdmin and that every JSON answer on an opted-in route carries
Vary; the public GET /server is wrapped bare, and a Range or Upgrade
request gets neither gzip nor Vary. The read-along doc still said any
gzip client gets the gzipped map, and discovery's comment named
fetchImage where queuedImage sets the per-fetch budget.

Part of #270.
@KodeStar
KodeStar merged commit 4976c1a into main Nov 22, 2026
6 checks passed
@KodeStar
KodeStar deleted the burndown/srv-harden branch November 22, 2026 14:03
@KodeStar KodeStar moved this from Backlog to Done in AudioSilo Nov 22, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in AudioSilo Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant