Back

webhook verification fails when payloads has an UTF-8 character

  • 1
  • Self Hosted
  • Webhooks
Kuromory
2 May, 2024, 11:18

I want to validate if the webhook was indeed from Appwrite and it works if the payload does not include special UTF-8 characters like ä,ü,ö etc. But when the payload includes these characters the hash/signature is diffrent...

I use C# for validateing the hash... here is the code:

TypeScript
   string payload;
   using var reader = new StreamReader(context.Request.InputStream, Encoding.UTF8);
   payload = await reader.ReadToEndAsync();
   string signature = _webHookUrl + payload.Trim();
   string hash = Convert.ToBase64String(hMACSHA1.ComputeHash(Encoding.UTF8.GetBytes(signature)));
   if (!context.Request?.Headers?.Get("x-appwrite-webhook-signature")?.Equals(hash) ?? true)
   {
       // Error hash is invalid
       return;
   }
TL;DR
Webhook verification fails when payloads have UTF-8 characters. The hash/signature is different when special characters like ä,ü,ö are present. The issue stems from Unicode encoding. Ensure consistent encoding when calculating hash.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more