Repository navigation
fix(tlock): bound Quicknet beacon response size - #694
Open
Hamda-gbade wants to merge 1 commit into
Open
Hamda-gbade wants to merge 1 commit into
Hamda-gbade wants to merge 1 commit into
Conversation
|
@Hamda-gbade Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Quicknet responses were parsed without a byte limit because drand-client reads response bodies in full before JSON parsing. Route chain-info and beacon requests through a streaming 64 KiB cap so an oversized response is aborted before parsing, while keeping the existing response validation and cryptographic checks unchanged. Adds offline boundary tests with an injected fake fetch for exactly-at-limit, one-byte-over, declared Content-Length, and chunked bodies. Closes Sub-Rosa-Issue#664 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
Author
|
CI note for reviewers: the failing checks also fail on
This PR only touches pnpm --filter @sub-rosa/tlock test:quicknet # 18/18 passThe unrelated failures include the pre-existing |
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.
Summary
Timelock sealing fetched Quicknet chain-info and beacon responses through
drand-client, which reads the whole response body and callsJSON.parsewithout any size ceiling. The beacon endpoint is public, so a proxy or replica could return an arbitrarily large body and force the sealer, keeper, or web app to buffer it in memory.This PR routes every Quicknet HTTP request through a bounded JSON fetch:
MAX_DRAND_RESPONSE_BYTES= 64 KiB (packages/tlock/src/http.ts), exported from@sub-rosa/tlockand noted indocs/LIMITATIONS.md. A normal quicknet beacon is a few hundred bytes, so 64 KiB is a generous cap.Content-Lengthis checked before reading when present; otherwise the body is read as a stream and cancelled as soon as the accumulated byte count exceeds the limit.JSON.parseonly runs after the full body fits.assertChainInfo/assertBeacon), round binding, BLS signature verification, and non-2xx failure behavior are unchanged. No timeout was removed or shortened.quicknet(fetchImpl = fetch)keeps the same public API while allowing offline boundary tests. The returned client implements drand-client'sChainClientinterface (chain(),get(),latest(),options), sofetchBeacon/ tlock-js continue to work.Files changed
packages/tlock/src/http.tsfetchDrandJson,MAX_DRAND_RESPONSE_BYTES,DrandResponseTooLargeError,FetchLikepackages/tlock/src/quicknet.tsDrandClientaliases drand-client'sChainClientpackages/tlock/src/index.tspackages/tlock/src/http.test.tspackages/tlock/package.jsontest,test:unit, andtest:quicknetdocs/LIMITATIONS.mdBoundary tests
All tests use a fake
fetch; no network access:MAX_DRAND_RESPONSE_BYTESis accepted and parsed.DrandResponseTooLargeError.Content-Lengthis rejected before a body is read.quicknet(fakeFetch)applies the same cap to chain-info./<chain-hash>/public/<round>.Verification
pnpm --filter @sub-rosa/tlock testand the workspace typechecks also exercise unrelated files that are already failing onupstream/main(for examplepackages/tlock/src/seal.tsreferences an unimportedassertSealRoundWindow). The new tests pass in isolation; those pre-existing failures are outside this change.Supply-chain review
.vscode/, workflow, or other editor/config file changes.preinstall/postinstall) added.Closes #664