Skip to content

Commit

Permalink
fix: fixed onConnect function ordering to prevent unnecessary redis q…
Browse files Browse the repository at this point in the history
…uery for hard-coded blocked values
  • Loading branch information
titanism committed Dec 14, 2024
1 parent 4ec09a9 commit 80d9c31
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions helpers/on-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ async function onConnect(session, fn) {
if (env.NODE_ENV !== 'production') this.logger.debug(err, { session });
}

// check against hard-coded denylist
let isDenylisted = false;
if (
session.resolvedClientHostname &&
config.denylist.has(session.resolvedClientHostname)
)
isDenylisted = session.resolvedClientHostname;
else if (
session.resolvedRootClientHostname &&
config.denylist.has(session.resolvedRootClientHostname)
)
isDenylisted = session.resolvedRootClientHostname;
else if (config.denylist.has(session.remoteAddress))
isDenylisted = session.remoteAddress;

if (isDenylisted) {
const err = new DenylistError(
`The value ${isDenylisted} is denylisted by ${config.urls.web} ; To request removal, you must visit ${config.urls.web}/denylist?q=${isDenylisted} ;`,
550,
isDenylisted
);
throw err;
}

//
// check if the connecting remote IP address is allowlisted
//
Expand Down Expand Up @@ -106,30 +130,6 @@ async function onConnect(session, fn) {
return fn(refineAndLogError(err, session, false, this));
}

// check against hard-coded denylist
let isDenylisted = false;
if (
session.resolvedClientHostname &&
config.denylist.has(session.resolvedClientHostname)
)
isDenylisted = session.resolvedClientHostname;
else if (
session.resolvedRootClientHostname &&
config.denylist.has(session.resolvedRootClientHostname)
)
isDenylisted = session.resolvedRootClientHostname;
else if (config.denylist.has(session.remoteAddress))
isDenylisted = session.remoteAddress;

if (isDenylisted) {
const err = new DenylistError(
`The value ${isDenylisted} is denylisted by ${config.urls.web} ; To request removal, you must visit ${config.urls.web}/denylist?q=${isDenylisted} ;`,
550,
isDenylisted
);
return fn(refineAndLogError(err, session, false, this));
}

try {
// NOTE: do not change this prefix unless you also change it in `helpers/on-close.js`
const prefix = `concurrent_${this.constructor.name.toLowerCase()}_${
Expand Down

0 comments on commit 80d9c31

Please sign in to comment.