bound io.ReadAll on untrusted HTTP response bodies#2208
Open
1seal wants to merge 1 commit intogoogle:mainfrom
Open
bound io.ReadAll on untrusted HTTP response bodies#22081seal wants to merge 1 commit intogoogle:mainfrom
1seal wants to merge 1 commit intogoogle:mainfrom
Conversation
replace unbounded io.ReadAll calls on registry/auth/token HTTP responses with limitio.ReadAll that enforces per-callsite size limits and returns a clear error on truncation. callsites bounded: - transport.CheckError (error bodies): 4 MiB - transport.retryError (error bodies): 4 MiB - bearer.refreshOauth (token responses): 4 MiB - bearer.refreshBasic (token responses): 4 MiB - remote.fetchReferrers (referrers index): 4 MiB - remote.RawConfigFile (config blobs): 8 MiB fixes google#2204
Author
|
hi @Subserial — this bounds io.ReadAll on untrusted HTTP response bodies to prevent memory exhaustion from a malicious registry. low-risk, no behavior change for normal responses. let me know if anything needs adjusting. |
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
internal/limitiopackage with a boundedReadAllthat enforces a maximum size and returns a clear error on truncation (read limit+1 to detect overflow)io.ReadAllcalls on untrusted registry/auth HTTP response bodies withlimitio.ReadAllusing per-callsite constantsCheckError(4 MiB),retryError(4 MiB),refreshOauth(4 MiB),refreshBasic(4 MiB),fetchReferrers(4 MiB),RawConfigFile(8 MiB)Test plan
go test ./internal/limitio/passes (new unit tests for within-limit, at-limit, over-limit, empty, negative-max)go test ./pkg/v1/remote/transport/passes (all existing transport tests)go test ./pkg/v1/remote/ -run 'TestReferrers|TestImage|TestConfig'passes (all existing remote tests for affected functions)go build ./...compiles cleanlyfixes #2204