Skip to content

[Identity] Reject semantically duplicate attestation object keys - #69461

Open
javiercn wants to merge 2 commits into
mainfrom
javiercn/reject-semantic-cbor-keys
Open

javiercn wants to merge 2 commits into
mainfrom
javiercn/reject-semantic-cbor-keys

Conversation

@javiercn

@javiercn javiercn commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Fixes #69343

Overview

Reject top-level WebAuthn attestation-object map keys that decode to the same text string even when their CBOR bytes differ. The central compatibility constraint is that valid non-preferred CBOR remains accepted rather than imposing canonical serialization.

CborReader in strict mode compares map keys by encoded bytes, so preferred, non-preferred definite-length, and chunked indefinite-length representations of authData can coexist even though they decode to the same protocol key. The parser previously allowed the later decoded value to replace the earlier one while the configured verifier received the original encoded object.

Design

There are no public API, signature, default, convention, or configuration changes.

AttestationObject.ParseCore now compares decoded top-level keys with StringComparer.Ordinal. This is intentionally narrower than requiring canonical CBOR and adds the application-level equivalence required by the WebAuthn data model. Detection stays at the top-level parser; nested attStmt maps remain opaque and owned by their format-specific verifiers.

flowchart LR
    A[CBOR attestation object] --> B[CborReader strict encoded-key checks]
    B --> C[Decode top-level text key]
    C --> D{Ordinal decoded key seen?}
    D -- Yes --> E[Reject before reading duplicate value]
    D -- No --> F[Read or skip value]
    F --> G[Parse authenticator data]
    G --> H[Invoke attestation verifier]
Loading

Implementation

// src/Identity/Core/src/Passkeys/AttestationObject.cs
var reader = new CborReader(data);
_ = reader.ReadStartMap();

var keys = new HashSet<string>(StringComparer.Ordinal);

while (reader.PeekState() != CborReaderState.EndMap)
{
    var key = reader.ReadTextString();
    if (!keys.Add(key))
    {
        // For example, 68 "authData", 78 08 "authData", and
        // 7F 64 "auth" 64 "Data" FF all produce the same string.
        throw PasskeyException.DuplicateAttestationObjectKey(key);
    }

    // Existing key-specific reads and unknown-key skipping continue unchanged.
}

The duplicate is rejected immediately after reading its key and before consuming its value, so it cannot replace the selected value and VerifyAttestationStatement is not invoked. Raw byte-identical duplicates remain rejected by strict CborReader through the existing invalid-format path; byte-distinct semantic duplicates receive the specific duplicate-key failure.

Outcome

Input class Result Contract proved
Byte-identical duplicate Rejected as invalid format Existing strict-reader behavior is preserved
Preferred + non-preferred definite-length duplicate Rejected before verifier Decoded-string semantic uniqueness
Preferred + chunked indefinite-length duplicate Rejected before verifier Equivalent chunked text is not a bypass
One unique non-preferred key Accepted Canonical CBOR is not required

Red/green verification removed decoded-key tracking and observed semantic-duplicate registration succeed and reach verification, then restored the implementation and observed all targeted cases pass.

Validation

  • PasskeyHandlerAttestationTest: 118 passed.
  • Microsoft.AspNetCore.Identity.Test: 573 passed, 1 pre-existing skip.
  • Existing PR CI before the final test-only coverage commit passed across Linux, Windows, macOS, source build, code check, local-development validation, Helix subsets, quarantined tests, lint, CLA, Build Analysis, and Build Insights.

@github-actions github-actions Bot added the area-identity Includes: Identity and providers label Sep 23, 2026
@javiercn

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
3 pipeline(s) were filtered out due to trigger conditions.

@javiercn

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
3 pipeline(s) were filtered out due to trigger conditions.

@javiercn
javiercn marked this pull request as ready for review September 24, 2026 16:46
Copilot AI lite review requested due to automatic review settings September 24, 2026 16:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Adds semantic duplicate-key rejection for WebAuthn attestation objects while preserving valid non-preferred CBOR encodings.

Changes:

  • Tracks decoded top-level keys using ordinal comparison.
  • Adds a dedicated duplicate-key exception.
  • Adds coverage for duplicate and non-preferred encodings.
File Description
src/​Identity/​test/​Identity.Test/​Passkeys/​PasskeyHandlerAttestationTest.cs Tests duplicate rejection and compatible encodings.
src/​Identity/​Core/​src/​Passkeys/​AttestationObject.cs Rejects duplicate decoded keys.
src/​Identity/​Core/​src/​PasskeyExceptionExtensions.cs Defines the duplicate-key error.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Oct 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-identity Includes: Identity and providers pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reject semantically duplicate CBOR keys in passkey attestation objects

2 participants