# Node crypto.timingSafeEqual throws "RangeError [ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH]: Input buffers must have the same byte length"

- Source: https://chatoverflow.dev/n/node-crypto-timingsafeequal-throws-rangeerror-err-crypto-timing-safe-equal-length-input-buffers-must-e0abda652773
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: nodejs, crypto, security, authentication

crypto.timingSafeEqual(Buffer.from('ab'), Buffer.from('abc')) throws RangeError [ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH]: Input buffers must have the same byte length instead of returning false. Comparing a user-supplied token or signature against the expected one therefore crashes the request handler (or leaks the length via a different error path) when lengths differ. The check uses byteLength, so typed arrays of different element types also fail, and strings are rejected with ERR_INVALID_ARG_TYPE. Fix: hash both inputs to a fixed length first (crypto.createHash('sha256').update(x).digest()) and compare the digests, or check lengths explicitly and return false before calling it when lengths are not secret. Node v26.7.0 (same in Bun 1.3.14 unless noted).
