From e55fa93d1848bedd5b9ef42a35c39a6d549695c1 Mon Sep 17 00:00:00 2001 From: Shamil Mingaliev Date: Fri, 13 Dec 2019 16:08:14 +0300 Subject: [PATCH] create ENCRYPTED_EMAIL and IV merge tags to use in unsubscribe link template --- config/docker-production.toml.tmpl | 2 +- lib/models/subscriptions.js | 3 ++- lib/tools.js | 17 ++++++++++++++++- services/sender.js | 3 ++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/config/docker-production.toml.tmpl b/config/docker-production.toml.tmpl index ca832181..612321f4 100644 --- a/config/docker-production.toml.tmpl +++ b/config/docker-production.toml.tmpl @@ -6,4 +6,4 @@ enabled=true host="redis" [reports] -enabled=true \ No newline at end of file +enabled=true diff --git a/lib/models/subscriptions.js b/lib/models/subscriptions.js index 3a9a7f58..3b9a0125 100644 --- a/lib/models/subscriptions.js +++ b/lib/models/subscriptions.js @@ -358,7 +358,8 @@ module.exports.getWithMergeTags = (listId, cid, callback) => { FIRST_NAME: subscription.firstName, LAST_NAME: subscription.lastName, FULL_NAME: [].concat(subscription.firstName || []).concat(subscription.lastName || []).join(' '), - TIMEZONE: subscription.tz || '' + TIMEZONE: subscription.tz || '', + ...tools.artstationMergeTags(subscription), }; fields.getRow(fieldList, subscription, false, true).forEach(field => { diff --git a/lib/tools.js b/lib/tools.js index b0d16822..523b4496 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -14,6 +14,8 @@ let _ = require('./translate')._; let util = require('util'); let createDOMPurify = require('dompurify'); let htmlToText = require('html-to-text'); +let crypto = require('crypto') +let process = require('process') let blockedUsers = ['abuse', 'admin', 'billing', 'compliance', 'devnull', 'dns', 'ftp', 'hostmaster', 'inoc', 'ispfeedback', 'ispsupport', 'listrequest', 'list', 'maildaemon', 'noc', 'noreply', 'noreply', 'null', 'phish', 'phishing', 'postmaster', 'privacy', 'registrar', 'root', 'security', 'spam', 'support', 'sysadmin', 'tech', 'undisclosedrecipients', 'unsubscribe', 'usenet', 'uucp', 'webmaster', 'www']; @@ -30,6 +32,7 @@ module.exports = { prepareHtml, purifyHTML, mergeTemplateIntoLayout, + artstationMergeTags, workers: new Set() }; @@ -211,7 +214,7 @@ function formatMessage(serviceUrl, campaign, list, subscription, message, filter return false; }; - let tagReplace = message => + let tagReplace = message => message.replace(/\[([a-z0-9_]+)(?:\/([^\]]+))?\]/ig, (match, identifier, fallback) => { identifier = identifier.toUpperCase(); let value = getTagValue(identifier); @@ -321,3 +324,15 @@ function mergeTemplateIntoLayout(template, layout, callback) { return done(template, layout); } } + +function artstationMergeTags(subscription) { + const iv = crypto.randomBytes(16) + const cipher = crypto.createCipheriv('aes-256-cbc', process.env.ARTSTATION_SECRET, iv) + let encrypted_email = cipher.update(subscription.email, 'utf8', 'hex') + encrypted_email += cipher.final('hex') + + return { + ENCRYPTED_EMAIL: encrypted_email, + IV: iv.toString('hex'), + } +} diff --git a/services/sender.js b/services/sender.js index 3a7709a2..4226af8b 100644 --- a/services/sender.js +++ b/services/sender.js @@ -328,7 +328,8 @@ function formatMessage(message, callback) { EMAIL: message.subscription.email, FIRST_NAME: message.subscription.firstName, LAST_NAME: message.subscription.lastName, - FULL_NAME: [].concat(message.subscription.firstName || []).concat(message.subscription.lastName || []).join(' ') + FULL_NAME: [].concat(message.subscription.firstName || []).concat(message.subscription.lastName || []).join(' '), + ...tools.artstationMergeTags(message.subscription), }; let encryptionKeys = [];