CVE-2019-16303: Generator jhipster kotlin Remote Code Execution Vulnerability

CRITICAL
Advisory Identifier: GHSA-j3rh-8vwq-wh84
CVSS 9.8
CWE-338
Published
Advisory Summary

CVE-2019-16303 is a CRITICAL (CVSS 9.8) remote code execution vulnerability (CWE-338: Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)) affecting Generator jhipster kotlin libraries in the npm ecosystem. The issue involves jhipster kotlin using insecure source of randomness `randomstringutils` before v1.2.0. Remediation is available by upgrading affected packages to version 1.2.0.

CVE-2019-16303 at a Glance

CVE Identifier CVE-2019-16303
GHSA Identifier GHSA-j3rh-8vwq-wh84
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-338: Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)
Affected Product Generator jhipster kotlin
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 9.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2019-16303

To remediate this vulnerability, upgrade all affected Generator jhipster kotlin dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

generator-jhipster-kotlin fixed: 1.2.0
npm install generator-jhipster-kotlin@1.2.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls generator-jhipster-kotlin

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2019-16303, inspect your project dependencies using npm:

npm ls generator-jhipster-kotlin

Analyze the terminal output to locate any version of Generator jhipster kotlin in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.2.0), your application is affected.

Note: The npm ls generator-jhipster-kotlin command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-338: Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG), where the product uses a pseudo-random number generator (prng) in a security context, but the prng's algorithm is not cryptographically strong. In Generator jhipster kotlin, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

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)

CVE-2019-16303 Affected Generator jhipster kotlin Versions

1 component(s)
Fixed Versions:
1.2.0
Product / Package Ecosystem Affected Versions Fixed Version
generator-jhipster-kotlin
npm
< 1.2.0
1.2.0

References

GitHub Advisory / Wiki ADVISORY
https://github.com/jhipster/generator-jhipster/security/advisories/GHSA-mwp6-j9wf-968c
GitHub Advisory / Wiki ADVISORY
https://github.com/jhipster/jhipster-kotlin/security/advisories/GHSA-j3rh-8vwq-wh84
NVD — CVE-2019-16303 NVD
https://nvd.nist.gov/vuln/detail/CVE-2019-16303
Generator jhipster kotlin Source Repository REPOSITORY
https://github.com/jhipster/generator-jhipster/issues/10401
Generator jhipster kotlin Source Repository REPOSITORY
https://github.com/jhipster/jhipster-kotlin/issues/183
Security Fix Commit FIX COMMIT
https://github.com/jhipster/generator-jhipster/commit/88448b85fd3e8e49df103f0061359037c2c68ea7
Security Fix Commit FIX COMMIT
https://github.com/jhipster/jhipster-kotlin/commit/deec3587ef7721cf5de5b960d43e9b68beff6193
Generator jhipster kotlin Source Repository REPOSITORY
https://github.com/jhipster/generator-jhipster
lists.apache.org/thread.html/r6d243e... WEB
https://lists.apache.org/thread.html/r6d243e7e3f25daeb242dacf3def411fba32a9388d3ff84918cb28ddd@%3Cissues.commons.apache.org%3E
lists.apache.org/thread.html/rc3f00f... WEB
https://lists.apache.org/thread.html/rc3f00f5d3d2ec0e2381a3b9096d5f5b4d46ec1587ee7e251a3dbb897@%3Cissues.commons.apache.org%3E
lists.apache.org/thread.html/rc87fa3... WEB
https://lists.apache.org/thread.html/rc87fa35a48b5d70b06af6fb81785ed82e82686eb83307aae6d250dc9@%3Cissues.commons.apache.org%3E
snyk.io/vuln/snyk-js-genera... WEB
https://snyk.io/vuln/SNYK-JS-GENERATORJHIPSTER-466980
www.jhipster.tech/2019/09/13/jhipster... WEB
https://www.jhipster.tech/2019/09/13/jhipster-release-6.3.0.html
www.npmjs.com/advisories/1187 WEB
https://www.npmjs.com/advisories/1187
www.npmjs.com/advisories/1188 WEB
https://www.npmjs.com/advisories/1188

Frequently Asked Questions

What is CVE-2019-16303?
CVE-2019-16303 is a security vulnerability in Generator jhipster kotlin involving JHipster Kotlin using insecure source of randomness `RandomStringUtils` before v1.2.0 under CWE-338: Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG).
Which Generator jhipster kotlin versions are affected?
Affected versions include releases prior to 1.2.0 across affected packages: generator-jhipster-kotlin.
What version fixes CVE-2019-16303?
Upgrading to 1.2.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is generator-jhipster-kotlin affected?
Yes, generator-jhipster-kotlin is affected in releases prior to 1.2.0. Upgrade your dependency to 1.2.0 or later.
What is the CVSS score of CVE-2019-16303?
CVE-2019-16303 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2019-16303?
CVE-2019-16303 is classified under CWE-338: Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG) (The product uses a Pseudo-Random Number Generator (PRNG) in a security context, but the PRNG's algorithm is not cryptographically strong.).
How can I check npm dependencies for CVE-2019-16303?
Run the dependency tree command: 'npm ls generator-jhipster-kotlin'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-j3rh-8vwq-wh84",
  "modified" : "2023-01-20T18:53:25Z",
  "published" : "2020-06-26T16:48:13Z",
  "aliases" : [ "CVE-2019-16303" ],
  "summary" : "JHipster Kotlin using insecure source of randomness `RandomStringUtils` before v1.2.0",
  "details" : "JHipster Kotlin is using an insecure source of randomness to generate all of its random values. JHipster Kotlin relies upon apache commons lang3 `RandomStringUtils`.\n\nFrom the documentation:\n\n> Caveat: Instances of Random, upon which the implementation of this class relies, are not cryptographically secure.\n> \\- https://commons.apache.org/proper/commons-lang/javadocs/api-3.9/org/apache/commons/lang3/RandomStringUtils.html\n\nHere are the examples of JHipster Kotlin's use of an insecure PRNG:\n\nhttps://github.com/jhipster/jhipster-kotlin/blob/193ae8f13c0be686f9687e78bacfedb144c47d8c/generators/server/templates/src/main/kotlin/package/service/util/RandomUtil.kt.ejs#L32\n\n## Proof Of Concepts Already Exist\n\nThere 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.\n\nhttps://medium.com/@alex91ar/the-java-soothsayer-a-practical-application-for-insecure-randomness-c67b0cd148cd\n\nPOC Repository: https://github.com/alex91ar/randomstringutils\n\n\n## Potential Impact Technical\n\nAll 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.\n\n## Potential Impact Scale\n\nNot as large as for the original jhipster project as the kotlin blueprint is not that widely used.\n\n### Patches\n\nUpdate your generated applications to > 1.2.0\n\n### Workarounds\n\nChange the content of `RandomUtil.kt` like this:\n\n```kotlin\nimport java.security.SecureRandom\nimport org.apache.commons.lang3.RandomStringUtils\n\nprivate const val DEF_COUNT = 20\n\nobject RandomUtil {\n    private val secureRandom: SecureRandom = SecureRandom()\n\n    init {\n        secureRandom.nextBytes(byteArrayOf(64.toByte()))\n    }\n\n    private fun generateRandomAlphanumericString(): String {\n        return RandomStringUtils.random(DEF_COUNT, 0, 0, true, true, null, secureRandom)\n    }\n\n    /**\n    * Generate a password.\n    *\n    * @return the generated password.\n    */\n    fun generatePassword(): String = generateRandomAlphanumericString()\n}\n```\n\nImportant is to exchange **every** call of `RandomStringUtils.randomAlphaNumeric`.\n\n\n\n### For more information\n\nIf you have any questions or comments about this advisory:\n* Open an issue in [JHipster Kotlin](https://github.com/jhipster/jhipster-kotlin)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "generator-jhipster-kotlin"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.2.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/jhipster/generator-jhipster/security/advisories/GHSA-mwp6-j9wf-968c"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jhipster/jhipster-kotlin/security/advisories/GHSA-j3rh-8vwq-wh84"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2019-16303"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jhipster/generator-jhipster/issues/10401"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jhipster/jhipster-kotlin/issues/183"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jhipster/generator-jhipster/commit/88448b85fd3e8e49df103f0061359037c2c68ea7"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jhipster/jhipster-kotlin/commit/deec3587ef7721cf5de5b960d43e9b68beff6193"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/jhipster/generator-jhipster"
  }, {
    "type" : "WEB",
    "url" : "https://lists.apache.org/thread.html/r6d243e7e3f25daeb242dacf3def411fba32a9388d3ff84918cb28ddd@%3Cissues.commons.apache.org%3E"
  }, {
    "type" : "WEB",
    "url" : "https://lists.apache.org/thread.html/rc3f00f5d3d2ec0e2381a3b9096d5f5b4d46ec1587ee7e251a3dbb897@%3Cissues.commons.apache.org%3E"
  }, {
    "type" : "WEB",
    "url" : "https://lists.apache.org/thread.html/rc87fa35a48b5d70b06af6fb81785ed82e82686eb83307aae6d250dc9@%3Cissues.commons.apache.org%3E"
  }, {
    "type" : "WEB",
    "url" : "https://snyk.io/vuln/SNYK-JS-GENERATORJHIPSTER-466980"
  }, {
    "type" : "WEB",
    "url" : "https://www.jhipster.tech/2019/09/13/jhipster-release-6.3.0.html"
  }, {
    "type" : "WEB",
    "url" : "https://www.npmjs.com/advisories/1187"
  }, {
    "type" : "WEB",
    "url" : "https://www.npmjs.com/advisories/1188"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-338" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2020-06-26T16:47:54Z",
    "nvd_published_at" : "2019-09-14T00:15:00Z"
  }
}