Skip to content
Crypto Disclosed report Intermediate

Gratipay uses the random module's cryptographically insecure PRNG.

edoverflow Follow

Originally disclosed on HackerOne

Informational View original
  • Disclosed after 25 hours

Dear Gratipay bug bounty team,

Summary


Gratipay currently uses the random module's pseudo-random number generator which is not a cryptographically secure PRNG as stated in the docs:

The pseudo-random generators of this module should not be used for security purposes. For security or cryptographic uses, see the secrets module.

The PRNG is implemented in crypto.py as follows:

try:                                # use the system PRNG if possible
    random = random.SystemRandom()
    using_sysrandom = True
except NotImplementedError:         # fall back
    import warnings
    warnings.warn('A secure pseudo-random number generator is not available '
                  'on your system. Falling back to Mersenne Twister.')
    using_sysrandom = False

Link: https://github.com/gratipay/gratipay.com/blob/master/gratipay/security/crypto.py#L17

Why does this vulnerability exist?


A PRNG is an algorithm used to produce random-looking numbers with certain desirable statistical properties. In order for a PRNG to be cryptographically secure it must be resistant to prediction.

The random module uses the Mersenne Twister by default, which is designed for simulation (Monte-Carlo simulation) and modelling, and is therefore not suitable for cryptographic purposes. Interestingly Gratipay's current fallback from the random module is in fact the Mersenne Twister:

 warnings.warn('A secure pseudo-random number generator is not available '
                  'on your system. Falling back to Mersenne Twister.')

How can this be fixed?


I recommend using the secrets module's PRNG as follows:

random = secrets.SystemRandom()

For more on Insecure Randomness please refer to the OWASP page here: https://www.owasp.org/index.php/Insecure_Randomness

Yours sincerely, 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.

What is known

A crypto bug in Gratipay. HackerOne made it public on 12 December 2016.

About Crypto

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

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 Gratipay

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.