From 0b9698c80a72a09dbbac2f5af0177d834251ec63 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 21 Feb 2023 21:07:04 +0100 Subject: [PATCH] [DOM] WebCrypto: Check decoded key type before using it. Just in case someone forces the wrong key type and misuses WebCrypto. It won't be usable anyway so better to throw. --- dom/crypto/WebCryptoTask.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dom/crypto/WebCryptoTask.cpp b/dom/crypto/WebCryptoTask.cpp index ad81b6d4c6..ed47325f8d 100644 --- a/dom/crypto/WebCryptoTask.cpp +++ b/dom/crypto/WebCryptoTask.cpp @@ -1741,6 +1741,10 @@ private: return NS_ERROR_DOM_SYNTAX_ERR; } + if (pubKey->keyType != rsaKey) { + return NS_ERROR_DOM_DATA_ERR; + } + // Extract relevant information from the public key mModulusLength = 8 * pubKey->u.rsa.modulus.len; if (!mPublicExponent.Assign(&pubKey->u.rsa.publicExponent)) { @@ -1874,6 +1878,10 @@ private: } if (mFormat.EqualsLiteral(WEBCRYPTO_KEY_FORMAT_SPKI)) { + if (pubKey->keyType != ecKey) { + return NS_ERROR_DOM_DATA_ERR; + } + if (!CheckEncodedECParameters(&pubKey->u.ec.DEREncodedParams)) { return NS_ERROR_DOM_OPERATION_ERR; }