Skip to content
Info disclosure Disclosed report Advanced

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:

https://github.com/doorkeeper-gem/doorkeeper/blob/cba795448032e6f99298e71b43645b2ed4c17de4/lib/doorkeeper/models/concerns/secret_storable.rb#L94

Implementation of SHA512 + pepper.

https://gist.github.com/benaubin/863b2bfb7f12c535e94c60dacfd25d07

References

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.

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

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.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.