fix(security): include webhook endpoint secrets in encryption key rotation

Open
#764 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
77/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
next.js, typescript

Research direction

Start with src/lib/crypto/rotation.ts and its tests; trace how the existing sealed tables are read, re-encrypted, and counted, then inspect webhookEndpointSecretAad in src/lib/data/webhook-endpoints.ts. Add coverage for rotating an endpoint secret and delivering with only the new key, and update the Key rotation section of docs/operations/deploy.md to list every sealed table. Done means the rotation counts and re-encrypts endpoint secrets and the documented table list is complete.

Written by the indexing model from the issue text.

Description

area: security bug impact: medium priority: P2 size: S

Context

Found by the Fable pre-production review on 2026-12-02 (main at cedc1914; every line reference below re-checked on main at cde5aa3b). Source: security and privacy readiness report, new issue 4.

npm run keys:rotate re-encrypts only two tables: sealedTables covers connection_credentials and notification_destination_secrets (src/lib/crypto/rotation.ts:43-111). Per-connection webhook endpoint secrets are sealed with the same key (sealSecret, src/lib/data/webhook-endpoints.ts:107-109) and are not rotated. An unreadable secret logs webhook_endpoint.secret_unreadable and returns null (webhook-endpoints.ts:209-212), which the webhook route answers with 404 (src/lib/webhooks/receive.ts:163-167). The procedure removes the old key once the script reports nothing remaining (docs/operations/deploy.md:294-300).

Impact: after a rotation and removal of the old key, every Polar, Resend, and GitLab per-connection delivery gets 404 and the script output shows nothing wrong; the timeline silently stops receiving those events until each connection's webhook is set up again. After a rotation prompted by a compromise, those secrets stay sealed under the compromised key.

Plan

  1. Add webhook_endpoints to sealedTables, with the same read, re-encrypt, and count steps as the other two, using its associated data (webhookEndpointSecretAad).
  2. Count it in "remaining", so the script never reports done while an endpoint secret is under an old key.
  3. List every sealed table in deploy.md "Key rotation".

Acceptance criteria

  • npm run keys:rotate re-encrypts webhook_endpoints secrets and counts them in "remaining".
  • A test rotates an endpoint secret, removes the old key, and verifies a delivery under the new key only.
  • deploy.md "Key rotation" lists every sealed table.
  • Playwright e2e: none needed, no screen changes.

Files and areas

src/lib/crypto/rotation.ts, its tests, docs/operations/deploy.md (Key rotation).

Non-goals: rotating other secrets, the incident runbook (separate issue).

Verification

npm run typecheck, npm run lint, npx vitest run src/lib/crypto src/lib/data.


Branch: <issue-number>-rotate-webhook-secrets

Model: anthropic/claude-opus-5-5 | Reasoning effort: unknown

Dominant language
TypeScript
Stars
13
Forks
2
Avg merge
5h 20m
Merged PRs (30d)
287

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from eddiejaoude/StackDash

All issues in eddiejaoude/StackDash

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.