Repository navigation
fix(webhook): handle non-ASCII signatures gracefully in secure_compare (#1991) - #1995
Open
jaideepkrishna2008-ui wants to merge 2 commits into
Open
jaideepkrishna2008-ui wants to merge 2 commits into
jaideepkrishna2008-ui wants to merge 2 commits into
Conversation
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
requested review from
ramya-stripe
and removed request for
a team
November 15, 2026 14:05
This branch has not been deployed
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.
Why?
Fixes #1991.
WebhookSignature.verify_headerraised an unhandledTypeErrorwhen av1value in theStripe-Signatureheader contained a non-ASCII character (e.g.,t=1,v1=é), instead of raisingSignatureVerificationError. This caused webhook handlers that catchValueErrorandSignatureVerificationErrorto fail with unhandled 500 errors on invalid external requests.secure_compareinstripe/_util.pypassed both string arguments directly to standard libraryhmac.compare_digest, which only supports ASCII strings.What?
secure_compareinstripe/_util.pyto gracefully catchTypeErrorand fall back to comparing UTF-8 encoded bytes withhmac.compare_digestin constant time.test_raise_on_non_ascii_signature_in_headerintests/test_webhook.pyverifying that non-ASCII signatures raiseSignatureVerificationError..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.