First value to compare.
Second value to compare.
True only when both values are byte-for-byte identical.
JavaScript's === on strings returns at the first differing byte. Over many
requests that difference is measurable, and it turns guessing a secret from
an exponential search into a linear one: an attacker who can time responses
recovers the value one byte at a time. This walks the whole buffer regardless
and accumulates the difference with a bitwise OR, so the work done is the
same for a value that matches on no bytes as for one that matches on all but
the last.
Length is the exception and cannot be hidden — a differing length exits immediately. That leaks only the size of the secret, which is not the part worth protecting.
Use this for any value a caller could otherwise guess a byte at a time: API keys, webhook secrets, signatures. Comparing a hash of a value is not a substitute, because the hashes are compared the same way.
Compares two strings without leaking, through how long the comparison took, how much of the expected value the caller already got right.