Skip to content

chore(security): verify Cloro webhook signatures on /cloro/callback #146

Closed

Description

@gkhngyk

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_SECRET to Vercel env (production + preview + development).
  • In server/src/server.js, mount express.raw({ type: 'application/json' }) on /cloro/callback specifically so the body bytes survive intact. The default express.json() middleware re-serializes the payload and breaks HMAC.
  • Compute HMAC-SHA256(secret, ${timestamp}.${rawBody}), compare against X-Cloro-Signature (v1=…) using crypto.timingSafeEqual. Reject 401 on mismatch.
  • Reject 400 when X-Cloro-Timestamp is more than 5 minutes off Date.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_SECRET documented in web/.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-tracking to a similar pattern — that runs against CRON_SECRET already

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

  1. added
    enhancement
    help wanted
    on Jun 2, 2026
  2. added a commit that references this issue on Jun 12, 2026
    8c8615c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions