fix: bound BasicConstraints ASN.1 parsing#41
Open
leanthebean wants to merge 1 commit into
Open
Conversation
leopoldjoy
reviewed
Jun 20, 2026
| require(ca == isCA, "isCA must be true for CA certs"); | ||
|
|
||
| if (certificate[basicConstraintsPtr.header()] == 0x02) { | ||
| maxPathLen = int64(uint64(certificate.uintAt(basicConstraintsPtr))); |
Contributor
There was a problem hiding this comment.
Reject zero-length pathLenConstraint before calling uintAt; otherwise an in-bounds 02 00 child still makes uintAt read ptr.content() outside the BasicConstraints SEQUENCE and can accept the malformed INTEGER as 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes CAT finding
7596fd8c-ca58-496f-81bc-c8e71c2ad57a.The BasicConstraints verifier previously called
firstChildOfon the decoded extension value unconditionally. For an empty BasicConstraints SEQUENCE (30 00), that made the ASN.1 walker parse the next byte outside the BasicConstraints container, and the escaped node could influence thecA/pathLenConstraintdecision.This change:
cA=falsewithout traversing children;pathLenConstraint;30 00, CA30 03 01 01 ff, and CA with pathLen30 06 01 01 ff 02 01 00.Security Impact
This removes the parser-bounds escape from the PKI trust gate. The existing coincidental mitigations still made the finding non-weaponizable against the current AWS Nitro profile, but the verifier no longer relies on adjacent extension ordering or outer signature-algorithm bytes for safety.
Tests
forge test --match-path test/CertManager.t.sol -vvvforge test