From 716db00117f77bf9d251374fdae091863a96ca46 Mon Sep 17 00:00:00 2001 From: Piotr Zmudzinski Date: Fri, 31 Mar 2023 15:00:10 +0200 Subject: [PATCH] fix: change typing of verifyWebhook and patch security issue (#1090) Co-authored-by: Federico Guerinoni <41150432+guerinoni@users.noreply.github.com> --- src/client.ts | 8 +++++++- src/signing.ts | 13 +++++++++---- test/unit/signing.js | 27 +++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 test/unit/signing.js diff --git a/src/client.ts b/src/client.ts index 85d62b8db..e1f2f63a9 100644 --- a/src/client.ts +++ b/src/client.ts @@ -2648,7 +2648,13 @@ export class StreamChat { + describe('CheckSignature', () => { + it('validates correct text body and signature', () => { + const rawBody = Buffer.from(MOCK_TEXT); + expect(CheckSignature(rawBody, MOCK_SECRET, MOCK_TEXT_SHA256)).to.be.true; + }); + + it('validates correct json body and signature', () => { + const rawBody = Buffer.from(JSON.stringify(MOCK_JSON_BODY)); + expect(CheckSignature(rawBody, MOCK_SECRET, MOCK_JSON_SHA256)).to.be.true; + }); + + it('refutes incorrect json body', () => { + const rawBody = Buffer.from(JSON.stringify({ ...MOCK_JSON_BODY, b: 2 })); + expect(CheckSignature(rawBody, MOCK_SECRET, MOCK_JSON_SHA256)).to.be.false; + }); + }); +});