Skip to content

fix(acme): bound ACME response body size to prevent unbounded-body DoS - #9010

Merged
cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
FelixPhipps:unbounded-body-dos
Jul 21, 2026
Merged

cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
FelixPhipps:unbounded-body-dos

Conversation

@FelixPhipps

@FelixPhipps FelixPhipps commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

Description

Problem

The ACME client talks to whichever server a tenant configures via Issuer.spec.acme.server. The client reads response bodies with no size limit: the vendored golang.org/x/crypto/acme fork buffers entire bodies into memory (io.ReadAll in responseError, json.NewDecoder on every success path, and on every 5xx retry) with no io.LimitReader.

A hostile or misconfigured ACME server can return an infinite or multi-gigabyte body that is fully buffered on the controller heap, OOM-killing the singleton cert-manager controller and halting certificate issuance/renewal cluster-wide.

Solution

Fix it from the calling side rather than patching the vendored fork. Every ACME response already flows through cert-manager's instrumented Transport.RoundTrip, so wrap resp.Body there in a limitedReadCloser capped at 16 MiB — comfortably above the largest legitimate response.

Legitimate certs behave unchanged.

Test plan

  • TestInstrumentedRoundTripper_RejectsOversizedResponseBody — an oversized streamed body errors with errACMEResponseBodyTooLarge and the read stays bounded.
  • TestInstrumentedRoundTripper_AllowsResponseBodyWithinLimit — a within-limit body is delivered in full.
  • Both new tests pass under -race.
  • Existing pkg/acme tests pass unchanged.
  • go build ./..., go vet ./..., gofmt clean, and full golangci-lint reports 0 issues.
Cap ACME server response bodies at 16 MiB to guard against unbounded-body denial-of-service.

@cert-manager-prow cert-manager-prow Bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. area/acme Indicates a PR directly modifies the ACME Issuer code needs-kind Indicates a PR lacks a `kind/foo` label and requires one. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 10, 2026
@FelixPhipps
FelixPhipps force-pushed the unbounded-body-dos branch 2 times, most recently from ce217f0 to 4d95d80 Compare July 10, 2026 16:01
Comment thread pkg/acme/client/http.go Resolved
Comment thread pkg/acme/client/http.go Resolved
Comment thread .golangci.yaml Outdated
max-blank-identifiers: 4
exhaustive:
default-signifies-exhaustive: true
forbidigo:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that this is beyond the scope of the PR.. if we do want this it should be in a different PR

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, removed and split into seperate PR here.

cert-manager's ACME client contacts a tenant-controlled server
(Issuer.spec.acme.server), so its responses must be treated as untrusted.
Response bodies were read with no size limit: the vendored
golang.org/x/crypto/acme fork buffers whole bodies into memory (io.ReadAll
in responseError, json.Decode on every success path, and on each 5xx
retry). A hostile or misconfigured ACME server can stream an unbounded
body that is buffered onto the controller heap, OOM-killing the singleton
controller and halting certificate issuance cluster-wide (CWE-770).

Cap every ACME response body from the calling side, in cert-manager's
instrumented RoundTripper, rather than patching the vendored fork: wrap
resp.Body with io.LimitReader (16 MiB) so the ACME library cannot buffer
more than the cap. The limit sits above the largest legitimate response
(the certificate chain, ~5.4 MiB) and applies to every response,
including retries.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Felix Phipps <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens cert-manager’s ACME HTTP client against unbounded (potentially DoS) response bodies by adding a response body size cap at the instrumented Transport.RoundTrip layer, and adds tests to validate the behavior.

Changes:

  • Add a 16 MiB cap for all ACME HTTP response bodies by wrapping resp.Body with a limiting io.ReadCloser.
  • Add new tests around oversized vs within-limit response bodies.
  • Minor comment/doc updates associated with the new transport behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pkg/acme/client/http.go Wraps ACME HTTP response bodies with a size-limited reader in the instrumented transport.
pkg/acme/client/http_test.go Adds tests validating capped vs within-limit response body handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/acme/client/http.go Resolved
Comment thread pkg/acme/client/http_test.go Resolved
Comment thread pkg/acme/client/http.go Resolved
Comment thread pkg/acme/client/http_test.go Resolved
Replace the custom limitedReadCloser (backed by io.LimitReader) with the
standard library's http.MaxBytesReader. LimitReader silently truncated an
oversized body and returned io.EOF, making a hostile unbounded body
indistinguishable from a legitimately short one. http.MaxBytesReader
instead surfaces a distinct *http.MaxBytesError once the limit is
exceeded, while still bounding memory, and removes the need for a custom
ReadCloser type. It accepts a nil ResponseWriter since only the
client-side cap is required.

Update the oversized-body test to assert the *http.MaxBytesError and that
bytes read stay bounded by the limit, and fix two grammar nits in
doc comments.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Felix Phipps <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

pkg/acme/client/http_test.go:198

  • The PR description/test plan mentions a dedicated errACMEResponseBodyTooLarge, but this test (and the implementation) currently surfaces an oversized body as a *http.MaxBytesError. Please align the PR description/test plan with the actual error type (or, if a cert-manager-specific sentinel error is required, switch to a custom ReadCloser that returns it when the limit is exceeded).
	var maxBytesErr *http.MaxBytesError
	if !errors.As(err, &maxBytesErr) {
		t.Fatalf("expected a *http.MaxBytesError reading an oversized body, got %T: %v", err, err)
	}

@ThatsMrTalbot

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ThatsMrTalbot

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cert-manager-prow cert-manager-prow Bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 21, 2026
@ThatsMrTalbot

Copy link
Copy Markdown
Contributor

Needs a release note to merge

@cert-manager-prow cert-manager-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 21, 2026
@FelixPhipps

Copy link
Copy Markdown
Member Author

/kind bug

@cert-manager-prow cert-manager-prow Bot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 21, 2026
@cert-manager-prow cert-manager-prow Bot removed the needs-kind Indicates a PR lacks a `kind/foo` label and requires one. label Jul 21, 2026
@cert-manager-prow
cert-manager-prow Bot merged commit 70e1c91 into cert-manager:master Jul 21, 2026
6 checks passed
@wallrj wallrj mentioned this pull request Jul 29, 2026
13 tasks done
@wallrj

wallrj commented Aug 31, 2026

Copy link
Copy Markdown
Member

/cherry-pick release-1.21

@cert-manager-bot

Copy link
Copy Markdown
Contributor

@wallrj: new pull request created: #9222

Details

In response to this:

/cherry-pick release-1.21

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@wallrj

wallrj commented Sep 11, 2026

Copy link
Copy Markdown
Member

@FelixPhipps This change has been included in v1.21.2, which is now published.

If you are able to install the release and verify that the change works as expected in your environment, that would be much appreciated. Thank you for the contribution.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/acme Indicates a PR directly modifies the ACME Issuer code dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants