Skip to content

TW-5728: add webhooks server --register to auto-register the tunnel webhook#115

Merged
qasim-nylas merged 1 commit into
mainfrom
feature/TW-5728-webhook-server-register-cloudflared-tunnel
Jun 26, 2026
Merged

TW-5728: add webhooks server --register to auto-register the tunnel webhook#115
qasim-nylas merged 1 commit into
mainfrom
feature/TW-5728-webhook-server-register-cloudflared-tunnel

Conversation

@qasim-nylas

Copy link
Copy Markdown
Collaborator

Summary

Adds --register to nylas webhooks server. One command now gives a customer verified webhooks locally: once the cloudflared tunnel is up, the CLI creates a Nylas webhook for the live tunnel URL, fetches the signing secret into memory (HMAC verification on, nothing to copy), and deletes the webhook on exit. Creation is retried while Nylas verification returns error 70005 (a fresh tunnel hostname is still propagating).

nylas webhooks server --tunnel cloudflared --register --triggers message.created

What & why

  • No unsigned window — POST events are rejected (503) until the secret is installed, so the public tunnel never processes an unsigned event; the GET challenge stays open so Nylas's create-time verification still succeeds.
  • Race-free secret swap — the signing secret is read under the lock and passed into the replay check; UpdateSecret installs it post-start.
  • Self-cleaning — stale auto-webhook sweep on start; teardown on shutdown (warns with a manual-delete hint if the delete fails).
  • Clean interrupts — signal-aware context so Ctrl+C aborts tunnel start / registration cleanly.
  • Fail-closed — rejects an empty-secret response and removes the half-created webhook; --register cannot combine with --secret/--allow-unsigned/--no-tunnel.
  • Early cloudflared check (offers brew install); prompts go to stderr under --json.

Testing

  • make ci-full green (quality + unit + race + integration + security + vuln + build)
  • New tests: AwaitSecret 503 gate, concurrent UpdateSecret -race, empty-secret cleanup, isWebhookVerifyError (incl. request-id false-positive), retry/timeout/sweep, flag conflicts
  • Verified end-to-end against a live account: register → events verified → deleted on Ctrl+C
  • Two rounds of Claude + Codex review; all findings addressed (final: both approve)

Related docs

… webhook

Run one command to receive verified webhooks locally. With --register, once the
cloudflared tunnel is up the CLI creates a Nylas webhook for the live tunnel URL,
fetches the signing secret into memory (HMAC verification on, nothing to copy),
and deletes the webhook on exit. Creation is retried while Nylas verification
returns error 70005 (a fresh tunnel hostname is still propagating).

- POST events are rejected (503) until the secret is installed, so the public
  tunnel never processes an unsigned event; the GET challenge stays open so
  Nylas's create-time verification still succeeds
- read the signing secret under the lock and pass it into the replay check to
  close the data race with the post-start UpdateSecret swap
- stale auto-webhook sweep on start; teardown on shutdown (warns if delete fails)
- signal-aware context so Ctrl+C aborts tunnel start / registration cleanly
- reject an empty-secret response and remove the half-created webhook
- early cloudflared check (with brew install offer); prompts go to stderr under --json
@qasim-nylas qasim-nylas requested a review from AaronDDM June 26, 2026 23:34

@AaronDDM AaronDDM left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 👍

@qasim-nylas qasim-nylas merged commit c6e9c38 into main Jun 26, 2026
7 checks passed
@qasim-nylas qasim-nylas deleted the feature/TW-5728-webhook-server-register-cloudflared-tunnel branch June 26, 2026 23:53
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.

2 participants