Skip to content

fix(webhook): handle non-ASCII signatures gracefully in secure_compare (#1991) - #1995

Open
jaideepkrishna2008-ui wants to merge 2 commits into
stripe:masterfrom
jaideepkrishna2008-ui:fix/webhook-non-ascii-signature
Open

jaideepkrishna2008-ui wants to merge 2 commits into
stripe:masterfrom
jaideepkrishna2008-ui:fix/webhook-non-ascii-signature

Conversation

@jaideepkrishna2008-ui

Copy link
Copy Markdown

Why?

Fixes #1991.

WebhookSignature.verify_header raised an unhandled TypeError when a v1 value in the Stripe-Signature header contained a non-ASCII character (e.g., t=1,v1=é), instead of raising SignatureVerificationError. This caused webhook handlers that catch ValueError and SignatureVerificationError to fail with unhandled 500 errors on invalid external requests.

secure_compare in stripe/_util.py passed both string arguments directly to standard library hmac.compare_digest, which only supports ASCII strings.

What?

  • Updated secure_compare in stripe/_util.py to gracefully catch TypeError and fall back to comparing UTF-8 encoded bytes with hmac.compare_digest in constant time.
  • Added regression test test_raise_on_non_ascii_signature_in_header in tests/test_webhook.py verifying that non-ASCII signatures raise SignatureVerificationError.
  • Added Hark changefile at .hark/changes/2026-11-15_jaideepkrishna2008-ui_webhook-non-ascii-signature.change.md.

See Also

Configuration

  • skip-changefile: This PR is not a user-facing change, so there's no changefile.

stripe#1991)

WebhookSignature.verify_header raised a TypeError when encountering
a non-ASCII character in header signatures because stdlib hmac.compare_digest
does not support non-ASCII string comparisons. Fall back to UTF-8 encoded
bytes comparison in secure_compare so invalid non-ASCII signatures raise
SignatureVerificationError as expected instead of an unhandled TypeError.

Fixes stripe#1991
@jaideepkrishna2008-ui
jaideepkrishna2008-ui requested a review from a team as a code owner November 15, 2026 14:05
@jaideepkrishna2008-ui
jaideepkrishna2008-ui requested review from ramya-stripe and removed request for a team November 15, 2026 14:05
@cla-assistant

cla-assistant Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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.

WebhookSignature.verify_header raises TypeError for a non-ASCII v1 signature

1 participant