timing attack
An attack that works out secret information by measuring how long an operation takes.
Comparing secrets with === can let an attacker recover a token or signature byte by byte.
In more detail
An ordinary string comparison stops at the first differing character, so a response that takes slightly longer reveals that more leading characters were right. Repeating this lets an attacker guess a token one character at a time.
Related terms
- side-channel attack — An attack that learns secrets from how a system behaves, such as timing, power use or error messages, rather than from a flaw in the algorithm itself.
- crypto.timingSafeEqual() — A node:crypto function that compares two Buffers of equal length in a time that does not depend on where they differ.
- strict equality — Comparing two values with === or !==, which never convert either value to another type first, so values of different types are never equal.
- constant-time comparison — Comparing two secret values in a way that always takes the same time, whether they differ in the first byte or the last.
Taught in
- Cryptographic Primitives: node:crypto & Ciphers — Node.js Internals & Backend Services
- Authentication Versus Authorisation — Application Security & Threat Modeling for Engineers
- Broken Object Level Authorization — Application Security & Threat Modeling for Engineers