fix(winbindex): verify the SHA-1 before sending, never serve wrong bytes - #75
Merged
Merged
Conversation
The symbol-server body was streamed to the client while its SHA-1 was computed, and compared only at the end. By then every byte (and the Content-Length) had been sent, so destroying the response could not fail the download: the client received a complete file with the wrong content and HTTP 200. Win11 21H2 notepad.exe and regedit.exe hit this on the public quickstart stack. Buffer the file (capped at WINBINDEX_MAX_PE_BYTES, 256 MiB), verify it, and only then send it with an exact Content-Length. Every failure (non-2xx, stream error, timeout, oversized body, SHA-1 mismatch) now leaves the response untouched and falls back to MinIO, so the failed_after_send outcome and the drain/backpressure code are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
GET /blob/:hash?filename=<pe>streamed the symbol-server body to the client while hashing it, and compared the SHA-1 only once the stream ended. By then every byte, and the upstreamContent-Length, had already gone out, sores.destroy()could not turn the download into a failure. The client received a complete file with the wrong content and HTTP 200.Reproduced on a fresh quickstart stack with the public corpus:
The API logged
SHA-1 mismatch … destroying response, butcurland the browser saved the wrong binary with no error.Fix
Buffer, verify, then send:
WINBINDEX_MAX_PE_BYTES(256 MiB, upstream cancelled past it).Content-Length. That also removes the content-encoding special case.not_availablewith the response untouched, so the route falls back to MinIO.failed_after_send,waitForDrainand the backpressure loop are removed, since no outcome can fail after sending any more.Trade-off: each in-flight download holds one PE file in memory (a few MB to a few tens of MB) instead of streaming it. The reason is documented in
docs/reference/winbindex-source.md.Verification
Content-Lengthis the verified size, and there's a new size-cap test that also checks the upstream is cancelled.tests/winbindex.test.ts: 37/37 pass. Full suite: 89/89 tests pass.tests/git-log/index.test.tsstill fails to compile (ts-jest top-levelawait), same as onmaster.npm run format-checkandnpm run buildpass.Not in this PR
On the quickstart stack the MinIO fallback answers
502 Storage Error(NoSuchBucket), because the public corpus ships no blobs. A404 Blob not availablewould be a clearer answer. That's pre-existing MinIO-path behavior, left for a separate change.🤖 Generated with Claude Code