Skip to content

bound io.ReadAll on untrusted HTTP response bodies#2208

Open
1seal wants to merge 1 commit intogoogle:mainfrom
1seal:bound-readall-untrusted-responses
Open

bound io.ReadAll on untrusted HTTP response bodies#2208
1seal wants to merge 1 commit intogoogle:mainfrom
1seal:bound-readall-untrusted-responses

Conversation

@1seal
Copy link

@1seal 1seal commented Feb 12, 2026

Summary

  • adds internal/limitio package with a bounded ReadAll that enforces a maximum size and returns a clear error on truncation (read limit+1 to detect overflow)
  • replaces all io.ReadAll calls on untrusted registry/auth HTTP response bodies with limitio.ReadAll using per-callsite constants
  • bounded callsites: CheckError (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 cleanly

fixes #2204

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
@1seal
Copy link
Author

1seal commented Feb 12, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

multiple unbounded io.ReadAll reads allow registry-controlled memory exhaustion (dos)

1 participant