Fix the type of exception thrown when decoding bad headers#124411
Open
bartonjs wants to merge 1 commit intodotnet:mainfrom
Open
Fix the type of exception thrown when decoding bad headers#124411bartonjs wants to merge 1 commit intodotnet:mainfrom
bartonjs wants to merge 1 commit intodotnet:mainfrom
Conversation
CoseMessage's Decode routines say that any failure is a CryptographicException, but some of the validation failures leak out ArgumentException from the validation in CoseHeaderMap.
Contributor
|
Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where CoseMessage.DecodeSign1 and CoseMessage.DecodeMultiSign methods would leak ArgumentException from internal validation in CoseHeaderMap, breaking the documented contract that decode failures should throw CryptographicException. The fix wraps these exceptions and also adds support for indefinite-length CBOR arrays in critical headers validation.
Changes:
- Modified exception handling in
DecodeBucketto wrap validationArgumentExceptionintoCryptographicException - Refactored CBOR array/map parsing to support both definite and indefinite-length encoding
- Added comprehensive test coverage for critical header validation with both encoding styles
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/libraries/System.Security.Cryptography.Cose/src/System/Security/Cryptography/Cose/CoseMessage.cs |
Added exception wrapping in DecodeBucket and refactored to support indefinite-length CBOR collections |
src/libraries/System.Security.Cryptography.Cose/tests/CoseMessageTests.DecodeSign1.cs |
Added tests verifying CryptographicException is thrown for critical header validation errors |
src/libraries/System.Security.Cryptography.Cose/tests/CoseMessageTests.DecodeMultiSign.cs |
Added tests verifying CryptographicException is thrown for critical header validation errors in multi-sign messages |
src/libraries/System.Security.Cryptography.Cose/tests/CoseMessageTests.Sign.CustomHeaderMaps.cs |
Extended existing tests to cover both definite and indefinite-length critical header arrays |
This was referenced Feb 14, 2026
Open
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.
CoseMessage's Decode routines say that any failure is a CryptographicException, but some of the validation failures leak out ArgumentException from the validation in CoseHeaderMap.