A class generated by the Generator in JHipster before 6.3.0 and JHipster Kotlin through 1.1.0 produces code that uses an insecure source of…
mitre·CWE-338·Published 2019-09-13
A class generated by the Generator in JHipster before 6.3.0 and JHipster Kotlin through 1.1.0 produces code that uses an insecure source of randomness (apache.commons.lang3 RandomStringUtils). This allows an attacker (if able to obtain their own password reset URL) to compute the value for all other password resets for other accounts, thus allowing privilege escalation or account takeover.
A class generated by the Generator in JHipster before 6.3.0 and JHipster Kotlin through 1.1.0 produces code that uses an insecure source of randomness (apache.commons.lang3 RandomStringUtils). This allows an attacker (if able to obtain their own password reset URL) to compute the value for all other password resets for other accounts, thus allowing privilege escalation or account takeover.
JHipster Kotlin is using an insecure source of randomness to generate all of its random values. JHipster Kotlin relies upon apache commons lang3 `RandomStringUtils`. From the documentation: > Caveat: Instances of Random, upon which the implementation of this class relies, are not cryptographically secure. > \- https://commons.apache.org/proper/commons-lang/javadocs/api-3.9/org/apache/commons/lang3/RandomStringUtils.html Here are the examples of JHipster Kotlin's use of an insecure PRNG: https://github.com/jhipster/jhipster-kotlin/blob/193ae8f13c0be686f9687e78bacfedb144c47d8c/generators/server/templates/src/main/kotlin/package/service/util/RandomUtil.kt.ejs#L32 ## Proof Of Concepts Already Exist There has been a POC of taking one RNG value generated `RandomStringUtils` and reversing it to generate all of the past/future RNG values public since March 3rd, 2018. https://medium.com/@alex91ar/the-java-soothsayer-a-practical-application-for-insecure-randomness-c67b0cd148cd POC Repository: https://github.com/alex91ar/randomstringutils ## Potential Impact Technical All that is required is to get one password reset token from a JHipster Kotlin generated service and using the POC above, you can reverse what all future password reset tokens to be generated by this server. This allows an attacker to pick and choose what account they would like to takeover by sending account password reset requests for targeted accounts. ## Potential Impact Scale Not as large as for the original jhipster project as the kotlin blueprint is not that widely used. ### Patches Update your generated applications to > 1.2.0 ### Workarounds Change the content of `RandomUtil.kt` like this: ```kotlin import java.security.SecureRandom import org.apache.commons.lang3.RandomStringUtils private const val DEF_COUNT = 20 object RandomUtil { private val secureRandom: SecureRandom = SecureRandom() init { secureRandom.nextBytes(byteArrayOf(64.toByte())) } private fun generateRandomAlphanumericString(): String { return RandomStringUtils.random(DEF_COUNT, 0, 0, true, true, null, secureRandom) } /** * Generate a password. * * @return the generated password. */ fun generatePassword(): String = generateRandomAlphanumericString() } ``` Important is to exchange **every** call of `RandomStringUtils.randomAlphaNumeric`. ### For more information If you have any questions or comments about this advisory: * Open an issue in [JHipster Kotlin](https://github.com/jhipster/jhipster-kotlin)
JHipster Kotlin is using an insecure source of randomness to generate all of its random values. JHipster Kotlin relies upon apache commons lang3 `RandomStringUtils`. From the documentation: > Caveat: Instances of Random, upon which the implementation of this class relies, are not cryptographically secure. > \- https://commons.apache.org/proper/commons-lang/javadocs/api-3.9/org/apache/commons/lang3/RandomStringUtils.html Here are the examples of JHipster Kotlin's use of an insecure PRNG: https://github.com/jhipster/jhipster-kotlin/blob/193ae8f13c0be686f9687e78bacfedb144c47d8c/generators/server/templates/src/main/kotlin/package/service/util/RandomUtil.kt.ejs#L32 ## Proof Of Concepts Already Exist There has been a POC of taking one RNG value generated `RandomStringUtils` and reversing it to generate all of the past/future RNG values public since March 3rd, 2018. https://medium.com/@alex91ar/the-java-soothsayer-a-practical-application-for-insecure-randomness-c67b0cd148cd POC Repository: https://github.com/alex91ar/randomstringutils ## Potential Impact Technical All that is required is to get one password reset token from a JHipster Kotlin generated service and using the POC above, you can reverse what all future password reset tokens to be generated by this server. This allows an attacker to pick and choose what account they would like to takeover by sending account password reset requests for targeted accounts. ## Potential Impact Scale Not as large as for the original jhipster project as the kotlin blueprint is not that widely used. ### Patches Update your generated applications to > 1.2.0 ### Workarounds Change the content of `RandomUtil.kt` like this: ```kotlin import java.security.SecureRandom import org.apache.commons.lang3.RandomStringUtils private const val DEF_COUNT = 20 object RandomUtil { private val secureRandom: SecureRandom = SecureRandom() init { secureRandom.nextBytes(byteArrayOf(64.toByte())) } private fun generateRandomAlphanumericString(): String { return RandomStringUtils.random(DEF_COUNT, 0, 0, true, true, null, secureRandom) } /** * Generate a password. * * @return the generated password. */ fun generatePassword(): String = generateRandomAlphanumericString() } ``` Important is to exchange **every** call of `RandomStringUtils.randomAlphaNumeric`. ### For more information If you have any questions or comments about this advisory: * Open an issue in [JHipster Kotlin](https://github.com/jhipster/jhipster-kotlin)
Una clase generada mediante el Generator en JHipster versiones anteriores a 6.3.0 y JHipster Kotlin versiones hasta 1.1.0, produce código que utiliza una fuente no segura de aleatoriedad (apache.commons.lang3 RandomStringUtils). Esto permite a un atacante (si es capaz de obtener su propia URL de restablecimiento de contraseña) calcular el valor de todos los demás restablecimientos de contraseña para otras cuentas, permitiendo la escalada de privilegios o la toma de control de la cuenta.
| Version | Type | Source | Base | Exp | Impact | Vector |
|---|---|---|---|---|---|---|
| 2.0 | Primary | NVD | 7.5 | 10.0 | 6.4 | AV:N/AC:L/Au:N/C:P/I:P/A:P |
| 3.1 | Primary | NVD | 9.8 | 3.9 | 5.9 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H |
| 3.1 | Secondary | GHSA | 9.8 | — | — | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H |