You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
construct_event_without_verification cannot parse an ASCII-8BIT payload #1994
Stripe::Webhook.construct_event_without_verification raises Encoding::UndefinedConversionError on a payload tagged ASCII-8BIT that holds a non-ASCII character. Stripe::Webhook.construct_event accepts the same payload.
Rails tags request.raw_post as ASCII-8BIT, and the doc comment recommends calling construct_event_without_verification after Signature.verify_header with the same payload, so a Rails app hits this on the first accented character.
Cause: _maybe_extract_from_cloud_provider_envelopecallspayload.encode("utf-8"), and a binary string cannot be transcoded. construct_event skips that step and JSON.parse reads the binary string as UTF-8.
To Reproduce
Run the snippet below.
Expected behavior
construct_event_without_verification accepts every payload that construct_event accepts.
Code snippets
require"stripe"payload=%({"id":"evt_1","object":"event","type":"payment_intent.payment_failed","data":{"object":{"name":"Andrés"}}}).bsecret="whsec_test"timestamp=Time.nowheader="t=#{timestamp.to_i},v1=#{Stripe::Webhook::Signature.compute_signature(timestamp,payload,secret)}"Stripe::Webhook.construct_event(payload,header,secret).type# => "payment_intent.payment_failed"Stripe::Webhook.construct_event_without_verification(payload)# Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8
Hi, I'd like to take this. The cause is as you describe: _maybe_extract_from_cloud_provider_envelope calls payload.encode("utf-8"), which can't transcode an ASCII-8BIT string with non-ASCII bytes. The same helper backs StripeClient#parse_event_notification_without_verification, so v2 notifications hit it too. My fix reads binary payloads as UTF-8 (dup.force_encoding), as JSON.parse already does in construct_event, and keeps encode for other encodings like UTF-16. Tests cover a binary v1 event, a binary v2 notification, and a UTF-16 payload. I'll open a PR unless you'd prefer a different approach.
Looks like PRs on this repo are limited to collaborators, so I can't open one. The fix and tests are on my fork if they're useful: idhanth/stripe-ruby@master...idhanth:stripe-ruby:fix-1994-webhook-binary-payload. It's a 9-line change to _maybe_extract_from_cloud_provider_envelope plus three tests, passing on Ruby 3.0 and 3.4 with rubocop and Sorbet clean.
@idhanth Thank you for offering to work on this! We have paused community contributions for the time being largely because we cannot commit to reviewing them in what we'd consider a timely fashion. We'll do our best to take a look but we unfortunately cannot promise anything here.
Activity
idhanth commentedon Oct 15, 2026
Hi, I'd like to take this. The cause is as you describe:
_maybe_extract_from_cloud_provider_envelopecallspayload.encode("utf-8"), which can't transcode an ASCII-8BIT string with non-ASCII bytes. The same helper backsStripeClient#parse_event_notification_without_verification, so v2 notifications hit it too. My fix reads binary payloads as UTF-8 (dup.force_encoding), asJSON.parsealready does inconstruct_event, and keepsencodefor other encodings like UTF-16. Tests cover a binary v1 event, a binary v2 notification, and a UTF-16 payload. I'll open a PR unless you'd prefer a different approach.idhanth commentedon Oct 15, 2026
Looks like PRs on this repo are limited to collaborators, so I can't open one. The fix and tests are on my fork if they're useful: idhanth/stripe-ruby@master...idhanth:stripe-ruby:fix-1994-webhook-binary-payload. It's a 9-line change to
_maybe_extract_from_cloud_provider_envelopeplus three tests, passing on Ruby 3.0 and 3.4 with rubocop and Sorbet clean.zacchua-stripe commentedon Oct 28, 2026
hi @alanlacerda thanks for the bug report!
@idhanth Thank you for offering to work on this! We have paused community contributions for the time being largely because we cannot commit to reviewing them in what we'd consider a timely fashion. We'll do our best to take a look but we unfortunately cannot promise anything here.
jar-stripe commentedon Nov 3, 2026
Hi! I just approved #2011, which should fix this. Once its merged it will show up in the release due out later this month.