fix: implement HMAC-SHA256 signature verification for OpenZeppelin webhook#34
fix: implement HMAC-SHA256 signature verification for OpenZeppelin webhook#34memosr wants to merge 1 commit into
Conversation
|
Good direction overall: reading the raw body before parsing and using One blocking mismatch with the OpenZeppelin Relayer implementation: the relayer sends the HMAC in the Source: OpenZeppelin Relayer computes And sends that value as This PR currently reads |
|
Thanks for the thorough review, @Cassxbt Both issues addressed in 9a93290
All tests pass. Ready for another look! |
|
Re-checked the updated implementation. The original OpenZeppelin Relayer mismatch is resolved: the route now reads One remaining test integration issue: I don’t see a runnable test command in So the implementation concern is fixed, but the regression test should be wired into a runnable command or adjusted for the repo’s test runner/module resolution. That way future maintainers can actually run the coverage you added. |
…bhook - Read X-Signature header and base64-decode the signature (matches OpenZeppelin Relayer spec) - Use timingSafeEqual with explicit length check on raw HMAC bytes - Extract verification logic into pure checkSignature() module for testability - Add 5 unit tests covering valid sig, wrong secret, tampered body, hex format, empty header - Add npm test script using node:test with tsx loader
9a93290 to
8ceead1
Compare
|
Thanks Test integration fixed in 8ceead1
Confirmed 1- accepts a valid signature I also rebased the branch onto the latest |
Problem
The OpenZeppelin Relayer webhook endpoint (
app/api/openzepellin/webhook/route.ts) accepts any POST request without verifying its origin. The code even has a comment admitting this:This means anyone can POST to this endpoint and forge transaction confirmations, triggering false status updates for arbitrary transactions.
Fix
Implemented HMAC-SHA256 signature verification using Node's built-in
cryptomodule:verifySignature()computes HMAC-SHA256 usingOZ_WEBHOOK_SIGNING_KEYenv vartimingSafeEqualto prevent timing attacks401if key is missing, header is absent, or signature is invalidImpact
OZ_WEBHOOK_SIGNING_KEYto be set in environment variables