Skip to content

Reject '..' path segments in Vault Issuer path fields - #8930

Merged
cert-manager-prow[bot] merged 1 commit into
cert-manager:masterfrom
wallrj-cyberark:vault-path-hardening
Jun 24, 2026
Merged

cert-manager-prow[bot] merged 1 commit into
cert-manager:masterfrom
wallrj-cyberark:vault-path-hardening

Conversation

@wallrj-cyberark

@wallrj-cyberark wallrj-cyberark commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Reject .. sequences in spec.vault.path and in the Vault auth
    mount path fields (appRole.path, kubernetes.path,
    clientCertificate.path, aws.mountPath) during webhook
    validation.
  • Replace filepath.Join with path.Join in the clientCertificate
    and kubernetes auth code paths.

Motivation

Go's path.Join resolves .. segments client-side before
constructing the HTTP request to Vault, which can silently produce a
different URL than the user intended. For the auth mount path fields,
.. can also escape the hard-coded auth/ prefix in the URL
construction.

filepath.Join is OS-dependent and not appropriate for URL path
construction; path.Join is already used in the AppRole and Sign code
paths.

Thanks to @jiayuqi7813 and @kodareef5 for reporting this.

Why only ..?

We considered whether other dangerous characters (%-encoded
traversal, null bytes, backslashes, newlines, query/fragment
delimiters) need sanitising and concluded that .. is the only
meaningful vector for these fields. The remaining characters are
already handled by layers below the webhook:

Character class Why it's safe Reference
Percent-encoded traversal (%2e%2e, %2f) The Vault Go client sets the path via url.URL.Path (the decoded field). Go's URL.String() re-encodes via EscapedPath(), so a literal %2e in Path becomes %252e on the wire — Vault sees the literal string, not ... pkg.go.dev/net/url#URL: "the Path field is stored in decoded form: /%47%6f%2f becomes /Go/"
Null bytes and control characters (\x00–\x1f, \x7f) Go's net/url.Parse rejects all ASCII control characters at parse time. Even if a control character reached the Vault client's URL construction, the HTTP request would fail. Go 1.12 release notes (net/url section); golang/go#27302; commit 829c5df58694
Backslashes (\) path.Join is POSIX-only and treats \ as an ordinary character, not a separator. (We removed the two filepath.Join calls that were OS-dependent in this PR.) pkg.go.dev/path: "This package does not deal with Windows paths with drive letters or backslashes"
Query / fragment injection (?, #) The Vault Go client constructs url.URL with the path in the .Path field and serialises via RequestURI(), which percent-encodes these characters. They are never interpreted as delimiters. hashicorp/vault api/client.go NewRequest, api/request.go toRetryableHTTP
Newlines (\r\n) Covered by the control-character rejection above (Go 1.12+). See above

Test plan

  • New validation test cases in TestValidateVaultIssuerConfig and
    TestValidateVaultIssuerAuth for .. rejection in all path fields
  • go test ./internal/apis/certmanager/validation/... passes
  • go build ./internal/vault/... confirms clean compilation after
    removing the path/filepath import
Vault Issuer webhook validation now rejects `..` path segments in `spec.vault.path` and auth mount path fields, preventing `path.Join` from silently resolving relative segments before constructing the Vault API request.

@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. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 23, 2026
@wallrj-cyberark
wallrj-cyberark requested a review from Copilot June 23, 2026 05:35

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 Vault Issuer configuration by preventing path traversal-like inputs (..) in Vault path fields during webhook validation, and standardizes URL path construction by using path.Join instead of OS-dependent filepath.Join in Vault auth login requests.

Changes:

  • Add webhook validation to reject .. in spec.vault.path and Vault auth mount path fields.
  • Replace filepath.Join with path.Join for client certificate and Kubernetes auth login URL construction.
  • Add new validation test cases covering .. rejection for all affected path fields.

Reviewed changes

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

File Description
internal/vault/vault.go Switch URL path joining to path.Join for Vault client-certificate and Kubernetes auth login endpoints.
internal/apis/certmanager/validation/issuer.go Add webhook validation rejecting .. in Vault Issuer path fields.
internal/apis/certmanager/validation/issuer_test.go Add unit tests asserting .. is rejected in all relevant Vault path fields.

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

Reject '..' sequences in spec.vault.path and in the auth mount path
fields (appRole.path, kubernetes.path, clientCertificate.path,
aws.mountPath) during webhook validation.

Go's path.Join resolves '..' segments client-side before constructing
the HTTP request to Vault, which can silently produce a different URL
than the user intended. For the auth mount path fields, '..' can also
escape the hard-coded 'auth/' prefix in the URL construction.

Also replace filepath.Join with path.Join in the clientCertificate and
kubernetes auth code paths. filepath.Join is OS-dependent and not
appropriate for URL path construction.

Reported-by: jiayuqi7813
Reported-by: kodareef5

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Richard Wall <[email protected]>
@wallrj-cyberark

Copy link
Copy Markdown
Member Author

/kind bug