fix(webhooks): handle svix 2.0.0 Webhook.verify() returning None - #196
Draft
Sbussiso wants to merge 1 commit into
Draft
fix(webhooks): handle svix 2.0.0 Webhook.verify() returning None#196Sbussiso wants to merge 1 commit into
Sbussiso wants to merge 1 commit into
Conversation
svix 2.0.0 is a breaking major release: Webhook.verify() now returns
None (it only validates the signature; the parsed event is no longer
returned). The weekly dependency refresh workflow runs 'uv lock
--upgrade', which resolves svix>=1.99.1 to 2.0.0, and 39 webhook
tests crashed with AttributeError: 'NoneType' object has no
attribute 'get' at event.get('type') in both the Clerk and Resend
handlers.
Keep wh.verify() as the signature-validation call (it still raises
WebhookVerificationError on a bad signature in both 1.x and 2.x),
then parse the now-authentic payload with json.loads() ourselves.
This is version-agnostic: identical behavior under svix 1.99.1
(verify returns the dict, which we overwrite with the same dict)
and 2.0.0 (verify returns None, we parse the verified bytes).
Verified: full backend suite (699 tests) passes under svix 2.0.0,
including all 39 previously-failing webhook tests. ruff clean.
CI run: https://github.com/SourceBox-LLC/Sentinel-Command/actions/runs/32700481827
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
The Weekly dependency refresh workflow (run #32700481827) runs
uv lock --upgradebefore the test gate. That resolvedsvix>=1.99.1→ svix 2.0.0, a breaking major release.svix 2.0.0 changed
Webhook.verify()to returnNone— it now only validates the signature; the parsed event dict is no longer returned (signature changed from-> dictto-> None). Both webhook handlers didevent = wh.verify(payload, headers)thenevent.get("type"), so 39 tests crashed with:Affected: all of
test_resend_webhook.py,test_webhooks.py, andtest_welcome_email.py(both the Clerk/api/webhooks/clerkand Resend/api/webhooks/resendroutes).Fix
Keep
wh.verify()as the signature-validation call (it still raisesWebhookVerificationErroron a bad signature in both svix 1.x and 2.x), then parse the now-authentic payload withjson.loads()ourselves. This is version-agnostic:verify()returns the dict; we overwrite it with the same dict (no-op).verify()returnsNone; we parse the verified bytes.verify()succeeding is proof the payload is authentic, so decoding it ourselves is safe and equivalent to what the library used to do internally.Verification
Reproduced the CI failure locally (installed svix 2.0.0 via
uv lock --upgrade), then confirmed the fix:ruff checkclean43 passedThis also lets the weekly refresh PR go green again — without this fix, every weekly refresh that pulls svix 2.0.0 will stay red.
CI run
https://github.com/SourceBox-LLC/Sentinel-Command/actions/runs/32700481827