Repository navigation
Description
Problem
The /cloro/callback endpoint at server/src/server.js:233 accepts webhooks from Cloro with no signature verification:
// Cloro webhook callback (public, no auth — security via task_id entropy + DB lookup)
app.post('/cloro/callback', async (req, res) => { … })Today's defence is just "we look up task.id in cloro_pending_tasks and ignore unknown ids." That bounces opportunistic spam but doesn't stop a forged delivery where the attacker has obtained a valid pending task_id by any side channel (a leaked log line, a compromised Cloro account, network capture). A forged COMPLETED payload runs straight through handleScraperResult, inserting attacker-controlled response text, citations, mention counts, sentiment, and shopping cards into prompt_results for the matched brand — silently. Hard to detect after the fact because the row looks normal.
Cloro now publishes a signed-delivery option (HMAC-SHA256 over timestamp.rawBody, three headers: X-Cloro-Signature, X-Cloro-Timestamp, X-Cloro-Webhook-Id). Their docs are at https://docs.cloro.dev/integrations/webhooks. We should enable signing and verify on this endpoint.
Scope
- Enable signing in the Cloro dashboard for the org; grab the generated
whsec_…secret. - Add
CLORO_WEBHOOK_SECRETto Vercel env (production + preview + development). - In
server/src/server.js, mountexpress.raw({ type: 'application/json' })on/cloro/callbackspecifically so the body bytes survive intact. The defaultexpress.json()middleware re-serializes the payload and breaks HMAC. - Compute
HMAC-SHA256(secret,${timestamp}.${rawBody}), compare againstX-Cloro-Signature(v1=…) usingcrypto.timingSafeEqual. Reject 401 on mismatch. - Reject 400 when
X-Cloro-Timestampis more than 5 minutes offDate.now()(replay protection). - Parse the JSON body only after signature passes.
- Logging: bump a counter / log line when we reject so we can spot probing.
Acceptance criteria
- Endpoint returns 401 for any POST without a valid signature
- Endpoint returns 400 for stale timestamps (> 5 min)
- Genuine Cloro deliveries still succeed end-to-end (tracking run → prompt_results row + shopping cards normalized)
-
CLORO_WEBHOOK_SECRETdocumented inweb/.env.example(or wherever server env keys live) with a comment pointing at the Cloro dashboard - Deploy notes call out that the dashboard switch and the env var must land at the same time — flipping signing on without the env breaks delivery
Out of scope
- Building a full audit-log table for verified-vs-rejected deliveries (separate hardening item)
- Backfilling signatures onto historical deliveries (Cloro doesn't ship them)
- Migrating the in-app
/api/cron/daily-trackingto a similar pattern — that runs againstCRON_SECRETalready
Notes
This is security hardening, not a "good first issue" — signature verification is easy to do wrong (timing attacks on == comparison, parsing-before-verifying, off-by-one tolerance windows). Anyone picking this up should be comfortable with HMAC and Express body parsing.
Activity
chore(security): verify Cloro webhook signatures on /cloro/callback (a…