Skip to content

Filter gzipped gem compact indexes under cooldown - #584

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/gem-index-gzip
Oct 24, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/gem-index-gzip

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

With cooldown on, the gem handler fetches /info/{name} from upstream and drops the lines of versions still in cooldown. The fetch passed on the client's Accept-Encoding, and setting that header turns off Go's transparent decompression, so for any client that accepts gzip (Bundler does by default) the filter scanned gzip bytes, matched nothing, and sent the compressed index on with upstream's Content-Encoding. Cooldown filtered nothing for Bundler.

  • The upstream fetch passes on only Accept, so the transport decompresses the index before it is filtered. The client's If-None-Match/If-Modified-Since are no longer sent upstream either, since they belong to the filtered copy.
  • The filtered index drops upstream's ETag, Last-Modified, Digest, Repr-Digest and range headers, which describe the unfiltered file. Bundler checks the digest against the body it receives.
  • The index is read through ReadMetadata before anything is written. bufio.Scanner stopped at a line over 64 KB and the handler sent what it had as a complete 200; a read error or an index over the metadata size limit now gets a 502.

The other handlers that pass Accept-Encoding upstream (npm search/keys/audit, NuGet, Conda, CRAN, gem API passthrough) relay the body unchanged, and Conda's repodata filter already decompresses itself, so they're left as they are.

Tests: TestGemCompactIndexCooldownClientAcceptsGzip, TestGemCompactIndexCooldownLongLine, TestGemCompactIndexCooldownOversizedIndex.

With cooldown on, /info/{name} is fetched from upstream and versions still in cooldown are removed line by line. The fetch passed on the client's Accept-Encoding, and setting that header turns off the transport's transparent decompression, so for any client that accepts gzip, Bundler included, the filter scanned gzip bytes, matched no versions and sent the compressed index on with upstream's Content-Encoding. Cooldown filtered nothing for those clients.

The fetch now passes on only Accept, so the transport decompresses the index before it is filtered. If-None-Match and If-Modified-Since are no longer passed on either: the client's validators came from a filtered copy, not from upstream's file.

The filtered index no longer carries upstream's ETag, Last-Modified, Digest, Repr-Digest or range headers, which describe the unfiltered file; Bundler checks the digest against the body it gets.

The index is now read through ReadMetadata before anything is written. bufio.Scanner stopped at a line over 64 KB and the handler sent what it had so far as a complete 200; a read error or an index over the metadata size limit now answers 502.
@andrew
andrew merged commit 319253a into git-pkgs:main Oct 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants