Skip to content

Commit

Permalink
fix: fixed port issue with mx forwarding, added safeguard for port (int)
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Dec 7, 2024
1 parent b6b3476 commit 86ad862
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/inquiries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions helpers/get-recipients.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion helpers/get-transporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
// <https://github.com/zone-eu/mx-connect#configuration-options>
mx = await asyncMxConnect({
ignoreMXHosts,
Expand Down

0 comments on commit 86ad862

Please sign in to comment.