Doorkeeper gem is vulnerable to a timing attack
The Doorkeeper gem performs database lookups on secret tokens using an indexed column, which leaks timing information. An attacker could average many requests to recover OAuth access tokens in linear time.
GitLab
Originally disclosed on GitLab
- Fixed in 3 months
- Disclosed after 3 months
HackerOne report #889331 by benaubin on 2020-06-02, assigned to @dcouture:
Summary
The doorkeeper gem is vulnerable to a timing attack on secret credentials (such as access tokens) similar to Rack's CVE-2019-16782 as it conducts queries using the token on an indexed database column (which makes it possible for an attacker to learn an access token in linear time).
Vulnerability number: GHSA-3hv6-4m9x-jfgj
Workaround
The workaround is quite simple.
Switch the secret storage strategy in Doorkeeper to hash tokens by default when storing in the database.
I'm working on implementing a SHA512 + pepper hashing strategy (faster on 64 bit processors and more secure, using a peppered hash adds a slight additional layer of protection for little overhead), although SHA256 is currently implemented in the library.
hash_token_secrets(it's AccessToken#token value)hash_application_secrets(it's Application#secret value)
Line to change:
Implementation of SHA512 + pepper.
https://gist.github.com/benaubin/863b2bfb7f12c535e94c60dacfd25d07
References
- https://stackoverflow.com/questions/18605294/is-devises-token-authenticatable-secure
- https://stackoverflow.com/questions/26077553/countermeasure-to-timing-attack-against-sql-select-of-hash-token
- http://blog.plataformatec.com.br/2013/08/devise-3-1-now-with-more-secure-defaults/
- https://codahale.com/a-lesson-in-timing-attacks/
- https://gist.github.com/josevalim/fb706b1e933ef01e4fb6
Impact
Even over a network, averaging multiple requests can disclose OAuth access tokens to an attacker in linear (or, potentially, sub-linear time). Rate limiting is not a viable mitigation strategy as the attack could be performed using a botnet, and attack traffic is indistinguishable from normal traffic, at least on the first request.
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 token is used directly in a database query on an indexed column, so the query time varies with the token value, leaking information.
Impact
An attacker could average multiple requests to disclose OAuth access tokens in linear or sub-linear time; rate limiting is not a viable mitigation because the attack can use a botnet and traffic is indistinguishable from normal traffic.
What the attacker needed
Network access to the application; ability to send many requests
The fix
The secret storage strategy should be changed to hash tokens by default when storing them in the database.
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 server checks a secret token, it looks it up in a database. The lookup takes slightly different amounts of time, and an attacker can average many requests to learn the token.
What is Info disclosure?
Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.