Skip to content

Validate COSE ALG+CRV combination when decoding passkey CredentialPublicKey - #68834

Merged
BrennanConroy merged 13 commits into
dotnet:mainfrom
GrantTotinov:passkey-alg-crv-validation-68755
Sep 29, 2026
Merged

BrennanConroy merged 13 commits into
dotnet:mainfrom
GrantTotinov:passkey-alg-crv-validation-68755

Conversation

@GrantTotinov

Copy link
Copy Markdown
Contributor

Validate COSE ALG+CRV combination when decoding passkey CredentialPublicKey

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Validates alg and crv match when decoding EC2 passkey public keys

Description

Adds validation that the COSE algorithm identifier (alg) and elliptic curve identifier (crv) form a valid pairing when decoding an EC2 passkey public key, alongside the existing kty+crv check. Covers the three alg/crv pairings CredentialPublicKey currently supports: ES256/P-256, ES384/P-384, ES512/P-521. An invalid combination throws the same way an invalid kty+crv combination already does, via PasskeyException from Decode().

ES256K is intentionally excluded, since it isn't in IsSupportedAlgorithm and P256K isn't accepted by the existing kty+crv check. OKP curves (Ed25519, Ed448, X25519, X448) are also out of scope, since MapCoseCrvToECCurve already rejects them with NotSupportedException before an alg+crv check would apply.

Fixes #68755

Copilot AI lite review requested due to automatic review settings August 27, 2026 00:03

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.

Pull request overview

Adds stricter validation when decoding passkey EC2 CredentialPublicKey CBOR by ensuring the COSE algorithm (alg) matches the COSE curve (crv) for supported ECDSA combinations, preventing malformed or inconsistent keys from being accepted and then failing later.

Changes:

  • Pass alg into EC public key parsing and reject invalid alg/crv pairings (ES256/P-256, ES384/P-384, ES512/P-521).
  • Add new unit tests covering valid pairings, mismatches, and the ES256K/P256K out-of-scope case.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Identity/Core/src/Passkeys/CredentialPublicKey.cs Validates alg+crv pairing during EC2 public key decode and throws CborContentException on invalid combinations.
src/Identity/test/Identity.Test/Passkeys/CredentialPublicKeyTest.cs Adds test coverage for accepted and rejected alg/crv combinations, including ES256K/P256K behavior.

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

@GrantTotinov

Copy link
Copy Markdown
Contributor Author

@BrennanConroy PR is up and ready for review.

@GrantTotinov

Copy link
Copy Markdown
Contributor Author

@BrennanConroy Can you have a look when you have time. Thanks.

@Youssef1313 Youssef1313 added the area-identity Includes: Identity and providers label Sep 2, 2026
@GrantTotinov

Copy link
Copy Markdown
Contributor Author

@BrennanConroy Addressed the comment wording and added the kty+crv test coverage in the latest commit. I'll push the NotSupportedException change for ES256K/P256K as a separate commit so it's easy to drop if you'd prefer a different approach.

P256K (secp256k1) is a valid COSE curve, but this implementation has never supported it. Reject it explicitly with NotSupportedException before the general kty+crv check, distinguishing "recognized but unsupported" from "not a valid kty+crv combination".
@GrantTotinov

Copy link
Copy Markdown
Contributor Author

@BrennanConroy Could you take a look when you get a chance? Thanks.

@BrennanConroy

Copy link
Copy Markdown
Member

/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.

@BrennanConroy
BrennanConroy merged commit f043395 into dotnet:main Sep 29, 2026
27 checks passed
@BrennanConroy

Copy link
Copy Markdown
Member

Thanks @GrantTotinov!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate Passkey Algorithm + CRV when decoding CredentialPublicKey

5 participants