CVE-2023-34109 (published 2023-06-07T18:15Z)

zxcvbn-ts is an open source password strength estimator written in typescript. This vulnerability affects users running on the nodeJS platform which are using the second argument of the zxcvbn function. It can result in an unbounded resource consumption as the user inputs array is extended with every function call. Browsers are impacted, too but a single user need to do a lot of input changes so that it affects the browser, while the node process gets the inputs of every user of a platform and can be killed that way. This problem has been patched in version 3.0.2. Users are advised to upgrade. Users unable to upgrade should stop using the second argument of the zxcvbn function and use the zxcvbnOptions.setOptions function.

CVSS v3 base score: 7.5, HIGH (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H)

Weakness information:
cwe_id: CWE-400
cwe_name: Uncontrolled Resource Consumption
description: The product does not properly control the allocation and maintenance of a limited resource, thereby enabling an actor to influence the amount of resources consumed, eventually leading to the exhaustion of available resources.
extended_description: 
            Limited resources include memory, file system storage, database connection pool entries, and CPU. If an attacker can trigger the allocation of these limited resources, but the number or size of the resources is not controlled, then the attacker could cause a denial of service that consumes all available resources. This would prevent valid users from accessing the product, and it could potentially have an impact on the surrounding environment. For example, a memory exhaustion attack against an application could slow down the application as well as its host operating system.
            There are at least three distinct scenarios which can commonly lead to resource exhaustion:
               
                  Lack of throttling for the number of allocated resources
                  Losing all references to a resource before reaching the shutdown stage
                  Not closing/returning a resource after processing
               
            Resource exhaustion problems are often result due to an incorrect implementation of the following situations:
               
                  Error conditions and other exceptional circumstances.
                  Confusion over which part of the program is responsible for releasing the resource.
               
         
         

Fix information:
repo_url: https://github.com/zxcvbn-ts/zxcvbn
commit_details: repo_url: https://github.com/zxcvbn-ts/zxcvbn
author: MrWook
author_date: 2023-06-06 15:05:13+02:00
msg: fix(user-inputs): resolve memory leak with user inputs on the fly
repository: repo_url: https://github.com/zxcvbn-ts/zxcvbn
repo_name: zxcvbn-ts/zxcvbn
description: Low-Budget Password Strength Estimation
repo_language: TypeScript
owner: zxcvbn-ts
file_changes: filename: Options.ts
change_type: ModificationType.MODIFY
diff: @@ -112,16 +112,16 @@ export class Options {
     const rankedDictionaries: RankedDictionaries = {}
     const rankedDictionariesMaxWorkSize: Record<string, number> = {}
     Object.keys(this.dictionary).forEach((name) => {
-      rankedDictionaries[name] = this.getRankedDictionary(name)
+      rankedDictionaries[name] = buildRankedDictionary(this.dictionary[name])
       rankedDictionariesMaxWorkSize[name] =
-        this.getRankedDictionariesMaxWordSize(name)
+        this.getRankedDictionariesMaxWordSize(this.dictionary[name])
     })
     this.rankedDictionaries = rankedDictionaries
     this.rankedDictionariesMaxWordSize = rankedDictionariesMaxWorkSize
   }
 
-  getRankedDictionariesMaxWordSize(name: string) {
-    const data = this.dictionary[name].map((el) => {
+  getRankedDictionariesMaxWordSize(list: (string | number)[]) {
+    const data = list.map((el) => {
       if (typeof el !== 'string') {
         return el.toString().length
       }
@@ -135,40 +135,33 @@ export class Options {
     return data.reduce((a, b) => Math.max(a, b), -Infinity)
   }
 
-  getRankedDictionary(name: string) {
-    const list = this.dictionary[name]
-    if (name === 'userInputs') {
-      const sanitizedInputs: string[] = []
-
-      list.forEach((input: string | number | boolean) => {
-        const inputType = typeof input
-        if (
-          inputType === 'string' ||
-          inputType === 'number' ||
-          inputType === 'boolean'
-        ) {
-          sanitizedInputs.push(input.toString().toLowerCase())
-        }
-      })
-
-      return buildRankedDictionary(sanitizedInputs)
-    }
-    return buildRankedDictionary(list)
+  buildSanitizedRankedDictionary(list: (string | number)[]) {
+    const sanitizedInputs: string[] = []
+
+    list.forEach((input: string | number | boolean) => {
+      const inputType = typeof input
+      if (
+        inputType === 'string' ||
+        inputType === 'number' ||
+        inputType === 'boolean'
+      ) {
+        sanitizedInputs.push(input.toString().toLowerCase())
+      }
+    })
+
+    return buildRankedDictionary(sanitizedInputs)
   }
 
   extendUserInputsDictionary(dictionary: (string | number)[]) {
-    if (this.dictionary.userInputs) {
-      this.dictionary.userInputs = [
-        ...this.dictionary.userInputs,
-        ...dictionary,
-      ]
-    } else {
-      this.dictionary.userInputs = dictionary
+    if (!this.dictionary.userInputs) {
+      this.dictionary.userInputs = []
     }
 
-    this.rankedDictionaries.userInputs = this.getRankedDictionary('userInputs')
+    const newList = [...this.dictionary.userInputs, ...dictionary]
+    this.rankedDictionaries.userInputs =
+      this.buildSanitizedRankedDictionary(newList)
     this.rankedDictionariesMaxWordSize.userInputs =
-      this.getRankedDictionariesMaxWordSize('userInputs')
+      this.getRankedDictionariesMaxWordSize(newList)
   }
 
   public addMatcher(name: string, matcher: Matcher) {

programming_language: TypeScript