fix: sync webhook events and HMAC verification with OpenWA v0.4.0#2
Merged
Conversation
- Replace invalid webhook event values (session.connected, session.qr_ready) with the canonical names and add the full WEBHOOK_EVENTS set in both nodes - Register the webhook secret on creation and verify the X-OpenWA-Signature HMAC-SHA256 header over the raw request body (was a plaintext header check) - Reject failed signature verification with HTTP 401 - Refresh README for payload drift (data.id, neutral type, whatsappId) and add an OpenWA >= 0.2.8 compatibility note - Add a node:test unit suite for signature verification and run it in CI Closes #1
…ation Adds an optional Webhook Secret field to the OpenWA action node's Create Webhook operation and includes it in the create request body, so OpenWA signs deliveries to webhooks registered through the action node. Mirrors the Trigger node's secret handling (the secret is sent verbatim, not trimmed).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Brings the node back in sync with the OpenWA backend (verified against v0.4.0). Fixes the two defects tracked in #1, refreshes documentation for payload drift, and adds a unit test for signature verification.
Defect 1 — Invalid webhook event names (HTTP 400 on trigger activation)
session.connectedandsession.qr_readyare not in OpenWA's acceptedWEBHOOK_EVENTSset, so selecting them madePOST /api/sessions/:id/webhooksreturn 400. Both nodes now offer the canonical 12-event set and the two invalid values are removed:Defect 2 — Webhook secret / HMAC mismatch (silent drop)
The Trigger previously posted only
{ url, events }on creation and verified a plaintextx-webhook-secretheader that OpenWA never sends, so every delivery was dropped when a secret was configured. Now:create()registers thesecretwith OpenWA, andwebhook()verifies theX-OpenWA-Signature: sha256=<hex>HMAC-SHA256 over the raw request body (timing-safe), rejecting failed verification with HTTP 401.The secret is registered and verified with the same value, so both sides stay in sync by construction. Verification hashes the raw bytes (not a re-serialized body), matching the exact
JSON.stringify(payload)OpenWA signs.Additional: webhook secret on the action node
The action node's Create Webhook operation gains an optional Webhook Secret field, included in the create body so OpenWA signs deliveries to webhooks registered through the action node — mirroring the Trigger's secret handling. (Originally noted as out of scope in #1; added on request.)
Documentation
data.id(notmessageId) for incoming payloads, engine-neutral messagetype(chat→text,ptt→voice,vcard→contact), engine-canonicalwhatsappIdfrom contact checks, and an "OpenWA >= 0.2.8" compatibility note.Tests
node:testsuite (test/verifySignature.test.mjs) covering valid, tampered-body, wrong-secret, missing-header, empty-header, and malformed-prefix cases — no new dependencies.Verification
npm run lint,npm run build, and the test suite (7/7) all pass locally. The action node's REST endpoints were confirmed unchanged in v0.4.0 and are untouched.Closes #1