CVE-2023-46133: Use of a Broken or Risky Cryptographic Algorithm (CWE-327)
value: CryptoES is a cryptography algorithms library compatible with ES6 and TypeScript. Prior to version 2.1.0, CryptoES PBKDF2 is 1,000 times weaker than originally specified in 1993, and at least 1,300,000 times weaker than current industry standard. This is because it both defaults to SHA1, a cryptographic hash algorithm considered insecure since at least 2005, and defaults to one single iteration, a 'strength' or 'difficulty' value specified at 1,000 when specified in 1993. PBKDF2 relies on iteration count as a countermeasure to preimage and collision attacks. If used to protect passwords, the impact is high. If used to generate signatures, the impact is high. Version 2.1.0 contains a patch for this issue. As a workaround, configure CryptoES to use SHA256 with at least 250,000 iterations.
CWE description: The product uses a broken or risky cryptographic algorithm or protocol.
CVSS v3 base score: 9.1
Published: 2023-10-25T21:15Z
Repository: https://github.com/entronad/crypto-es
Language: JSON
Files changed: CHANGELOG.md, __tests__/debug.js, __tests__/pbkdf2.test.ts, lib/pbkdf2.js, package-lock.json, package.json
Commit date: 2023-10-24 22:53:30 +0800
Commit message: v2.1.0

Diff: diff --git a/CHANGELOG.md b/CHANGELOG.md
index de7ec79..24907ad 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
+## 2.1.0
+
+**2023-10-24**
+
+- Change pbkdf2 default params to enhance security: https://github.com/entronad/crypto-es/security/advisories/GHSA-mpj8-q39x-wq5h
+
 ## 2.0.4
 
 **2023-07-25**
 
 - Declare no side effects for tree shaking: https://github.com/entronad/crypto-es/pull/37
diff --git a/__tests__/debug.js b/__tests__/debug.js
index ac1c9c1..e4e7ea6 100644
--- a/__tests__/debug.js
+++ b/__tests__/debug.js
@@ -1,6 +1,11 @@
 import C from '../lib/index.js';
 
-const data = {};
-data.saltA = C.enc.Hex.parse('AA00000000000000');
-const encryptedA = C.Blowfish.encrypt('Test', 'pass', { salt: data.saltA, hasher: C.algo.SHA256 }).toString();
-console.log(encryptedA);
\ No newline at end of file
+// const data = {};
+// data.saltA = C.enc.Hex.parse('AA00000000000000');
+// const encryptedA = C.Blowfish.encrypt('Test', 'pass', { salt: data.saltA, hasher: C.algo.SHA256 }).toString();
+// console.log(encryptedA);
+
+const start = (new Date()).getTime();
+console.log(C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 128 / 32}).toString());
+const end = (new Date()).getTime();
+console.log(end - start);
diff --git a/__tests__/pbkdf2.test.ts b/__tests__/pbkdf2.test.ts
index 249cb0e..03efbc3 100644
--- a/__tests__/pbkdf2.test.ts
+++ b/__tests__/pbkdf2.test.ts
@@ -2,76 +2,76 @@
 import C from '../lib/index.js';
 
 describe('pbkdf2', () => {
   it('keySize 128', () => {
     expect(C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 128 / 32 }).toString())
-      .toBe('cdedb5281bb2f801565a1122b2563515');
+      .toBe('62929ab995a1111c75c37bc562261ea3');
   });
 
   it('keySize 256', () => {
     expect(C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 256 / 32 }).toString())
-      .toBe('cdedb5281bb2f801565a1122b25635150ad1f7a04bb9f3a333ecc0e2e1f70837');
+      .toBe('62929ab995a1111c75c37bc562261ea3fb3cdc7e725c4ca87c03cec5bb7663e1');
   });
 
   it('keySize 128 iterations 2', () => {
     expect(C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 128 / 32, iterations: 2 }).toString())
-      .toBe('01dbee7f4a9e243e988b62c73cda935d');
+      .toBe('262fb72ea65b44ab5ceba7f8c8bfa781');
   });
 
   it('keySize 256 iterations 2', () => {
     expect(C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 256 / 32, iterations: 2 }).toString())
-      .toBe('01dbee7f4a9e243e988b62c73cda935da05378b93244ec8f48a99e61ad799d86');
+      .toBe('262fb72ea65b44ab5ceba7f8c8bfa7815ff9939204eb7357a59a75877d745777');
   });
 
   it('keySize 128 iterations 1200', () => {
     expect(C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 128 / 32, iterations: 1200 }).toString())
-      .toBe('5c08eb61fdf71e4e4ec3cf6ba1f5512b');
+      .toBe('c76a982415f1acc71dc197273c5b6ada');
   });
 
   it('keySize 256 iterations 1200', () => {
     expect(C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 256 / 32, iterations: 1200 }).toString())
-      .toBe('5c08eb61fdf71e4e4ec3cf6ba1f5512ba7e52ddbc5e5142f708a31e2e62b1e13');
+      .toBe('c76a982415f1acc71dc197273c5b6ada32f62915ed461718aad32843762433fa');
   });
 
   it('keySize 128 iterations 5', () => {
     expect(C.PBKDF2('password', C.enc.Hex.parse('1234567878563412'), { keySize: 128 / 32, iterations: 5 }).toString())
-      .toBe('d1daa78615f287e6a1c8b120d7062a49');
+      .toBe('74e98b2e9eeddaab3113c1efc6d82b07');
   });
 
   it('keySize 256 iterations 5', () => {
     expect(C.PBKDF2('password', C.enc.Hex.parse('1234567878563412'), { keySize: 256 / 32, iterations: 5 }).toString())
-      .toBe('d1daa78615f287e6a1c8b120d7062a493f98d203e6be49a6adf4fa574b6e64ee');
+      .toBe('74e98b2e9eeddaab3113c1efc6d82b073c4860195b3e0737fa21a4778f376321');
   });
 
   it('keySize 128 iterations 1200 pass phrase equals block size', () => {
     expect(C.PBKDF2('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'pass phrase equals block size', { keySize: 128 / 32, iterations: 1200 }).toString())
-      .toBe('139c30c0966bc32ba55fdbf212530ac9');
+      .toBe('c1dfb29a4d2f2fb67c6f78d074d66367');
   });
 
   it('keySize 256 iterations 1200 pass phrase equals block size', () => {
     expect(C.PBKDF2('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'pass phrase equals block size', { keySize: 256 / 32, iterations: 1200 }).toString())
-      .toBe('139c30c0966bc32ba55fdbf212530ac9c5ec59f1a452f5cc9ad940fea0598ed1');
+      .toBe('c1dfb29a4d2f2fb67c6f78d074d663671e6fd4da1e598572b1fecf256cb7cf61');
   });
 
   it('keySize 128 iterations 1200 pass phrase exceeds block size', () => {
     expect(C.PBKDF2('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'pass phrase exceeds block size', { keySize: 128 / 32, iterations: 1200 }).toString())
-      .toBe('9ccad6d468770cd51b10e6a68721be61');
+      .toBe('22344bc4b6e32675a8090f3ea80be01d');
   });
 
   it('keySize 256 iterations 1200 pass phrase exceeds block size', () => {
     expect(C.PBKDF2('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'pass phrase exceeds block size', { keySize: 256 / 32, iterations: 1200 }).toString())
-      .toBe('9ccad6d468770cd51b10e6a68721be611a8b4d282601db3b36be9246915ec82a');
+      .toBe('22344bc4b6e32675a8090f3ea80be01d5f95126a2cddc3facc4a5e6dca04ec58');
   });
 
   it('keySize 128 iterations 50', () => {
     expect(C.PBKDF2(C.enc.Hex.parse('f09d849e'), 'EXAMPLE.COMpianist', { keySize: 128 / 32, iterations: 50 }).toString())
-      .toBe('6b9cf26d45455a43a5b8bb276a403b39');
+      .toBe('44b0781253db3141ac4174af29325818');
   });
 
   it('keySize 256 iterations 50', () => {
     expect(C.PBKDF2(C.enc.Hex.parse('f09d849e'), 'EXAMPLE.COMpianist', { keySize: 256 / 32, iterations: 50 }).toString())
-      .toBe('6b9cf26d45455a43a5b8bb276a403b39e7fe37a0c41e02c281ff3069e1e94f52');
+      .toBe('44b0781253db3141ac4174af29325818584698d507a79f9879033dec308a2b77');
   });
 
   it('input integrity', () => {
     const password = C.lib.WordArray.create([0x12345678]);
     const salt = C.lib.WordArray.create([0x12345678]);
diff --git a/lib/pbkdf2.js b/lib/pbkdf2.js
index 508cc91..6b9dd51 100644
--- a/lib/pbkdf2.js
+++ b/lib/pbkdf2.js
@@ -1,10 +1,10 @@
 import {
   Base,
   WordArray,
 } from './core.js';
-import { SHA1Algo } from './sha1.js';
+import { SHA256Algo } from './sha256.js';
 import { HMAC } from './hmac.js';
 
 /**
  * Password-Based Key Derivation Function 2 algorithm.
  */
@@ -23,21 +23,24 @@ export class PBKDF2Algo extends Base {
   constructor(cfg) {
     super();
 
     /**
      * Configuration options.
+     * 
+     * The default `hasher` and `interations` is different from CryptoJs to enhance security:
+     * https://github.com/entronad/crypto-es/security/advisories/GHSA-mpj8-q39x-wq5h
      *
      * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
-     * @property {Hasher} hasher The hasher to use. Default: SHA1
-     * @property {number} iterations The number of iterations to perform. Default: 1
+     * @property {Hasher} hasher The hasher to use. Default: SHA256
+     * @property {number} iterations The number of iterations to perform. Default: 250000
      */
     this.cfg = Object.assign(
       new Base(),
       {
         keySize: 128 / 32,
-        hasher: SHA1Algo,
-        iterations: 1,
+        hasher: SHA256Algo,
+        iterations: 250000,
       },
       cfg,
     );
   }
 
diff --git a/package-lock.json b/package-lock.json
index 9252416..5db8ee6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3,11 +3,10 @@
   "version": "2.0.4",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
-      "name": "crypto-es",
       "version": "2.0.4",
       "license": "MIT",
       "devDependencies": {
         "@types/jest": "^29.5.2",
         "jest": "29.5.0",
@@ -2292,10 +2291,11 @@
         "@jest/types": "^29.5.0",
         "@types/graceful-fs": "^4.1.3",
         "@types/node": "*",
         "anymatch": "^3.0.3",
         "fb-watchman": "^2.0.0",
+        "fsevents": "^2.3.2",
         "graceful-fs": "^4.2.9",
         "jest-regex-util": "^29.4.3",
         "jest-util": "^29.5.0",
         "jest-worker": "^29.5.0",
         "micromatch": "^4.0.4",
diff --git a/package.json b/package.json
index 85b085b..bbcc238 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,8 @@
 {
   "name": "crypto-es",
-  "version": "2.0.4",
+  "version": "2.1.0",
   "description": "A cryptography algorithms library compatible with ES6 and TypeScript",
   "keywords": [
     "typescript",
     "security",
     "crypto",

Vulnerable code: const data = {};
data.saltA = C.enc.Hex.parse('AA00000000000000');
const encryptedA = C.Blowfish.encrypt('Test', 'pass', { salt: data.saltA, hasher: C.algo.SHA256 }).toString();
console.log(encryptedA);
      .toBe('cdedb5281bb2f801565a1122b2563515');
      .toBe('cdedb5281bb2f801565a1122b25635150ad1f7a04bb9f3a333ecc0e2e1f70837');
      .toBe('01dbee7f4a9e243e988b62c73cda935d');
      .toBe('01dbee7f4a9e243e988b62c73cda935da05378b93244ec8f48a99e61ad799d86');
      .toBe('5c08eb61fdf71e4e4ec3cf6ba1f5512b');
      .toBe('5c08eb61fdf71e4e4ec3cf6ba1f5512ba7e52ddbc5e5142f708a31e2e62b1e13');
      .toBe('d1daa78615f287e6a1c8b120d7062a49');
      .toBe('d1daa78615f287e6a1c8b120d7062a493f98d203e6be49a6adf4fa574b6e64ee');
      .toBe('139c30c0966bc32ba55fdbf212530ac9');
      .toBe('139c30c0966bc32ba55fdbf212530ac9c5ec59f1a452f5cc9ad940fea0598ed1');
      .toBe('9ccad6d468770cd51b10e6a68721be61');
      .toBe('9ccad6d468770cd51b10e6a68721be611a8b4d282601db3b36be9246915ec82a');
      .toBe('6b9cf26d45455a43a5b8bb276a403b39');
      .toBe('6b9cf26d45455a43a5b8bb276a403b39e7fe37a0c41e02c281ff3069e1e94f52');
import { SHA1Algo } from './sha1.js';
     * @property {Hasher} hasher The hasher to use. Default: SHA1
     * @property {number} iterations The number of iterations to perform. Default: 1
        hasher: SHA1Algo,
        iterations: 1,
      "name": "crypto-es",
  "version": "2.0.4",
Fixed code: ## 2.1.0

**2023-10-24**

- Change pbkdf2 default params to enhance security: https://github.com/entronad/crypto-es/security/advisories/GHSA-mpj8-q39x-wq5h

// const data = {};
// data.saltA = C.enc.Hex.parse('AA00000000000000');
// const encryptedA = C.Blowfish.encrypt('Test', 'pass', { salt: data.saltA, hasher: C.algo.SHA256 }).toString();
// console.log(encryptedA);

const start = (new Date()).getTime();
console.log(C.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 128 / 32}).toString());
const end = (new Date()).getTime();
console.log(end - start);
      .toBe('62929ab995a1111c75c37bc562261ea3');
      .toBe('62929ab995a1111c75c37bc562261ea3fb3cdc7e725c4ca87c03cec5bb7663e1');
      .toBe('262fb72ea65b44ab5ceba7f8c8bfa781');
      .toBe('262fb72ea65b44ab5ceba7f8c8bfa7815ff9939204eb7357a59a75877d745777');
      .toBe('c76a982415f1acc71dc197273c5b6ada');
      .toBe('c76a982415f1acc71dc197273c5b6ada32f62915ed461718aad32843762433fa');
      .toBe('74e98b2e9eeddaab3113c1efc6d82b07');
      .toBe('74e98b2e9eeddaab3113c1efc6d82b073c4860195b3e0737fa21a4778f376321');
      .toBe('c1dfb29a4d2f2fb67c6f78d074d66367');
      .toBe('c1dfb29a4d2f2fb67c6f78d074d663671e6fd4da1e598572b1fecf256cb7cf61');
      .toBe('22344bc4b6e32675a8090f3ea80be01d');
      .toBe('22344bc4b6e32675a8090f3ea80be01d5f95126a2cddc3facc4a5e6dca04ec58');
      .toBe('44b0781253db3141ac4174af29325818');
      .toBe('44b0781253db3141ac4174af29325818584698d507a79f9879033dec308a2b77');
import { SHA256Algo } from './sha256.js';
     * 
     * The default `hasher` and `interations` is different from CryptoJs to enhance security:
     * https://github.com/entronad/crypto-es/security/advisories/GHSA-mpj8-q39x-wq5h
     * @property {Hasher} hasher The hasher to use. Default: SHA256
     * @property {number} iterations The number of iterations to perform. Default: 250000
        hasher: SHA256Algo,
        iterations: 250000,
        "fsevents": "^2.3.2",
  "version": "2.1.0",