Skip to content

fix: harden OCSP/CRL revocation checks against SSRF and DoS - #517

Merged
cert-manager-prow[bot] merged 2 commits into
cert-manager:mainfrom
FelixPhipps:inspect-secret-dos
Jul 7, 2026
Merged

cert-manager-prow[bot] merged 2 commits into
cert-manager:mainfrom
FelixPhipps:inspect-secret-dos

Conversation

@FelixPhipps

Copy link
Copy Markdown
Member

Description

Problem

The inspect secret command reads a kubernetes.io/tls Secret and, to report revocation status, makes network requests to the OCSP and CRL URLs listed inside the certificate. Those URLs are taken at face value — and a certificate can come from an untrusted source (e.g. a Secret created by a low-privilege tenant), so the URLs should be treated as potentially attacker-influenced. The current code contacts them with no safeguards:

  • DoS: both sinks used Timeout 0 - Meaning a tarpitting or infinite-streaming endpoint hangs or OOM-kills the process.
  • CRL allow-list bypass: the ldap/https gate is only checked on the first hop, but http.DefaultClient follows redirects without re-checking scheme (https:// → http:///).
  • OCSP SSRF: no scheme check at all.

Solution

Route all OCSP/CRL requests through a shared client with a 10s timeout and redirects disabled, cap responds with io.LimitReader (1 MiB), and restricts OCSP URLs to http(s). The misleading #nosec rationales are corrected. Legitimate certs behave unchanged.

Test plan

  • Test_checkCRLValidCert_doesNotFollowRedirects — a CRL endpoint that 307-redirects to a second server errors out, and the redirect target is never contacted.
  • Test_checkOCSPValidCert_rejectsNonHTTPScheme — an ftp:// OCSP URL is rejected before any network call.
  • Both new tests pass under -race.
  • Existing pkg/inspect/secret tests pass unchanged
  • go build ./..., go vet ./..., and gofmt clean.

The inspect secret command dereferences OCSP and CRL URLs taken verbatim
from the untrusted certificate under inspection. Use a shared HTTP client
with a request timeout and redirects disabled (closing the CRL scheme
allow-list bypass via redirect), cap response bodies with io.LimitReader,
and restrict OCSP URLs to http(s). Correct the misleading #nosec
rationales accordingly.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: felix.phipps <[email protected]>
@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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 2, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

Hi @FelixPhipps. Thanks for your PR.

I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@cert-manager-prow cert-manager-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 2, 2026
@SgtCoDFish

Copy link
Copy Markdown
Member

/ok-to-test

@cert-manager-prow cert-manager-prow Bot added ok-to-test and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 3, 2026
@wallrj-cyberark
wallrj-cyberark requested a review from Copilot July 6, 2026 05:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Hardens inspect secret certificate revocation checks by reducing SSRF/redirect exposure and bounding resource usage when contacting OCSP responders and CRL distribution points derived from untrusted certificates.

Changes:

  • Introduces a shared HTTP client for OCSP/CRL checks with a 10s timeout and redirects disabled.
  • Restricts OCSP URLs to http/https schemes before performing network requests.
  • Caps OCSP/CRL response reads to 1 MiB and adds targeted tests for redirect handling and scheme rejection.

Reviewed changes

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

File Description
pkg/inspect/secret/util.go Adds shared hardened HTTP client, scheme restriction for OCSP, and response/time bounds for OCSP/CRL fetching.
pkg/inspect/secret/util_test.go Adds tests to ensure CRL checks do not follow redirects and OCSP checks reject non-HTTP(S) schemes.

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

Comment thread pkg/inspect/secret/util.go Resolved
Comment thread pkg/inspect/secret/util.go Resolved
Comment thread pkg/inspect/secret/util.go Resolved
net/http cannot dereference ldap:// URLs, so listing "(ldap/https only)"
in the CRL request #nosec G704 rationale is misleading. Only http(s) is
actually fetched by revocationHTTPClient. Remove the scheme list to keep
the security rationale accurate.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: felix.phipps <[email protected]>

@wallrj-cyberark wallrj-cyberark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fix correctly addresses all four defects identified in the security audit (CWE-918 / CWE-400):

  1. DoS via zero timeout — shared revocationHTTPClient with Timeout: 10s
  2. OCSP SSRF (no scheme check) — scheme restricted to http/https before making the request
  3. CRL redirect bypass — CheckRedirect returns http.ErrUseLastResponse, preventing scheme downgrade via 307
  4. Unbounded io.ReadAll — io.LimitReader with 1 MiB cap on both OCSP and CRL paths

Verified locally:

  • Both new tests pass with -race (Test_checkCRLValidCert_doesNotFollowRedirects, Test_checkOCSPValidCert_rejectsNonHTTPScheme)
  • Full pkg/inspect/secret test suite passes
  • go vet clean
  • CI green (test, verify, integration, dco)

The Copilot suggestions around explicit LimitReader truncation detection are valid enhancements but not required for the security fix — the current behaviour (truncate then fail at ASN.1 parse) is safe. The #nosec ldap wording has been addressed in the second commit.

/label tide/merge-method-squash

@cert-manager-prow cert-manager-prow Bot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jul 7, 2026
@wallrj-cyberark
wallrj-cyberark requested a review from wallrj July 7, 2026 11:57
@wallrj

wallrj commented Jul 7, 2026

Copy link
Copy Markdown
Member

/approve
/lgtm

@cert-manager-prow cert-manager-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 7, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wallrj, wallrj-cyberark

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 7, 2026
@cert-manager-prow
cert-manager-prow Bot merged commit 8c0652c into cert-manager:main Jul 7, 2026
5 checks passed
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. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. lgtm Indicates that a PR is ready to be merged. ok-to-test size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants