Skip to content
Crypto Disclosed report Advanced

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.

edoverflow Follow

Originally disclosed on HackerOne

Informational View original
  • 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.

Python
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.

Diff
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

The original report as published on HackerOne, by edoverflow. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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.

More by edoverflow

View all

27 more disclosed reports, best first.

More from Yelp

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.