Conversation
HmacImportParams.length is optional; value_or(0) collapsed an explicit 0 into the same codepath as an absent length, so importRaw/importJwk treated it as "use the key-data length" and returned a usable key. The spec requires DataError when length is present and zero.
|
Warning Review limit reached
More reviews will be available in 19 minutes and 43 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
Comment |
|
Updated 10:11 PM PT - Jun 27th, 2026
❌ @robobun, your commit 34b2fbc has some failures in 🧪 To try this PR locally: bunx bun-pr 32899That installs a local version of the PR into your bun-32899 --bun |
There was a problem hiding this comment.
LGTM — straightforward spec-compliance guard mirroring the existing generateKey pattern; the error-precedence nit for pkcs8/spki is take-it-or-leave-it.
Extended reasoning...
Overview
This PR adds a single 4-line early-return guard to CryptoAlgorithmHMAC::importKey in src/jsc/bindings/webcrypto/CryptoAlgorithmHMAC.cpp, rejecting with DataError when HmacImportParams.length is present and zero. It also adds two regression tests in test/js/web/crypto/web-crypto.test.ts covering the raw and jwk formats, asserting that absent length still works, length:0 rejects with DataError, and adjacent non-zero lengths behave as before.
The guard is a near-verbatim copy of the existing length && !length.value() check in generateKey ~20 lines above (which throws OperationError per its own spec step), so it follows an established pattern in the same file.
Security risks
None. The change makes input validation stricter, turning a previously-accepted nonsensical parameter (length: 0) into a rejection. It does not relax any check, touch key material handling, or affect the sign/verify paths. No new data flows are introduced.
Level of scrutiny
Low. This is a small, mechanical spec-compliance fix in WebKit-derived WebCrypto bindings: one conditional plus an exception callback, with the exact std::optional present-and-zero idiom already used elsewhere in the function's sibling. The behavior aligns Bun with Node, Deno, and browsers per the PR description. Tests demonstrate the before/after delta cleanly and pin surrounding behavior (absent / 1 / 159 / 160) to guard against regressions.
Other factors
- The one finding from bug-hunting is a true nit: placing the guard before the
switch(format)meanspkcs8/spki+length:0now yieldsDataErrorinstead ofNotSupportedError. That input is nonsensical (HMAC doesn't support those formats), the call fails either way, and no WPT covers it. Not a blocker. - No CODEOWNERS entry covers
src/jsc/bindings/webcrypto/. - No prior human review comments to address; CodeRabbit was rate-limited and posted no findings.
Unsupported formats (pkcs8, spki) must reject with NotSupportedError before the length member is considered, so the present-and-zero guard belongs inside the raw and jwk branches, not before the switch.
There was a problem hiding this comment.
LGTM — the error-precedence nit is addressed (guard now lives inside the Raw/Jwk cases) and the new pkcs8/spki tests pin it.
Extended reasoning...
Overview
Adds an 8-line guard to CryptoAlgorithmHMAC::importKey so that an explicit length: 0 in HmacImportParams rejects with DataError for the raw and jwk formats, matching the WebCrypto spec and Node/Deno/browser behavior. Previously the .value_or(0) collapse made length: 0 indistinguishable from an absent length, so the call succeeded with a derived length. ~58 lines of tests cover absent/0/1/159/160 for raw, absent/0 for jwk, and pin NotSupportedError precedence for pkcs8/spki regardless of length.
Security risks
None. This strictly tightens input validation on a nonsensical parameter combination that every other engine already rejects. No crypto primitives, key material handling, or memory management are touched.
Level of scrutiny
Low. The C++ change is two identical 4-line early-returns that mirror the existing generateKey pattern in the same file (same hmacParameters.length && !hmacParameters.length.value() shape, just DataError instead of OperationError per spec). The placement inside the per-format case arms keeps the spec's error ordering intact, and the author explained why the check can't move into CryptoKeyHMAC::importRaw (structured-clone calls it with 0 meaning "unspecified").
Other factors
- My earlier nit about the guard running before the format switch was fully addressed in 92a9c65; the inline thread is resolved and the new
it.each(['pkcs8','spki'])test guards against regressing it. - No CODEOWNERS cover these paths.
- The bug-hunting pass found nothing.
- The CI failures reported by robobun are all
build-rustjobs (plus one muslbuild-cpp) inscripts/build/ci.ts— this PR touches no Rust, so those look like infra flakes rather than anything caused here.
There was a problem hiding this comment.
LGTM — the error-precedence nit is addressed and the new tests pin both the fix and the format ordering.
Extended reasoning...
Overview
Adds a length == 0 → DataError guard to the Raw and Jwk branches of CryptoAlgorithmHMAC::importKey (8 lines of C++), plus a new describe block in web-crypto.test.ts covering absent/zero/short/exact length for raw and jwk, and asserting that pkcs8/spki still reject with NotSupportedError regardless of length.
My earlier review flagged that the guard was placed before the format switch, which would have flipped the spec's error precedence for unsupported formats. The author moved it into the per-format cases in 92a9c65 and added tests that lock in the precedence — this fully resolves the nit.
Security risks
None. The change tightens input validation on an edge case (HmacImportParams.length === 0) that previously fell through to deriving the length from key data. No new key material handling, no crypto primitive changes, no parsing of attacker-controlled buffers beyond what already exists.
Level of scrutiny
Low. This is a narrow spec-compliance fix matching browser/Node/Deno behavior. The guard pattern is copied verbatim from generateKey a few lines up in the same file, and the placement now mirrors how sibling algorithm files structure per-format checks. The author's note about not pushing the check into CryptoKeyHMAC::importRaw (because SerializedScriptValue.cpp relies on 0 meaning unspecified there) is correct and shows the right call sites were considered.
Other factors
No CODEOWNERS cover this path. The bug-hunting pass found nothing. Tests are thorough — they distinguish absent vs. explicit-zero, cover both supported formats, and regression-test the error-precedence ordering for unsupported formats. The robobun CI comment references failures on an earlier commit (aada231) before the ci: retrigger commit; the code change itself is sound regardless.
|
CI status, for whoever picks this up: The only lane that fails is The Build 65758 ran the full matrix against this exact code: 280 lanes passed and that one darwin lane was the only failure. On build 65821 six more test lanes expired waiting for an agent, and the most recent main build (65790) failed with its pipeline step timing out, so the agent pool looks unhealthy in general right now, independent of this PR. I retried once with an empty commit and it hit the same timeout, so I'll stop re-pushing rather than pile up retrigger commits. The change is ready to review. |
|
Closing: this change is already on main. #34838 (50bb3bd) added the Verified on main at e3b6d63 (source) and f42e980 (runtime):
Two expectations in this PR's tests differ from main on purpose. Main matches Node v26.3.0 in both cases:
|
Problem
crypto.subtle.importKeywith HMAC and an explicitlength: 0inHmacImportParamsreturns a usable key whosealgorithm.lengthis derived from the key data, instead of rejecting. The spec requiresDataErrorwhen thelengthmember is present and zero.Node v26.3.0, Deno, and browsers all reject with
DataErrorhere.Cause
CryptoAlgorithmHMAC::importKeypasseshmacParameters.length.value_or(0)toCryptoKeyHMAC::importRaw/importJwk, collapsing "length is absent" and "length is 0" into the same value.importRawthen treats0as "unspecified" via a falsy check and falls back to the key-data length.Fix
Reject a present-and-zero
lengthinside therawandjwkbranches ofCryptoAlgorithmHMAC::importKey, after the format dispatch. That placement keeps the spec's error precedence: an unsupported format (pkcs8,spki) still rejects withNotSupportedErrorregardless oflength.The check has to live here rather than in
CryptoKeyHMAC::importRaw:SerializedScriptValue.cppcallsimportRaw(0, ...)for structured-clone deserialization, where0must keep meaning "unspecified".The
length: 1..159cases already throwDataError, which is what the spec says; Node'sNotSupportedErrorthere is Node deviating, so those rows are left as-is.Verification
The two
length:0tests fail onmainwithzero: { length: 160 }instead ofzero: { error: "DataError" }. The format-precedence tests pass onmainand guard against a guard placed before the format switch.