You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
crypto.createHmac(alg, key) returns "" when alg is a const reference (string-literal-only dispatch — same pattern as #1074) #1076
Same shape as #1074 (jwt.sign `algorithm` option). The codegen for `crypto.createHmac` lowers based on whether the first argument is an inline `Expr::String` — `Expr::Identifier` (const refs), for-loop bindings, and any non-literal expression silently fall through to a path that produces an empty hash.
I'd guess `createHash`, `createCipheriv`, `createDecipheriv`, `createSign`, `createVerify` all share the bug (haven't tested all). Anywhere the runtime dispatches via a name string from the first arg.
Why this is a quiet trap
The chain runs without throwing — `.update(data).digest("hex")` is valid on whatever the broken `createHmac` returned — so callers see `""` back and only notice when a downstream comparison fails (e.g., HMAC-based webhook signature verification returns `false` 100% of the time, or TOTP verification never matches).
This call happens to use a literal so it works. PERRY_GAPS.md item B mis-diagnosed the smoke-test failure as a cross-module Buffer issue, but I just confirmed cross-module Buffer round-trips work fine; the real symptom would be: any nearby code that loops over algorithms (e.g., `for (const a of HASH_ALGS) { check(crypto.createHmac(a, k)...) }`) silently produces empties.
The Shopware/Woo webhook verifiers use `crypto.createHmac("sha256", secret).update(body).digest(...)` with inline literals, so they're not bitten — but anyone writing `const a = "sha256"; crypto.createHmac(a, secret)` is.
Suggested fix
Same as #1074: resolve simple compile-time-known const references before the literal-string match. `const a = "sha256"` is statically known. A small symbol-table lookup in the `createHmac` lowering would catch the common case.
Or: add a runtime path that takes the alg string at runtime and dispatches dynamically (slower but correct). Either is better than silent `""`.
Activity
fix(crypto): #1076 createHmac/createHash dispatch via const-bound or …
fix(jwt): #1074 — algorithm option resolves const-bound ident before …
fix(crypto): sha224/sha384, base64 digest, and Buffer hash input (#1393)