1 Timing Attack Mechanics
A timing side-channel attack exploits the fact that standard string comparison functions return early when they find a mismatch — the more matching characters, the longer the comparison takes. An attacker who can measure response time can infer secret values one character at a time.
Vulnerable HMAC verification (Python):
def verify_token(user_token, expected_token):
# == does early exit: stops at first mismatch
return user_token == expected_token
# If user sends "aXXXXXXXX..." and the real token starts with "a",
# the comparison takes slightly longer — the "a" matches!Attack scenario: An attacker sends thousands of API webhook requests with different HMAC signature values. By measuring response times statistically, they can determine the correct signature byte-by-byte without knowing the secret.
This requires very precise timing measurements, but network timing attacks have been demonstrated in practice with enough requests to average out noise.