Repository navigation
Validate COSE ALG+CRV combination when decoding passkey CredentialPublicKey - #68834
Conversation
There was a problem hiding this comment.
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
alginto EC public key parsing and reject invalidalg/crvpairings (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.
|
@BrennanConroy PR is up and ready for review. |
|
@BrennanConroy Can you have a look when you have time. Thanks. |
|
@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".
|
@BrennanConroy Could you take a look when you get a chance? Thanks. |
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). 3 pipeline(s) were filtered out due to trigger conditions. |
|
Thanks @GrantTotinov! |
Validate COSE ALG+CRV combination when decoding passkey CredentialPublicKey
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