Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to access a rawBody in an endpoint #10831

Closed
jesuscovam opened this issue Oct 5, 2023 · 2 comments
Closed

how to access a rawBody in an endpoint #10831

jesuscovam opened this issue Oct 5, 2023 · 2 comments

Comments

@jesuscovam
Copy link

Describe the bug

To validate a request from stripe, I have to provide them the rawBody of the request, but every try throws an error.

Screenshot 2023-10-04 at 5 39 10 p m

I have tried other solutions that I read in other issues that worked for some users but I couldn't make it work

Solution with text: #3384 (comment)

Solution with buffer: #3384 (comment)

I think we have the same error #10339

Reproduction

pnpm dev this sveltekit app repo

have installed the stripe-cli and have an user to test it download stripe cli

do the login for the stripe with stripe login

connect the cli with the server stripe listen --forward-to http://localhost:5173/api/with-buffer

in a another terminal run a stripe event, the one I use is payment.intent stripe trigger payment_intent.succeeded

you can also test the other method with stripe listen --forward-to http://localhost:5173/api/with-text

Logs

StripeSignatureVerificationError: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?

System Info

System:
    OS: macOS 14.0
    CPU: (8) arm64 Apple M1
    Memory: 45.23 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
    Yarn: 1.22.10 - /opt/homebrew/bin/yarn
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm
    pnpm: 8.8.0 - ~/Library/pnpm/pnpm
    Watchman: 2023.05.22.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 117.0.5938.149
    Safari: 17.0
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0
    @sveltejs/adapter-vercel: ^3.0.3 => 3.0.3
    @sveltejs/kit: ^1.20.4 => 1.25.1
    svelte: ^4.0.5 => 4.2.1
    vite: ^4.4.2 => 4.4.10

Severity

blocking an upgrade

Additional Information

No response

@david-plugge
Copy link
Contributor

Not sure but request.body should be the raw body that stripe expects. No need to call request.text() or similar.

@eltigerchino
Copy link
Member

eltigerchino commented Oct 5, 2023

Based on https://github.com/stripe/stripe-node/blob/465c7f326daaa626028efff4c211739e1261921c/src/Webhooks.ts#L29 we want a string or Uint8Array. However this user mentions there are issues with request.text().

Can you try

// Uint8Array
const webhookPayload = new Uint8Array(await request.arrayBuffer());

https://stripe.com/docs/identity/handle-verification-outcomes#create-webhook

or

// base64 string
const webhookPayload = (new Buffer(await request.arrayBuffer())).toString('base64');

@sveltejs sveltejs locked and limited conversation to collaborators Oct 5, 2023
@eltigerchino eltigerchino converted this issue into discussion #10832 Oct 5, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants