5 months ago
Hi i am using nest js for backend , stripe webhook to trigger the task
but the server is logging
"Webhook signature verification failed. Webhook payload must be provided as a string or a Buffer (https://nodejs.org/api/buffer.html) instance representing the raw request body.Payload was provided as a parsed JavaScript object instead.
Signature verification is impossible without access to the original signed material. "
i am also logging more info
Body type: object
Is Buffer: false
Body length: undefined
Has signature header: true
Original URL: /webhooks/stripe
can you help me how to resolve this issue?
Pinned Solution
5 months ago
Well would you look at that. Found a tutorial on this!
https://manuel-heidrich.dev/blog/how-to-access-the-raw-body-of-a-stripe-webhook-request-in-nestjs/
Let me know if this helps!
6 Replies
5 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
5 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • 5 months ago
5 months ago
Hey there! It looks like raw body is what you're looking for!
https://docs.nestjs.com/faq/raw-body
> One of the most common use-case for having access to the raw request body is performing webhook signature verifications. Usually to perform webhook signature validations the unserialized request body is required to calculate an HMAC hash.
noahd
Hey there! It looks like raw body is what you're looking for! https://docs.nestjs.com/faq/raw-body> One of the most common use-case for having access to the raw request body is performing webhook signature verifications. Usually to perform webhook signature validations the unserialized request body is required to calculate an HMAC hash.
5 months ago
thankyou for reply
i tried this
@Post()
@HttpCode(200)
async handleEvent(@Req() req: RawBodyRequest<Request>, @Res() res: Response) {...
console.log('=== WEBHOOK DEBUG INFO ===');
console.log('Body type:', typeof req.body);
console.log('Raw Body type:', typeof req.rawBody);
console.log('Raw Body is Buffer:', Buffer.isBuffer(req.rawBody));
console.log('Raw Body length:', req.rawBody?.length); try {
event = this.stripe.webhooks.constructEvent(
req.rawBody,
sig,
this.webhookSecret,
);but its not working , these are the logs from backend service
=== WEBHOOK DEBUG INFO ===
Body type: object
Raw Body type: object
Raw Body is Buffer: true
Raw Body length: 2576
Webhook signature verification failed. No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
If a webhook request is being forwarded by a third-party tool, ensure that the exact request body, including JSON formatting and new line style, is preserved.
5 months ago
Are you able to provide the part of your code where you are handling the request? Curious how you are accessing the body
5 months ago
Well would you look at that. Found a tutorial on this!
https://manuel-heidrich.dev/blog/how-to-access-the-raw-body-of-a-stripe-webhook-request-in-nestjs/
Let me know if this helps!
noahd
Well would you look at that. Found a tutorial on this! https://manuel-heidrich.dev/blog/how-to-access-the-raw-body-of-a-stripe-webhook-request-in-nestjs/Let me know if this helps!
5 months ago
Thankyou , this resolved my issue .
Status changed to Solved brody • 5 months ago
