Verify content digest on the batch CAS download path#656
Open
evilgensec wants to merge 2 commits into
Open
Conversation
BatchDownloadBlobsWithStats stored each returned blob keyed by the server-asserted digest without re-hashing the returned bytes, so a CAS that returns data not matching the requested digest would be accepted and written to disk by the download paths. The streamed path (readBlobStreamed) already verifies the calculated digest against the expected one; this makes the batch path consistent by verifying the returned bytes hash to the requested digest before storing them. Adds a regression test.
BatchDownloadBlobs now verifies that returned bytes hash to the requested digest, so TestBatchReadBlobsIndividualRequestRetries failed: it served blobs under fabricated digest.TestNew digests that never matched their data, which the new check correctly rejects. Give the two data-returning blobs real content-hash digests, make the per-request digest comparison order-independent (the content-hash digests no longer sort in the fabricated a,b,c,d order), and fail fast on a request-count mismatch instead of panicking. Write-path tests are unaffected.
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.
What
BatchDownloadBlobsWithStatsstores each blob returned byBatchReadBlobskeyed by the digest the server asserts in the response, without re-hashing the returned bytes:There is no length check and no
NewFromBlob(r.Data) == requestedcheck, so a CAS that returns bytes which do not match the requested digest — a buggy or compromised server, a caching/forwarding proxy, or an on-path party on a non-TLS connection — is taken at face value, and the bytes are later written to disk bydownloadBatch/downloadNonUnified.The streamed path already guards against this:
readBlobStreamedtees the stream throughdigest.NewFromReaderand returnscalculated digest %s != expected digest %son mismatch. BecauseuseBatchOpsdefaults to true andmakeBatchesgroups every sub-MaxBatchSizeblob into a batch, the unverified batch path is the common route for most blobs.Change
Verify the returned (post-decompression) bytes hash to the requested digest before storing them, mirroring the streamed path, and key the result by the verified digest. Adds
TestBatchDownloadBlobsDigestMismatch.