crypto.subtle.importKey doesn't check the curve when importing JWK ECC keys
Categories
(Core :: DOM: Web Crypto, defect, P2)
Tracking
()
People
(Reporter: twiss, Assigned: anna.weine)
Details
(Keywords: sec-audit, Whiteboard: [adv-main130-])
Attachments
(2 files)
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
phab-bot
:
approval-mozilla-esr128+
|
Details | Review |
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":).
Updated•4 years ago
|
Updated•4 years ago
|
Comment 1•4 years ago
|
||
The severity field is not set for this bug.
:keeler, could you have a look please?
For more information, please visit auto_nag documentation.
Updated•4 years ago
|
Updated•2 years ago
|
Comment 2•2 years ago
|
||
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.
Comment 3•2 years ago
|
||
We did a group triaging session and decided to have a second look at it just in case, Anna, will take another look shortly
Updated•2 years ago
|
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 4•1 year ago
|
||
Updated•1 year ago
|
| Assignee | ||
Comment 5•1 year ago
|
||
Hi Daniel,
should we add this example into the list of WebCrypto tests?
Thanks!
| Reporter | ||
Comment 6•1 year ago
|
||
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 :)
| Assignee | ||
Updated•1 year ago
|
Comment 8•1 year ago
|
||
| Assignee | ||
Updated•1 year ago
|
Comment 10•1 year ago
|
||
I think we are good with just sec-audit, though to confirm I'll refer to Dan.
Updated•1 year ago
|
Updated•1 year ago
|
Comment 11•1 year ago
|
||
Did you want to nominate this for ESR128 uplift? It grafts cleanly.
Updated•1 year ago
|
| Assignee | ||
Comment 12•1 year ago
|
||
Updated•1 year ago
|
Comment 13•1 year ago
|
||
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
| Assignee | ||
Updated•1 year ago
|
Updated•1 year ago
|
Comment 14•1 year ago
|
||
| uplift | ||
Updated•1 year ago
|
Updated•1 year ago
|
Description
•