Skip to content

Harden outer COSE_Sign1 decode with the same CBOR limits as the payload#12

Open
prasanna-anchorage wants to merge 2 commits into
mainfrom
fix/harden-outer-cose-decode
Open

Harden outer COSE_Sign1 decode with the same CBOR limits as the payload#12
prasanna-anchorage wants to merge 2 commits into
mainfrom
fix/harden-outer-cose-decode

Conversation

@prasanna-anchorage

Copy link
Copy Markdown
Contributor

Summary

  • verifier.go decoded the outer COSE_Sign1 envelope with a bare cbor.Unmarshal, relying on fxamacker/cbor's much looser defaults (131,072 max array elements/map pairs) even though parser.go already applied tighter limits (32 nested levels, 128 max array elements/map pairs) to the inner attestation document payload.
  • Both decode paths now share a single hardenedDecMode in parser.go, so no CBOR decode entry point in the package is left relying on the un-configured defaults.
  • Added TestOuterCOSEDecodeHardening in verifier_test.go, which smuggles an oversized array into the outer envelope's unprotected-headers slot (200 elements — over our 128 limit, but well under fxamacker's 131,072 default) and confirms it's now rejected at the outer decode, with an error distinguishable from the inner-document decode path.

Test plan

  • go build ./...
  • go vet ./...
  • go test ./... — 123 passed (122 existing + 1 new)
  • Pre-commit hooks (dependency check, lint, tests) passed on commit

verifier.go decoded the outer COSE_Sign1 envelope with a bare
cbor.Unmarshal, relying on fxamacker/cbor's much looser defaults
(131,072 max array elements/map pairs) even though parser.go already
applied tighter limits (32 nested levels, 128 max array elements/map
pairs) to the inner attestation document. Both now share a single
hardenedDecMode so no decode entry point is left on the looser
defaults.
Copilot AI review requested due to automatic review settings July 14, 2026 01:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens decoding of attacker-controlled CBOR by applying the same strict fxamacker/cbor resource limits to the outer COSE_Sign1 envelope as already used for the inner attestation document payload, preventing the outer wrapper from relying on permissive library defaults.

Changes:

  • Replaced outer COSE_Sign1 cbor.Unmarshal calls in verifier.go with the shared hardenedDecMode.Unmarshal.
  • Centralized CBOR decode limits into a single hardenedDecMode in parser.go and reused it for inner document decoding.
  • Added a regression test ensuring oversized outer-envelope structures are rejected early.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
verifier.go Uses the shared hardened CBOR decode mode when parsing the outer COSE_Sign1 envelope.
verifier_test.go Adds a test that validates the outer COSE decode now enforces the hardened CBOR limits.
parser.go Introduces a shared hardened CBOR DecMode and reuses it for inner document decoding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread parser.go
Comment thread verifier_test.go Outdated
- Reword the DecMode panic comment: it fires at package init (runtime),
  not build time.
- Fix "un-configured" -> "unconfigured" hyphenation in the new test's
  comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

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.

2 participants