Hello! I’m trying to use the Stream webhook to receive updates when a uploaded video is ready to stream. I’ve implemented everything following the instructions on https://developers.cloudflare.com/stream/uploading-videos/using-webhooks#verify-webhook-authenticity to verify the webhook authenticity. I’ve tested it uploading videos through the quick upload on the stream dashboard and it worked flawlessly, but when I upload via API, the digest just doesn’t match in the webhook.
After almost a month without any solution we decided to go live without this validation. We’ve tried to reimplement the algorithm using the provided samples in the docs but apparently there is something missing in the documentation itself or in our configuration. It’ll be less secure but it’s the way to go right now.
Hi there, I just ran some tests to try and reproduce your issue of the signature not matching only when you upload via URL. I was not able to reproduce the issue and the signatures matched regardless of how I uploaded the video.
I am including the steps of my test along with the sample code I used in case it helps:
First, you can that the video in my test was uploaded using a URL:
Thanks for the reply! I’ve tried replacing my implementation by yours but still getting a different signature. My code is looking almost identical to the one you provided, but it’s a ExpressJS middleware instead of a Cloudflare Worker.
I’ve created a Cloudflare Worker to test if the problem was on my local environment but apparently it isn’t. I’ve also generated a new webhook secret. The code of my worker is the following:
Can you try getting the raw response body (response.text()) instead of going from a JSON object to the string using JSON.stringify()? JSON.stringify might not return the exact bytes that were returned in the response and a single letter or space being off would cause a mismatch.
For my tests, I used a tool like https://webhook.site/ to manually form the signature source string, verifying it matches and then automating it using code. I would recommend trying something like that to help you debug.
It worked! The problem was the JSON.stringify() from the beginning. I tested it in the worker and also in the Node API and now it matches perfectly.
I think this is not clear in the docs, maybe it’s worth adding a note about this.
Thank you!