From 86ad86267163ec29f4ef230a3bd792c580f8bf04 Mon Sep 17 00:00:00 2001 From: titanism <101466223+titanism@users.noreply.github.com> Date: Sat, 7 Dec 2024 04:18:45 -0600 Subject: [PATCH] fix: fixed port issue with mx forwarding, added safeguard for port (int) --- app/controllers/api/v1/inquiries.js | 2 +- helpers/get-recipients.js | 4 ++-- helpers/get-transporter.js | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/inquiries.js b/app/controllers/api/v1/inquiries.js index cd3eee1a2c..edb0fd16cc 100644 --- a/app/controllers/api/v1/inquiries.js +++ b/app/controllers/api/v1/inquiries.js @@ -10,10 +10,10 @@ const _ = require('lodash'); const { isEmail } = require('validator'); const { Headers } = require('mailsplit'); -const { decrypt } = require('./encrypt-decrypt'); const config = require('#config'); const env = require('#config/env'); const { Inquiries, Users } = require('#models'); +const { decrypt } = require('#helpers/encrypt-decrypt'); const webhookSignatureKey = env.WEBHOOK_SIGNATURE_KEY; const WEBHOOK_SIGNATURE_HEADER = 'X-Webhook-Signature'; diff --git a/helpers/get-recipients.js b/helpers/get-recipients.js index a91dc5f0ed..370e690295 100644 --- a/helpers/get-recipients.js +++ b/helpers/get-recipients.js @@ -40,7 +40,7 @@ async function getRecipients(session, scan) { session.envelope.rcptTo, // eslint-disable-next-line complexity async (to) => { - let port = '25'; + let port = 25; try { let hasAdultContentProtection = true; let hasPhishingProtection = true; @@ -146,7 +146,7 @@ async function getRecipients(session, scan) { if (_.isObject(body)) { // `port` (String) - a valid port number, defaults to 25 if (isSANB(body.port) && isPort(body.port) && body.port !== '25') { - port = body.port; + port = Number.parseInt(body.port, 10); logger.debug(`Custom port for ${to.address} detected`, { port, session diff --git a/helpers/get-transporter.js b/helpers/get-transporter.js index 974fc09482..6d23d37ac3 100644 --- a/helpers/get-transporter.js +++ b/helpers/get-transporter.js @@ -98,6 +98,9 @@ async function getTransporter(options = {}, err) { // client } = options; + // safeguard to ensure port is always a number + if (typeof port === 'string') throw new TypeError('Port must be a number'); + let mx = { host: target, port @@ -109,7 +112,7 @@ async function getTransporter(options = {}, err) { // // this is required since custom port forwarding would be recursive otherwise - if (env.NODE_ENV === 'test' || port === 25) { + if (port === 25) { // mx = await asyncMxConnect({ ignoreMXHosts,