Skip to content

Commit 8f64875

Browse files
authored
Merge pull request #4014 from Countly/SER-483-Vulnerable-email-unsubscription
[SER-483] email reports unsubscribe code generation aes-256-ctr encryption replaced with aes-256-gcm
2 parents 9211aff + e8cb2fc commit 8f64875

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

plugins/reports/api/reports.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,8 @@ var metricProps = {
605605
try {
606606
const reportConfig = plugins.getConfig("reports", null, true);
607607
const key = reportConfig.secretKey;
608-
const decipher = crypto.createDecipheriv('aes-256-ctr', key, Buffer.from(data.iv, 'hex'));
608+
const decipher = crypto.createDecipheriv('aes-256-gcm', key, Buffer.from(data.iv, 'hex'));
609+
decipher.setAuthTag(Buffer.from(data.authTag, 'hex'));
609610
const decrpyted = Buffer.concat([decipher.update(Buffer.from(data.content, 'hex')), decipher.final()]);
610611
const result = JSON.parse(decrpyted.toString());
611612
return result;
@@ -621,7 +622,7 @@ var metricProps = {
621622

622623
const iv = crypto.randomBytes(16);
623624
const key = reportConfig.secretKey;
624-
const cipher = crypto.createCipheriv('aes-256-ctr', key, iv);
625+
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
625626
const data = {
626627
"reportID": report._id,
627628
"email": email,
@@ -630,7 +631,8 @@ var metricProps = {
630631
const encrypted = Buffer.concat([cipher.update(JSON.stringify(data)), cipher.final()]);
631632
const result = {
632633
iv: iv.toString('hex'),
633-
content: encrypted.toString('hex')
634+
content: encrypted.toString('hex'),
635+
authTag: cipher.getAuthTag().toString('hex')
634636
};
635637
return JSON.stringify(result);
636638
}

0 commit comments

Comments
 (0)