Closed Bug 1760806 Opened 4 years ago Closed 1 year ago

crypto.subtle.importKey doesn't check the curve when importing JWK ECC keys

Categories

(Core :: DOM: Web Crypto, defect, P2)

Firefox 100
defect

Tracking

()

RESOLVED FIXED
130 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr128 --- fixed
firefox129 --- wontfix
firefox130 --- fixed

People

(Reporter: twiss, Assigned: anna.weine)

Details

(Keywords: sec-audit, Whiteboard: [adv-main130-])

Attachments

(2 files)

Steps to reproduce:

In Web Crypto, when importing an ECDSA or ECDH key in JsonWebKey format, the importKey() function doesn't check that the JWK "crv" field matches the "namedCurve" field of the algorithm identifier. It uses the crv field for the resulting key, which means that you can silently end up with a key of a different curve than you expected. For ECDSA keys, it also doesn't check the "alg" field ("ES256" / "ES384" / "ES521"), which should also correspond to the specified curve.

Actual results:

Some examples:

const ecdsaKey = await crypto.subtle.importKey('jwk', {
    "alg": "ES256",
    "crv": "P-256",
    "ext": true,
    "key_ops": ["verify"],
    "kty": "EC",
    "x": "OHqWk67pCFd4uTsIdPqBYY07hyO437NrWfeQUQemMUw",
    "y": "vw6udLfdNpXVS5r7MmsPWCZwPKv3ZWh2PyXOyReeVVY"
}, {
    "name": "ECDSA",
    "namedCurve": "P-521"
}, true, ["verify"]);
console.log(ecdsaKey.algorithm.namedCurve); // P-256

const ecdhKey = await crypto.subtle.importKey('jwk', {
    "crv": "P-256",
    "d": "kRyHUtNO4MjE4tG5RFjDYFIE7cMFTQieOozwvwxdiwU",
    "ext": true,
    "key_ops": ["deriveBits"],
    "kty": "EC",
    "x": "CRWJeGR9DSxUDaPwBm5FuY3aaQohKOYU2hxnaFiq94I",
    "y": "C-Qk2LL2DbA0yndHXDGU-_hwK53lQOcGG1JpWN-KxEc"
}, {
    "name": "ECDH",
    "namedCurve": "P-521"
}, true, ["deriveBits"]);
console.log(ecdhKey.algorithm.namedCurve); // P-256

Expected results:

Both calls to importKey() should throw a DataError. This is required by the Web Crypto spec in the steps to import ECDSA and ECDH keys, here for ECDSA and here for ECDH (search for If format is "jwk":).

Assignee: nobody → nobody
Status: UNCONFIRMED → NEW
Component: Untriaged → Libraries
Ever confirmed: true
Product: Firefox → NSS
Version: Trunk → other
Assignee: nobody → nobody
Component: Libraries → DOM: Web Crypto
Product: NSS → Core
Version: other → Firefox 100

The severity field is not set for this bug.
:keeler, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(dkeeler)
Severity: -- → S4
Flags: needinfo?(dkeeler)
Group: crypto-core-security

Ben: if there's a need to block public visibility of this issue after two years is it worse than the "S4" severity indicates? What security rating (sec-high, sec-low?) would you give it.

We did a group triaging session and decided to have a second look at it just in case, Anna, will take another look shortly

Flags: needinfo?(nkulatova)
Whiteboard: sec-audit
Keywords: sec-audit
Whiteboard: sec-audit
Assignee: nobody → anna.weine
Flags: needinfo?(anna.weine)
Flags: needinfo?(anna.weine)
Severity: S4 → S3
Flags: needinfo?(anna.weine)
Priority: -- → P2
Flags: needinfo?(anna.weine)
Attachment #9414125 - Attachment description: WIP: Bug 1760806 - WebCrypto: ECDH and ECDSA JWK import to check that the crv in params and crv in alg are the same → Bug 1760806 - WebCrypto: ECDH and ECDSA JWK import to check that the crv in params and crv in alg are the same

Hi Daniel,
should we add this example into the list of WebCrypto tests?

Thanks!

Flags: needinfo?(anna.weine) → needinfo?(d.huigens)

Yeah, it would be good to test this in wpt (and perhaps a bit more generally, e.g. other combinations as well); there's even a note about it here. I can take a stab at it, but I'll be on vacation the next two weeks so it'd probably be after that. If you want to beat me to it feel free ofc :)

Flags: needinfo?(d.huigens)
Flags: needinfo?(anna.weine)
Pushed by nkulatova@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/bcacbdd1e5b5 WebCrypto: ECDH and ECDSA JWK import to check that the crv in params and crv in alg are the same r=keeler
Group: crypto-core-security → core-security-release
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 130 Branch
Flags: needinfo?(anna.weine)

Does this still need a rating (sec-low, etc)?

Flags: needinfo?(anna.weine)

I think we are good with just sec-audit, though to confirm I'll refer to Dan.

Flags: needinfo?(anna.weine) → needinfo?(dveditz)
QA Whiteboard: [post-critsmash-triage]
Flags: qe-verify-

Did you want to nominate this for ESR128 uplift? It grafts cleanly.

Flags: needinfo?(anna.weine)
Flags: needinfo?(dveditz)
Whiteboard: [adv-main130-]
Attachment #9422012 - Flags: approval-mozilla-esr128?

esr128 Uplift Approval Request

  • User impact if declined: None
  • Code covered by automated testing: no
  • Fix verified in Nightly: no
  • Needs manual QE test: no
  • Steps to reproduce for manual QE testing: Just in case. It's a webcrypto code, so in order to check the change you should call https://bugzilla.mozilla.org/show_bug.cgi?id=1760806#c0 code through browser terminal
  • Risk associated with taking this patch: Little risk
  • Explanation of risk level: the keys could be generated with a wrong parameters, that will cause the other operations not to work without revealing any user data
  • String changes made/needed: No
  • Is Android affected?: no
Flags: needinfo?(anna.weine)
Attachment #9422012 - Flags: approval-mozilla-esr128? → approval-mozilla-esr128+
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: