Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#8491·worldmonitor

refactor(convex): extract shared Svix signature verification; three copies have diverged

Author: koala73Created Sep 22, 2026Updated Sep 25, 2026

Summary

Svix/standardwebhooks signature verification is hand-copied across three webhook handlers with no canonical source. The constant-time comparison helper it depends on is copied into five files. There is no convex/lib/svix* module.

This is pre-existing and follows an established repo convention, so it is not a regression and not urgent. Filing it because the copies have already started to diverge, and PR #8469 made that measurably worse.

The copies

Full Svix v1 verifiers (whsec_ secret, HMAC-SHA256, v1,<sig> header parsing):

File Verifier
convex/accountDeletion/clerkWebhook.ts Clerk user.deleted
convex/resendWebhookHandler.ts Resend
convex/payments/webhookHandlers.ts Dodo Payments (standardwebhooks)

timingSafeEqualStrings alone is additionally copied into:

  • convex/http.ts:80
  • convex/companyMonitoring/orchestration.ts:193 (same logic, params named left/right)

Evidence of drift

1. The secret prefix strip is now inconsistent. PR #8469 fixed an unanchored replace("whsec_", "") — which removes the first occurrence anywhere rather than a prefix — in one copy only:

  • convex/accountDeletion/clerkWebhook.ts:58 — fixed, anchored startsWith/slice
  • convex/resendWebhookHandler.ts:89 — still secret.replace("whsec_", "")
  • convex/payments/webhookHandlers.ts:59 — still webhookKey.replace("whsec_", "")

Not reachable today (_ is outside the base64 alphabet atob accepts), so this is robustness rather than a live defect — but it is a fix that exists in one third of the copies.

2. The signature-candidate cap is in one copy only. #8469 bounded the v1 candidate loop (MAX_SIGNATURE_CANDIDATES = 5) because each candidate costs a key generation plus two HMAC signs on an unauthenticated endpoint. The other two verifiers remain unbounded.

3. A parts-length guard exists in one copy only. convex/resendWebhookHandler.ts:110 does if (parts.length !== 2) continue; after splitting the versioned signature. clerkWebhook.ts does not.

So three different hardening measures each live in exactly one of three copies. That is the failure mode the duplication creates: a fix to one verifier silently leaves the others unpatched.

Proposed scope

Extract a shared convex/lib/svixVerify.ts exporting:

  • timingSafeEqualStrings(a, b)
  • verifySvixSignature(payload, headers, secret, { skewSeconds, headerNames })

parameterized on skew seconds and header names (Clerk/Resend use svix-*, Dodo uses webhook-*), and fold in all three hardening measures once. Migrate the three verifiers to it; optionally migrate http.ts and companyMonitoring/orchestration.ts to the shared compare helper.

Suggested as a follow-up after #8469 merges — doing it inside that PR would widen an account-deletion change into the Resend and Dodo webhook paths, which it does not otherwise touch.

Verification available

convex/__tests__/accountDeletionClerkWebhook.test.ts has nine tests covering the Clerk verifier specifically (invalid signature, stale/future/non-numeric timestamp, candidate cap, rotation-shaped header, duplicate svix-id, ignored event type), and the Resend and Dodo handlers have their own suites. A rewire has real coverage to land against.

Provenance

Raised by the maintainability reviewer in the multi-agent review of #8469 and independently confirmed by a validator, which downgraded it from P1 to P2/P3 on the grounds that the pattern predates this PR. Deliberately left unfixed there; see the PR discussion.

Source: koala73/worldmonitor

View original on GitHubView discussion on GitHub