Firefly's verify_access_token() function does a byte-by-byte comparison of HMAC values.
The verify_access_token() function compares HMAC signatures using a byte-by-byte equality check that exits early on mismatch, creating a timing side channel. An attacker could measure response times to guess the correct signature and forge a valid access token without knowing the HMAC key.
Originally disclosed on HackerOne
- Triaged in 9 days
- Fixed in 11 days
- Disclosed after 23 days
Dear Yelp bug bounty team,
Summary
Firefly is vulnerable to timing attacks, because the verify_access_token() function performs a byte-by-byte comparison, which terminates early when two characters do not match.
Timing attacks are a type of side channel attack where one can discover valuable information by recording the time it takes for a cryptographic algorithm to execute.
def verify_access_token(token, key):
"""Verify that the given access token is still valid. Returns true if it is,
false if it either failed to validate or has expired.
A token is a combination of a unix timestamp and a signature"""
t = token[:15]
signature = token[15:]
expected_signature = hmac.new(key, msg=t, digestmod=hashlib.sha1).hexdigest()
return signature == expected_signature and int(t) >= int(time.time())
The == operation does a byte-by-byte comparison of two values and as soon as the two differentiate it terminates. This means the longer it takes until the operation returns, the more correct characters the attacker has guessed. An attacker can then create a valid HMAC without knowing the HMAC key.
How can this be fixed?
You have already imported the hmac module, so this fix simply consists of changing one line.
def verify_access_token(token, key):
"""Verify that the given access token is still valid. Returns true if it is,
false if it either failed to validate or has expired.
A token is a combination of a unix timestamp and a signature"""
t = token[:15]
signature = token[15:]
expected_signature = hmac.new(key, msg=t, digestmod=hashlib.sha1).hexdigest()
- return signature == expected_signature and int(t) >= int(time.time())
+ return hmac.compare_digest(signature, expected_signature) and int(t) >= int(time.time())
The hmac.compare_digest() function does not terminate as soon as two bytes are not the same.
If you would like me to submit a PR to address this issue, I would be more than happy to do that.
Best regards, Ed
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could potentially forge a valid HMAC signature and bypass token validation, though the report does not demonstrate a working exploit.
What the attacker needed
Ability to measure response times
The fix
The comparison should use a constant-time function such as `hmac.compare_digest()` instead of `==`.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program checks a secret code, it often compares characters one by one and stops at the first wrong character. If an attacker can measure how long the check takes, they can guess the code character by character because a longer check means more characters were correct. This is called a timing attack, and it can let someone forge a valid access token without knowing the secret key.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.