Secrets compared with === (timing-unsafe token and signature checks)

Last updated November 11, 2026
Steps
- Search the code for secret checks that use ===, ==, !==, .equals() or startsWith(): API keys, webhook signatures, cron secrets, invite or magic-link tokens, password-reset tokens, admin passcodes and HMAC digests.
- In Node.js, compare with crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b)). It throws if the two buffers have different byte lengths, so first hash both values to a fixed length (for example SHA-256 of each) or check lengths and return the same generic failure.
- In Python, use hmac.compare_digest(a, b) instead of ==. In other languages, use the constant-time compare from your crypto library.
- Prefer the provider’s official verification helper where one exists (for example a payment or messaging SDK’s webhook-signature function) instead of building and comparing the signature yourself.
- For passwords, never compare raw strings at all: store a slow hash (bcrypt, scrypt or Argon2) and use the library’s verify function.
- Return the same error and status code for every failed check, and add rate limiting to the endpoint so an attacker cannot make thousands of timed guesses.
- Retest: confirm valid secrets still pass, wrong ones fail with the same generic error, and wrong-length inputs do not crash the route.
Why it matters
MITRE’s CWE-208 describes operations that take different amounts of time in a way an attacker can observe, revealing security-relevant information such as whether part of a check succeeded. Its observed examples include CVE-2019-10071, a Java framework that compared HMAC signatures with String.equals() instead of a constant-time algorithm. Node.js documents crypto.timingSafeEqual as a constant-time comparison suitable for HMAC digests and secret values like authentication cookies, and Python’s hmac docs recommend compare_digest() instead of == to reduce timing-attack risk. Network noise makes these attacks harder over the internet, but the fix is one line, and rate limiting closes the remaining gap. This page is for checking and fixing your own app.
Sources
MITRE CWE-208: Observable Timing Discrepancy — https://cwe.mitre.org/data/definitions/208.html
Node.js docs: crypto.timingSafeEqual(a, b) — https://nodejs.org/api/crypto.html
Python docs: hmac.compare_digest — https://docs.python.org/3/library/hmac.html
Checked at the source on November 11, 2026.
Related patterns
- Stripe webhooks not verified
- Cron and webhook-style job endpoints anyone can trigger
- JWTs decoded but never verified
- Tokens and IDs generated with Math.random()
- Password reset flows that leak accounts or trust the Host header
- Passwords stored in plain text or with fast hashes
- No rate limiting on login, signup or AI endpoints
Found a problem you'd rather not fix yourself?
Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.
Get it fixed by StorenTechVibe Security Weekly
One email a week with new failure patterns and how to fix them.
By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.