Skip to content

feat(webhooks): make callback_url callable with the webhook secret - #1240

Merged
gkhngyk merged 20 commits into
ansvisor:mainfrom
knockknock10:feature/webhook-callback-secret-912
Oct 20, 2026
Merged

gkhngyk merged 20 commits into
ansvisor:mainfrom
knockknock10:feature/webhook-callback-secret-912

Conversation

@knockknock10

Copy link
Copy Markdown
Contributor

Summary

  • Add a public POST /webhooks/content/:id/status endpoint outside the authenticated /api routes.
  • Verify X-Webhook-Secret against the brand's active webhook secret using a constant-time comparison; reject missing or incorrect secrets.
  • Apply the existing public IP-based rate limiter (30 requests per 15 minutes).
  • Reuse the status whitelist shared with the dashboard route and preserve dismissal metadata and guarded updates.
  • Update both single and bulk opportunity.sent payloads to include the new callback_url and callback_method: "POST".
  • Document the callback method, secret header, supported statuses, and rate limit.
  • Add tests for missing/wrong/correct secrets and invalid status values.

Related issue

Closes #912

Type of change

  • feat — New feature
  • test — Adding or updating tests
  • docs — Documentation update

Validation

  • npm test from server/ — 1,825 tests passed
  • npm run lint from server/
  • npm run format:check from server/

The server test, lint, and format commands passed locally. GitHub Actions CI will run after this PR is opened.

Copilot AI balanced review requested due to automatic review settings October 20, 2026 04:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The secret check is sound:

  • it compares in constant time;
  • it is scoped to the opportunity's own brand;
  • an unknown id gets the same 401 as a wrong secret;
  • only the status changes.

One change before merge:

The rate limit. publicLimiter allows 30 requests per 15 minutes per IP. n8n cloud, Zapier and Make send from IP pools shared by all their customers. One bulk send of 20 opportunities with an in_progress and a done callback each is already 40 calls. Anyone else on the same pool can also use up the bucket. Bot ingest hit the same problem, and botIngestKey keys by the secret's hash. Please key this limiter the same way, with a higher ceiling, and keep a small IP limiter that counts only failed (401) attempts. Update the line in webhooks.mdx too.

Smaller:

  • sent can overwrite a callback. Both send routes set status: 'sent' after the receiver answers. A workflow that calls back before it responds (n8n's "respond when last node finishes") has its in_progress or done overwritten. Only set sent if the status hasn't moved since the send began.
  • Docs: say that callbacks need a secret; it is optional in settings today.
  • Tests: add a secret from another brand, a config without a secret, and an unknown id (all 401).
  • Bad ids: a non-UUID :id becomes a 500 (Postgres 22P02). Check the shape first and return the same 401.

@knockknock10

Copy link
Copy Markdown
Contributor Author

Maintainer follow-up addressed on the current branch.

  • The callback limiter now keys the high-volume budget by SHA-256 hash of the supplied secret (1,200 requests/15 minutes) and uses a separate per-IP limiter that counts only failed 401 attempts (10/15 minutes).
  • Both single and bulk sends conditionally mark an opportunity as sent only if its status and updated_at have not changed since delivery began, preserving an early callback or user edit.
  • Non-UUID IDs return the same 401 as unknown IDs and wrong secrets.
  • Tests cover another brand's secret, an active config without a secret, an unknown UUID, and malformed IDs.
  • The docs now explicitly require a non-empty configured secret for callbacks and describe the rate limits and race-safe status behavior.

Latest CI run #2391 passed all server, web and schema jobs.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this works now. Keying the budget by the secret and keeping a separate limiter for failed attempts solves the shared-IP problem for valid callbacks. Tested on top of main with #1239, #1241, #1242 and #1131: server 1,897 and web 1,796 tests pass, and lint and Prettier are clean.

One thing for a follow-up, not a blocker: the failed-attempt limiter is per IP, so ten 401s from one Zapier or Make customer with a stale secret also block every other customer's callbacks from that egress IP for 15 minutes. Keying it by IP plus opportunity id would keep a bad secret from blocking anyone else.

@gkhngyk
gkhngyk merged commit ade0e43 into ansvisor:main Oct 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(webhooks): make callback_url callable with the webhook secret so workflows can report status back

3 participants