Skip to content

Reject leaf certificates with root-path SPIFFE IDs in Verify - #405

Open
bcleenders wants to merge 2 commits into
spiffe:mainfrom
bcleenders:require-non-root-path-in-spiffe-id
Open

Reject leaf certificates with root-path SPIFFE IDs in Verify#405
bcleenders wants to merge 2 commits into
spiffe:mainfrom
bcleenders:require-non-root-path-in-spiffe-id

Conversation

@bcleenders

@bcleenders bcleenders commented Jul 23, 2026

Copy link
Copy Markdown

Verify (and by extension ParseAndVerify) accepted leaf certificates whose SPIFFE ID had no path component (e.g. spiffe://example.org). X509-SVID spec section 5.2 requires that the leaf SPIFFE ID has a non-root path:

The validator [...] MUST ensure that the SPIFFE ID has a non-root path component.

This check already existed in validateLeafCertificate, which is used by Parse/ParseRaw/Load, but Verify had its own inline leaf checks that were an incomplete copy. The duplication also meant Verify was missing the digitalSignature key usage requirement.

To avoid future inconsistencies between the two paths, this PR uses the same validateLeafCertificate function as the Parse path uses.

Related: #375

Spec reference: https://github.com/spiffe/spiffe/blob/main/standards/X509-SVID.md#52-leaf-validation

@bcleenders
bcleenders force-pushed the require-non-root-path-in-spiffe-id branch 2 times, most recently from e3a3aff to 173d1d4 Compare July 23, 2026 11:17
[X509-SVID 5.2 Leaf Validation](https://github.com/spiffe/spiffe/blob/main/standards/X509-SVID.md#52-leaf-validation) requires certificates to have a non-root path component:

> The validator [...] MUST ensure that the SPIFFE ID has a non-root path component.

This test demonstrates that currently the Validator does not check this.
I'll send a second commit that fixes this, but sending this as first
commit to demonstrate the failure.

Signed-off-by: bcleenders <bcleenders@spotify.com>
@bcleenders
bcleenders force-pushed the require-non-root-path-in-spiffe-id branch from 173d1d4 to ae204ce Compare July 23, 2026 11:26
@bcleenders

bcleenders commented Jul 23, 2026

Copy link
Copy Markdown
Author

I don't see test failures in CI, but locally I get:

$ go test ./...
[...]
--- FAIL: TestVerify (0.00s)
    --- FAIL: TestVerify/bad_leaf_no_non-root_path_SPIFFE_ID (0.00s)
        verify_test.go:141:
            	Error Trace:	/Users/bcleenders/src/github/spiffe/go-spiffe/svid/x509svid/verify_test.go:141
            	Error:      	An error is expected but got nil.
            	Test:       	TestVerify/bad_leaf_no_non-root_path_SPIFFE_ID
FAIL
FAIL	github.com/spiffe/go-spiffe/v2/svid/x509svid	0.553s

Verify had its own inline leaf validation that was an incomplete copy of validateLeafCertificate.

Replacing it with a call to the shared function so both `Parse` and `Verify` enforce the same checks, including the non-root path requirement from X509-SVID 5.2.

Signed-off-by: bcleenders <bcleenders@spotify.com>
@bcleenders
bcleenders marked this pull request as ready for review July 23, 2026 11:33
chain: leaf1NoURI,
bundle: bundle1,
err: "x509svid: could not get leaf SPIFFE ID: certificate contains no URI SAN",
err: "x509svid: cannot get leaf certificate SPIFFE ID: certificate contains no URI SAN",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updating the error messages, to align with validateLeafCertificate.

@bcleenders

Copy link
Copy Markdown
Author

@amartinezfayo could you take a look?

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.

1 participant