Skip to content
Crypto Disclosed report Advanced

Backport bug 767623 to BMO: Use HMAC to generate tokens and sensitive graph filenames

Bugzilla's CSRF tokens are generated using MD5 over concatenated values including a secret, which is cryptographically weak. An attacker might exploit this to reuse expired tokens or forge tokens for other users, though the report notes exploitation is currently very difficult.

Wladimir Palant Follow

Originally disclosed on Mozilla

  • Fixed in 4 days
  • Paid in 13 days
  • Disclosed after 4 days
Text
A note up front: from what I can tell, exploiting this issue is currently very difficult. But even if that's the case, future code additions might open up vulnerabilities by relying on this code to work properly.

Bugzilla's CSRF tokens are currently generated as MD5 checksums over a number of values concatenated with asterisks (see Bugzilla::Token::issue_hash_token):

> MD5(<time>*<secret>*<userid>*<param1>*<param2>)

This is obviously the wrong way to do it. Not only is MD5 considered broken, HMAC is the proper way of hashing data along with a secret.

As to how to exploit this weakness, figuring this out takes a crypto expert which I'm not. My research indicated three potential scenarios however:

1. A length extension attack is easy to perform. However, it will only give you another valid CSRF token for the same user ID, nothing you couldn't get by other means. It will also allow manipulating token parameters. However, all relevant code will currently validate these parameters independently of the token itself, so there is nothing to gain from that either.

2. Inserting one more block at the beginning of the data, thus prepending the timestamp by 64 bytes. It would allow reusing expired tokens, e.g. if SSL traffic is intercepted and decoded later: the Bugzilla::Token::check_hash_token function doesn't validate the timestamp, the byte sequence merely needs to start with a large enough number and the token won't be considered expired. Executing this attack without changing the hash value requires a preimage attack however - while a preimage attack on MD5 has been published, it's still only a theoretical possibility at this point.

3. Generating a collision for the data block containing the user ID, by manipulating token generation parameters (param2 can be set to an arbitrary value in some cases). MD5 collisions differ only in a few bits, so you might get another valid CSRF token for somebody else's user ID. How feasible this attack is given that part of the data block (first 11 bytes) is the unknown site secret isn't something I can tell.

The obvious solution would be using HMAC-SHA256 for these tokens, this approach is already taken elsewhere in the same module.

The original report as published on Mozilla's Bugzilla, by Wladimir Palant. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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

Root cause

Likely the use of MD5 instead of HMAC for generating CSRF tokens, which is cryptographically weak and allows potential attacks like length extension or collision.

Impact

An attacker could potentially reuse expired tokens or forge tokens for other users, but the report states that exploiting this is currently very difficult and no practical attack is demonstrated.

What the attacker needed

Access to a valid token; crypto expertise to exploit

The fix

The obvious solution is to use HMAC-SHA256 for these tokens, as is already done elsewhere in the same module.

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.

Bugzilla uses a checksum (like a fingerprint) made with an old algorithm called MD5 to create security tokens that prevent cross-site request forgery. MD5 is no longer considered safe because it has known weaknesses. The report suggests replacing it with a stronger method called HMAC, which is designed for this purpose.

What is Crypto?

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

More by Wladimir Palant

View all

30 more disclosed reports, best first.

More from Mozilla

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.