Repository navigation
chore(security): verify Cloro webhook signatures on /cloro/callback - #229
Merged
Merged
Conversation
Add HMAC-SHA256 signature verification (X-Cloro-Signature / X-Cloro-Timestamp, v1=<hex> over `timestamp.rawBody`) to the public Cloro callback endpoint, enforced when CLORO_WEBHOOK_SECRET is set. Uses crypto.timingSafeEqual and a 5-minute replay window; rejections log webhook id + IP for probe detection. The callback path is mounted with express.raw() ahead of the global JSON parser so the body bytes survive intact for HMAC, and the payload is parsed only after the signature check passes. When CLORO_WEBHOOK_SECRET is unset (self-hosted installs, or signing not yet enabled in the Cloro dashboard) behavior is unchanged: deliveries are accepted and validated via task_id lookup, as before. Closes #146
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.
Closes #146
What
Adds HMAC-SHA256 signature verification to the public
/cloro/callbackwebhook endpoint, enforced whenCLORO_WEBHOOK_SECRETis set.server/src/lib/cloro-webhook-verify.js— pure verification function: computesHMAC-SHA256(secret, \${timestamp}.${rawBody}`), parses thev1=scheme fromX-Cloro-Signature, compares withcrypto.timingSafeEqual`, and rejects timestamps outside a 5-minute replay window. No env access, injectable clock — ready for unit tests once the server test runner lands (ci: add automated test job once test infra exists #125).server/src/server.js— mountsexpress.raw({ type: 'application/json' })on/cloro/callbackahead of the global JSON parser so the body bytes survive intact for HMAC (the global parser skips the path since the body is already consumed; all other routes are untouched). The payload is JSON-parsed only after the signature check passes. Rejections respond 401 (bad/missing signature) or 400 (stale/invalid timestamp, malformed JSON) before the 200 ack, and log the delivery's webhook id + IP so probing is visible.server/.env.example— documentsCLORO_WEBHOOK_SECRETwith the rollout caveat.Backward compatibility
When
CLORO_WEBHOOK_SECRETis unset — every self-hosted install today, and cloud until the dashboard switch is flipped — behavior is byte-for-byte unchanged: deliveries are accepted and validated viatask_identropy +cloro_pending_taskslookup, exactly as before. Nothing breaks on merge.The signature scheme was verified against Cloro's published docs (https://docs.cloro.dev/guides/webhooks): the
whsec_…secret is used as-is (no prefix stripping or base64 decoding), signed string istimestamp.rawBody, hex digest inv1=.Test plan
verifyCloroWebhook: valid signature accepted; missing headers → 401; wrong secret → 401; tampered body → 401; stale (±6 min) timestamp → 400; 4 min 59 s old → accepted; non-numeric timestamp → 400; garbage/emptyv1=→ 401No pending tasklog); malformed JSON → 400;/api/*routes unaffectedDeploy notes (cloud)
Order matters after this merges and deploys:
whsec_…secret — it is shown exactly once.CLORO_WEBHOOK_SECRETon the server and restart.Doing 3 without 2 rejects every delivery with 401. The 2→3 gap is safe (unsigned deliveries are still accepted until the env lands), and Cloro retries failed deliveries up to 5 times with exponential backoff, so a short restart window self-heals.