fix(webhooks): require v1 version prefix when verifying signatures

SH
2d ago
+38-1

Webhooks.verify split each signature entry on , and verified the digest without checking that the version prefix is v1, so headers such as v0,<hmac> or v2,<hmac> were accepted.

Changes:

  • Require parts[0] == "v1" alongside len(parts) == 2 in resend/webhooks/_webhooks.py.
  • Add unit tests in tests/webhooks_test.py verifying non-v1 signatures are rejected while mixed headers containing a valid v1 signature succeed.

Verification:

  • flake8 --max-line-length=130 ./resend/
  • mypy --ignore-missing-imports resend/ examples/ tests/webhooks_test.py (160 files, 0 issues)
  • pytest --doctest-modules tests (879 passed)

Summary by cubic

Fixes webhook signature verification so only v1-prefixed signatures are accepted. Previously, headers like v0,<hmac> or v2,<hmac> were treated as valid because the version prefix was never checked.

Bug Fixes

  • Require the version prefix to be exactly v1 when parsing signature entries.
  • Add tests covering rejection of v0/v2 signatures and acceptance of mixed headers containing a valid v1 signature.