Skip to content

fix(ts): return false on truncated webhook signatures - #145

Open
ron-42 wants to merge 1 commit into
inkbox-ai:mainfrom
ron-42:fix/ts-verify-webhook-truncated-sig
Open

fix(ts): return false on truncated webhook signatures#145
ron-42 wants to merge 1 commit into
inkbox-ai:mainfrom
ron-42:fix/ts-verify-webhook-truncated-sig

Conversation

@ron-42

@ron-42 ron-42 commented Aug 9, 2026

Copy link
Copy Markdown

Fixes #144

The bug

verifyWebhook calls Node's timingSafeEqual with no length check. When X-Inkbox-Signature is sha256= plus a digest that is not exactly 64 hex characters, verification throws:

RangeError: Input buffers must have the same byte length

instead of returning false.

Python (hmac.compare_digest) and Rust (explicit length guard) already return false. A TypeScript webhook receiver that treats verifyWebhook as a boolean check and does not wrap it in try/catch will 500 on malformed or attack traffic instead of rejecting with 403.

Existing tests only covered equal-length failures, so CI stayed green.

The fix

One length guard before timingSafeEqual, matching Python/Rust. One regression test for sha256=abcd.

if (expected.length !== received.length) return false;
return timingSafeEqual(Buffer.from(expected), Buffer.from(received));

CLI and any other caller already go through this shared helper — no second patch.

Verification

npm test -- tests/signing-keys.test.ts
# 13 passed

Manual cases that previously threw now return false: truncated, empty digest, odd length, too-long. Valid signatures and wrong-but-same-length digests unchanged.

timingSafeEqual throws RangeError on length mismatch;
Python/Rust return false. Malformed traffic can 500 a receiver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(sdk/ts): TypeScript verifyWebhook throws on truncated signatures

1 participant