From dc780d77e409fdcc81d83c0c4932cf4803435662 Mon Sep 17 00:00:00 2001 From: SGavrl <277843151+SGavrl@users.noreply.github.com> Date: Mon, 22 Jun 2026 22:19:02 +0000 Subject: [PATCH] js: handle SHA-512/224 and SHA-512/256 in crypto.subtle.digest The digest op fell through to SHA-256 for any unrecognized algorithm name, so SHA-512/224 and SHA-512/256 silently returned a SHA-256 hash. Add the two FIPS 180-4 truncated variants, which the AWS WAF challenge proof-of-work (used by booking.com and other CloudFront/WAF sites) requires. Fixes #314. --- crates/obscura-js/src/ops.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/obscura-js/src/ops.rs b/crates/obscura-js/src/ops.rs index 1975b72..99cccd3 100644 --- a/crates/obscura-js/src/ops.rs +++ b/crates/obscura-js/src/ops.rs @@ -1067,9 +1067,10 @@ fn op_binding_called(state: &OpState, #[string] name: &str, #[string] payload: & } /// Real WebCrypto `crypto.subtle.digest`. `algorithm` is the SubtleCrypto -/// algorithm name (`SHA-1` / `SHA-256` / `SHA-384` / `SHA-512`); unknown -/// names fall through to SHA-256 to match the previous JS fallback. Returns -/// the raw digest bytes so the JS shim can hand them back as an ArrayBuffer. +/// algorithm name (`SHA-1` / `SHA-256` / `SHA-384` / `SHA-512`, plus the +/// FIPS 180-4 truncated variants `SHA-512/224` and `SHA-512/256`). Other +/// names fall back to SHA-256. Returns the raw digest bytes so the JS shim +/// can hand them back as an ArrayBuffer. #[op2] #[buffer] fn op_subtle_digest(#[string] algorithm: &str, #[buffer] data: &[u8]) -> Vec { @@ -1080,6 +1081,8 @@ fn op_subtle_digest(#[string] algorithm: &str, #[buffer] data: &[u8]) -> Vec "SHA-256" => sha2::Sha256::digest(data).to_vec(), "SHA-384" => sha2::Sha384::digest(data).to_vec(), "SHA-512" => sha2::Sha512::digest(data).to_vec(), + "SHA-512/224" => sha2::Sha512_224::digest(data).to_vec(), + "SHA-512/256" => sha2::Sha512_256::digest(data).to_vec(), _ => sha2::Sha256::digest(data).to_vec(), } }