CVE-2023-46133 (published 2023-10-25T21:15Z)

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.

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

Weakness information:
cwe_id: CWE-327
cwe_name: Use of a Broken or Risky Cryptographic Algorithm
description: The product uses a broken or risky cryptographic algorithm or protocol.
extended_description: 
	   Cryptographic algorithms are the methods by which data is scrambled to prevent observation or influence by unauthorized actors. Insecure cryptography can be exploited to expose sensitive information, modify data in unexpected ways, spoof identities of other users or devices, or other impacts.
           It is very difficult to produce a secure algorithm, and even high-profile algorithms by accomplished cryptographic experts have been broken. Well-known techniques exist to break or weaken various kinds of cryptography. Accordingly, there are a small number of well-understood and heavily studied algorithms that should be used by most products. Using a non-standard or known-insecure algorithm is dangerous because a determined adversary may be able to break the algorithm and compromise whatever data has been protected.
           Since the state of cryptography advances so rapidly, it is common for an algorithm to be considered "unsafe" even if it was once thought to be strong. This can happen when new attacks are discovered, or if computing power increases so much that the cryptographic algorithm no longer provides the amount of protection that was originally thought.
	   For a number of reasons, this weakness is even more challenging to manage with hardware deployment of cryptographic algorithms as opposed to software implementation. First, if a flaw is discovered with hardware-implemented cryptography, the flaw cannot be fixed in most cases without a recall of the product, because hardware is not easily replaceable like software. Second, because the hardware product is expected to work for years, the adversary's computing power will only increase over time.
	 
         

Fix information:
repo_url: https://github.com/entronad/crypto-es
commit_details: repo_url: https://github.com/entronad/crypto-es
author: entronad
author_date: 2023-10-24 22:53:30+08:00
msg: v2.1.0
repository: repo_url: https://github.com/entronad/crypto-es
repo_name: entronad/crypto-es
description: A cryptography algorithms library
repo_language: JavaScript
owner: entronad
file_changes: filename: CHANGELOG.md
change_type: ModificationType.MODIFY
diff: @@ -1,3 +1,9 @@
+## 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**

programming_language: Markdown
filename: debug.js
change_type: ModificationType.MODIFY
diff: @@ -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);

programming_language: JavaScript
filename: pbkdf2.test.ts
change_type: ModificationType.MODIFY
diff: @@ -4,72 +4,72 @@ 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', () => {

programming_language: JavaScript
filename: pbkdf2.js
change_type: ModificationType.MODIFY
diff: @@ -2,7 +2,7 @@ import {
   Base,
   WordArray,
 } from './core.js';
-import { SHA1Algo } from './sha1.js';
+import { SHA256Algo } from './sha256.js';
 import { HMAC } from './hmac.js';
 
 /**
@@ -25,17 +25,20 @@ export class PBKDF2Algo extends Base {
 
     /**
      * 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,
     );

programming_language: TypeScript
filename: package-lock.json
change_type: ModificationType.MODIFY
diff: @@ -5,7 +5,6 @@
   "requires": true,
   "packages": {
     "": {
-      "name": "crypto-es",
       "version": "2.0.4",
       "license": "MIT",
       "devDependencies": {
@@ -2294,6 +2293,7 @@
         "@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",

programming_language: JavaScript
filename: package.json
change_type: ModificationType.MODIFY
diff: @@ -1,6 +1,6 @@
 {
   "name": "crypto-es",
-  "version": "2.0.4",
+  "version": "2.1.0",
   "description": "A cryptography algorithms library compatible with ES6 and TypeScript",
   "keywords": [
     "typescript",

programming_language: CoffeeScript