fix(bump/datahub): cap response body size (#65)#107
Merged
Conversation
#65) Wraps DataHub responses in io.LimitReader and inspects Content-Length before reading, returning an error instead of OOMing the process. Caps are tuned per endpoint and configurable via DataHubConfig. Closes F-007.
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
resp.Bodyreads inio.LimitReaderand inspectsContent-Lengthbefore reading the body, so a hostile or malfunctioning DataHub cannot exhaust process memory by streaming an unbounded response./block/<hash>(binary block metadata: 80-byte header + subtree-hash list + coinbase tx + coinbase BUMP) — default 1 GiB viabump.DefaultMaxBlockBytes. The endpoint serves block metadata only, so 1 GiB is two-plus orders of magnitude over a realistic Teranode payload while still bounding memory.bump_builder.datahub_max_block_bytes(BumpBuilderConfig.DataHubMaxBlockBytes); default applied via Viper. A value<= 0falls back tobump.DefaultMaxBlockBytesso a misconfigured zero never silently disables the protection.bump/datahub_test.go:Content-Length) is rejected with an error mentioningexceedsand the cap, and the error does not embed the response content;LimitReader(max+1)boundary);Content-Lengthis rejected before any body bytes are read;Closes #65
Test plan
go build ./...go vet ./...go test ./bump/... -racego test ./... -race(full suite)golangci-lint run ./bump/... ./config/... ./services/bump_builder/.../block/<hash>is generous; tighten if Teranode's realistic max-block-metadata payload is lower for your fleet).