Fix trailing data handling with CertificateRevocationListBuilder.LoadPem.#122825
Merged
stephentoub merged 3 commits intodotnet:mainfrom Jan 3, 2026
Merged
Fix trailing data handling with CertificateRevocationListBuilder.LoadPem.#122825stephentoub merged 3 commits intodotnet:mainfrom
stephentoub merged 3 commits intodotnet:mainfrom
Conversation
…Pem. CRLBuilder.LoadPem asserted that the DER data read is the same amount as the decoded length of the data, however the DER reader does not enforce no trailing data, so this assert could be reached. This change blocks trailing data in the PEM, and changes the assert to an actual exception.
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones |
vcsjones
commented
Jan 2, 2026
...y/src/System/Security/Cryptography/X509Certificates/CertificateRevocationListBuilder.Load.cs
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a security vulnerability in CertificateRevocationListBuilder.LoadPem where trailing data in PEM-encoded CRLs was not properly validated. The fix converts a Debug.Assert into a proper exception and adds test coverage for the scenario.
- Replaces
Debug.Assertwith proper validation that throwsCryptographicExceptionwhen trailing data is detected - Adds comprehensive test coverage for both string and ReadOnlySpan overloads of LoadPem with trailing data
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| CertificateRevocationListBuilder.Load.cs | Replaces Debug.Assert with proper exception throwing when bytesConsumed != bytesWritten |
| CrlBuilderTests.cs | Adds new test case LoadPem_TrailingData to verify trailing data is properly rejected |
bartonjs
approved these changes
Jan 2, 2026
This was referenced Jan 3, 2026
stephentoub
approved these changes
Jan 3, 2026
Member
|
/ba-g deadletter |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
CRLBuilder.LoadPem asserted that the DER data read is the same amount as the decoded length of the data, however the DER reader does not enforce no trailing data, so this assert could be reached.
This change blocks trailing data in the PEM, and changes the assert to an actual exception.
Fixes #122823