fix(billing): compare Stripe webhook signature in constant time (BUNYIP-107) #147
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/BUNYIP-107-webhook-constant-time"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Compare the Stripe webhook signature in constant time. The verifier hex-encoded the expected HMAC and compared it to each provided
v1signature with==, which short-circuits on the first differing byte and leaks timing. This is on the billing-grant path (a forged webhook drives membership/entitlement state), so constant-time comparison is the expected hygiene (Stripe's own SDK uses it).Change
v1signature from hex and verify it against the computed MAC with hmac's constant-timeverify_slice, instead of hex-encoding the expected MAC and string-comparing.verify_sliceconsumes it).v1handling are preserved.Testing (rust-builder container)
cargo test -p bunyip-domain --lib stripe: 23 pass, including the existing valid/invalid/old-timestamp/missing-timestamp/no-v1 tests and a newverify_webhook_signature_wrong_but_valid_hexthat exercises the constant-time rejection path (valid hex, wrong value).cargo clippy -p bunyip-domain --all-targets -- -D warnings: clean.cargo fmt --all --check: clean.