Skip to content

Commit

Permalink
fix(core): Upgrade crypto-js to address CVE-2023-46233 (#7519)
Browse files Browse the repository at this point in the history
[GH Advisory](GHSA-xwcq-pm8m-c4vf)
  • Loading branch information
netroy committed Oct 26, 2023
1 parent df89685 commit 65e5593
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/core/jest.config.js
Expand Up @@ -2,4 +2,5 @@
module.exports = {
...require('../../jest.config'),
globalSetup: '<rootDir>/test/setup.ts',
setupFilesAfterEnv: ['<rootDir>/test/setup-mocks.ts'],
};
2 changes: 1 addition & 1 deletion packages/core/package.json
Expand Up @@ -54,7 +54,7 @@
"axios": "^0.21.1",
"concat-stream": "^2.0.0",
"cron": "~1.7.2",
"crypto-js": "^4.1.1",
"crypto-js": "^4.2.0",
"fast-glob": "^3.2.5",
"file-type": "^16.5.4",
"flatted": "^3.2.4",
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/Cipher.ts
Expand Up @@ -7,13 +7,15 @@ export class Cipher {
constructor(private readonly instanceSettings: InstanceSettings) {}

encrypt(data: string | object) {
const { encryptionKey } = this.instanceSettings;
return AES.encrypt(
typeof data === 'string' ? data : JSON.stringify(data),
this.instanceSettings.encryptionKey,
encryptionKey,
).toString();
}

decrypt(data: string) {
return AES.decrypt(data, this.instanceSettings.encryptionKey).toString(enc.Utf8);
const { encryptionKey } = this.instanceSettings;
return AES.decrypt(data, encryptionKey).toString(enc.Utf8);
}
}
30 changes: 30 additions & 0 deletions packages/core/test/Cipher.test.ts
@@ -0,0 +1,30 @@
import Container from 'typedi';
import { InstanceSettings } from '@/InstanceSettings';
import { Cipher } from '@/Cipher';
import { mockInstance } from './utils';

describe('Cipher', () => {
mockInstance(InstanceSettings, { encryptionKey: 'test_key' });
const cipher = Container.get(Cipher);

describe('encrypt', () => {
it('should encrypt strings', () => {
const encrypted = cipher.encrypt('random-string');
const decrypted = cipher.decrypt(encrypted);
expect(decrypted).toEqual('random-string');
});

it('should encrypt objects', () => {
const encrypted = cipher.encrypt({ key: 'value' });
const decrypted = cipher.decrypt(encrypted);
expect(decrypted).toEqual('{"key":"value"}');
});
});

describe('decrypt', () => {
it('should decrypt string', () => {
const decrypted = cipher.decrypt('U2FsdGVkX194VEoX27o3+y5jUd1JTTmVwkOKjVhB6Jg=');
expect(decrypted).toEqual('random-string');
});
});
});
1 change: 1 addition & 0 deletions packages/core/test/setup-mocks.ts
@@ -0,0 +1 @@
import 'reflect-metadata';
2 changes: 1 addition & 1 deletion packages/workflow/package.json
Expand Up @@ -51,7 +51,7 @@
"@n8n/tournament": "^1.0.2",
"@n8n_io/riot-tmpl": "^4.0.0",
"ast-types": "0.15.2",
"crypto-js": "^4.1.1",
"crypto-js": "^4.2.0",
"deep-equal": "^2.2.0",
"esprima-next": "5.8.4",
"form-data": "^4.0.0",
Expand Down
18 changes: 11 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 65e5593

Please sign in to comment.