Limit CBOR depth#7838
Merged
maxtropets merged 2 commits intomicrosoft:mainfrom Apr 27, 2026
Merged
Conversation
achamayou
approved these changes
Apr 27, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a configurable nesting-depth limit to the internal CBOR parser/serializer to prevent stack overflow from adversarially (or accidentally) deeply-nested CBOR, with coverage in the CBOR unit tests.
Changes:
- Add
max_depthparameter (default16) toccf::cbor::parseandccf::cbor::serialize. - Enforce depth checks during CBOR decode (
consume*) and encode (to_raw_*) recursion, throwing on exceed. - Add unit tests validating parse/serialize behavior at and beyond configured depth limits.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/crypto/cbor.h |
Extends CBOR parse/serialize API with a max_depth parameter (default 16). |
src/crypto/cbor.cpp |
Implements max-depth enforcement in recursive decode/encode helpers. |
src/crypto/test/cbor.cpp |
Adds tests for max-depth behavior in parsing and serialization. |
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.
Parsing CBOR of undefined depth or roughly 10k+ can overflow. This PRs adds a safety barrier to only parse reasonably deep CBORs, while still allows to go deeper with a newly added function parameter.