Truly independent web browser
LibWeb: Reject Argon2 lengths that are not a whole number of bytes
Shannon Boothc7868e60adfd
diff --git a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cppindex b771d51fcbf..615fdda87be 100644--- a/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp+++ b/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp@@ -9535,8 +9535,8 @@ WebIDL::ExceptionOr<GC::Ref<CryptoKey>> Argon2::import_key(JS::Realm&, AlgorithmWebIDL::ExceptionOr<ByteBuffer> Argon2::derive_bits(JS::Realm&, AlgorithmParams const& params, GC::Ref<CryptoKey> key, Optional<u32> length){auto const& normalized_algorithm = static_cast<Argon2Params const&>(params);- // 1. If length is null, or is less than 32 (4*8), then throw an OperationError.- if (!length.has_value() || length.value() < 32u)+ // 1. If length is null, or is less than 32 (4*8), or is not a multiple of 8, then throw an OperationError.+ if (!length.has_value() || length.value() < 32u || length.value() % 8 != 0)return WebIDL::OperationError::create("Length must be equal or greater than 32"_utf16);// 2. If the version member of normalizedAlgorithm is present and is not 19 (0x13), then throw an OperationError.diff --git a/Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-Argon2-length-whole-bytes.txt b/Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-Argon2-length-whole-bytes.txtnew file mode 100644index 00000000000..20fa8ea1519--- /dev/null+++ b/Tests/LibWeb/Text/expected/Crypto/SubtleCrypto-Argon2-length-whole-bytes.txt@@ -0,0 +1,2 @@+length 36: OperationError+length 40: okdiff --git a/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-Argon2-length-whole-bytes.html b/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-Argon2-length-whole-bytes.htmlnew file mode 100644index 00000000000..6075091ce19--- /dev/null+++ b/Tests/LibWeb/Text/input/Crypto/SubtleCrypto-Argon2-length-whole-bytes.html@@ -0,0 +1,20 @@+<!doctype html>+<script src="../include.js"></script>+<script>+ promiseTest(async () => {+ async function check(label, promise) {+ try {+ await promise;+ println(`${label}: ok`);+ } catch (error) {+ println(`${label}: ${error.name}`);+ }+ }++ const key = await crypto.subtle.importKey("raw-secret", new Uint8Array(16), "Argon2id", false, ["deriveBits"]);+ const algorithm = { name: "Argon2id", nonce: new Uint8Array(16), parallelism: 1, memory: 8, passes: 1 };++ await check("length 36", crypto.subtle.deriveBits(algorithm, key, 36));+ await check("length 40", crypto.subtle.deriveBits(algorithm, key, 40));+ });+</script>