Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/webhook-missing-sha256.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-server-sdk': patch
---

`WebhookReceiver.receive` reports a token without a `sha256` claim as "sha256 was not found in the token" instead of "sha256 checksum of body does not match", as the Python server SDK does.
14 changes: 14 additions & 0 deletions packages/livekit-server-sdk/src/WebhookReceiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ describe('webhook receiver', () => {
expect(event.room?.name).toBe('mytestroom');
expect(event.event).toBe('room_started');
});

it('rejects a body that does not match the token hash', async () => {
const token = await t.toJwt();
await expect(receiver.receive(`${body} `, token)).rejects.toThrow(
'sha256 checksum of body does not match',
);
});

it('reports a token without a sha256 claim as such', async () => {
const token = await new AccessToken(testApiKey, testSecret).toJwt();
await expect(receiver.receive(body, token)).rejects.toThrow(
'sha256 was not found in the token',
);
});
});

describe('decoding json payload', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/livekit-server-sdk/src/WebhookReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export class WebhookReceiver {
throw new Error('authorization header is empty');
}
const claims = await this.verifier.verify(authHeader, clockTolerance);
if (!claims.sha256) {
throw new Error('sha256 was not found in the token');
}
// confirm sha
const hash = await digest(body);
const hashDecoded = btoa(
Expand Down
Loading