From 9f5136651524d664b9c5fa30be346564b863b9aa Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Thu, 29 Aug 2024 19:27:04 +0200 Subject: [PATCH] Simplify ES6-style functions --- src/handlers/proxyHandler.js | 5 +-- src/handlers/requestHandler.js | 5 +-- src/index.js | 4 +- .../nonStandardCodesAndHttpAuthentication.js | 30 +++++++------- src/utils/clusterBunShim.js | 8 +--- src/utils/generateErrorStack.js | 6 +-- src/utils/ipBlockList.js | 9 ++--- src/utils/ipMatch.js | 5 +-- src/utils/sha256.js | 39 ++++--------------- 9 files changed, 37 insertions(+), 74 deletions(-) diff --git a/src/handlers/proxyHandler.js b/src/handlers/proxyHandler.js index f3e60bf..87b5f45 100644 --- a/src/handlers/proxyHandler.js +++ b/src/handlers/proxyHandler.js @@ -32,9 +32,8 @@ function proxyHandler(req, socket, head) { // SVR.JS configuration object (modified) const config = deepClone(process.serverConfig); - config.generateServerString = () => { - return generateServerString(config.exposeServerVersion); - }; + config.generateServerString = () => + generateServerString(config.exposeServerVersion); const reqip = socket.remoteAddress; const reqport = socket.remotePort; diff --git a/src/handlers/requestHandler.js b/src/handlers/requestHandler.js index 5fcb667..be2fc14 100644 --- a/src/handlers/requestHandler.js +++ b/src/handlers/requestHandler.js @@ -34,9 +34,8 @@ function requestHandler(req, res) { // SVR.JS configuration object (modified) const config = deepClone(process.serverConfig); - config.generateServerString = () => { - return generateServerString(config.exposeServerVersion); - }; + config.generateServerString = () => + generateServerString(config.exposeServerVersion); // getCustomHeaders() in SVR.JS 3.x config.getCustomHeaders = () => { diff --git a/src/index.js b/src/index.js index c039a20..283632b 100644 --- a/src/index.js +++ b/src/index.js @@ -1719,9 +1719,7 @@ function start(init) { /^(?:0\.|1\.0\.|1\.1\.[0-9](?![0-9])|1\.1\.1[0-2](?![0-9]))/, ) ) && - process.serverConfig.users.some((entry) => { - return entry.pbkdf2; - }) + process.serverConfig.users.some((entry) => entry.pbkdf2) ) serverconsole.locwarnmessage( "PBKDF2 password hashing function in Bun versions older than v1.1.13 blocks the event loop, which may result in denial of service.", diff --git a/src/middleware/nonStandardCodesAndHttpAuthentication.js b/src/middleware/nonStandardCodesAndHttpAuthentication.js index 164be7f..7c419e7 100644 --- a/src/middleware/nonStandardCodesAndHttpAuthentication.js +++ b/src/middleware/nonStandardCodesAndHttpAuthentication.js @@ -42,12 +42,12 @@ process.serverConfig.nonStandardCodes.forEach((nonStandardCodeRaw) => { if (!cluster.isPrimary) { passwordHashCacheIntervalId = setInterval(() => { - pbkdf2Cache = pbkdf2Cache.filter((entry) => { - return entry.addDate > new Date() - 3600000; - }); - scryptCache = scryptCache.filter((entry) => { - return entry.addDate > new Date() - 3600000; - }); + pbkdf2Cache = pbkdf2Cache.filter( + (entry) => entry.addDate > new Date() - 3600000, + ); + scryptCache = scryptCache.filter( + (entry) => entry.addDate > new Date() - 3600000, + ); }, 1800000); } @@ -192,11 +192,10 @@ module.exports = (req, res, logFacilities, config, next) => { ); return; } else { - cacheEntry = scryptCache.find((entry) => { - return ( - entry.password == hashedPassword && entry.salt == list[_i].salt - ); - }); + cacheEntry = scryptCache.find( + (entry) => + entry.password == hashedPassword && entry.salt == list[_i].salt, + ); if (cacheEntry) { cb(cacheEntry.hash); } else { @@ -226,11 +225,10 @@ module.exports = (req, res, logFacilities, config, next) => { ); return; } else { - cacheEntry = pbkdf2Cache.find((entry) => { - return ( - entry.password == hashedPassword && entry.salt == list[_i].salt - ); - }); + cacheEntry = pbkdf2Cache.find( + (entry) => + entry.password == hashedPassword && entry.salt == list[_i].salt, + ); if (cacheEntry) { cb(cacheEntry.hash); } else { diff --git a/src/utils/clusterBunShim.js b/src/utils/clusterBunShim.js index 642d94e..5c7ced8 100644 --- a/src/utils/clusterBunShim.js +++ b/src/utils/clusterBunShim.js @@ -26,9 +26,7 @@ if (!process.singleThreaded) { cluster.worker = { id: parseInt(process.env.NODE_UNIQUE_ID), process: process, - isDead: () => { - return false; - }, + isDead: () => false, send: (message, ...params) => { process.send(message, ...params); }, @@ -98,9 +96,7 @@ if (!process.singleThreaded) { }); newWorker.process = newWorker; - newWorker.isDead = () => { - return newWorker.exitCode !== null || newWorker.killed; - }; + newWorker.isDead = () => newWorker.exitCode !== null || newWorker.killed; newWorker.id = newEnvironment.NODE_UNIQUE_ID; function checkSendImplementation(worker) { diff --git a/src/utils/generateErrorStack.js b/src/utils/generateErrorStack.js index 24f9af4..fe58772 100644 --- a/src/utils/generateErrorStack.js +++ b/src/utils/generateErrorStack.js @@ -5,9 +5,9 @@ function generateErrorStack(errorObject) { // If the error stack starts with the error name, return the original stack (it is V8-style then). if ( - errorStack.some((errorStackLine) => { - return errorStackLine.indexOf(errorObject.name) == 0; - }) + errorStack.some( + (errorStackLine) => errorStackLine.indexOf(errorObject.name) == 0, + ) ) { return errorObject.stack; } diff --git a/src/utils/ipBlockList.js b/src/utils/ipBlockList.js index cdeea64..d5f7d00 100644 --- a/src/utils/ipBlockList.js +++ b/src/utils/ipBlockList.js @@ -10,9 +10,8 @@ function ipBlockList(rawBlockList) { }; // Function to normalize IPv4 address (remove leading zeros) - const normalizeIPv4Address = (address) => { - return address.replace(/(^|\.)(?:0(?!\.|$))+/g, "$1"); - }; + const normalizeIPv4Address = (address) => + address.replace(/(^|\.)(?:0(?!\.|$))+/g, "$1"); // Function to expand IPv6 address to full format const expandIPv6Address = (address) => { @@ -236,9 +235,7 @@ function ipBlockList(rawBlockList) { ? checkIfIPv4CIDRMatches : checkIfIPv6CIDRMatches; - return instance.cidrs.some((iCidr) => { - return checkMethod(ipParsedObject, iCidr); - }); + return instance.cidrs.some((iCidr) => checkMethod(ipParsedObject, iCidr)); }; // Add initial raw block list values to the instance diff --git a/src/utils/ipMatch.js b/src/utils/ipMatch.js index 1370ff3..5ef0e6f 100644 --- a/src/utils/ipMatch.js +++ b/src/utils/ipMatch.js @@ -4,9 +4,8 @@ function ipMatch(IP1, IP2) { if (!IP2) return false; // Function to normalize IPv4 address (remove leading zeros) - const normalizeIPv4Address = (address) => { - return address.replace(/(^|\.)(?:0(?!\.|$))+/g, "$1"); - }; + const normalizeIPv4Address = (address) => + address.replace(/(^|\.)(?:0(?!\.|$))+/g, "$1"); // Function to expand IPv6 address to full format const expandIPv6Address = (address) => { diff --git a/src/utils/sha256.js b/src/utils/sha256.js index 58043de..4ea6abe 100644 --- a/src/utils/sha256.js +++ b/src/utils/sha256.js @@ -22,37 +22,14 @@ function sha256(s) { return (msw << 16) | (lsw & 0xffff); }; - const S = (X, n) => { - return (X >>> n) | (X << (32 - n)); - }; - - const R = (X, n) => { - return X >>> n; - }; - - const Ch = (x, y, z) => { - return (x & y) ^ (~x & z); - }; - - const Maj = (x, y, z) => { - return (x & y) ^ (x & z) ^ (y & z); - }; - - const Sigma0256 = (x) => { - return S(x, 2) ^ S(x, 13) ^ S(x, 22); - }; - - const Sigma1256 = (x) => { - return S(x, 6) ^ S(x, 11) ^ S(x, 25); - }; - - const Gamma0256 = (x) => { - return S(x, 7) ^ S(x, 18) ^ R(x, 3); - }; - - const Gamma1256 = (x) => { - return S(x, 17) ^ S(x, 19) ^ R(x, 10); - }; + const S = (X, n) => (X >>> n) | (X << (32 - n)); + const R = (X, n) => X >>> n; + const Ch = (x, y, z) => (x & y) ^ (~x & z); + const Maj = (x, y, z) => (x & y) ^ (x & z) ^ (y & z); + const Sigma0256 = (x) => S(x, 2) ^ S(x, 13) ^ S(x, 22); + const Sigma1256 = (x) => S(x, 6) ^ S(x, 11) ^ S(x, 25); + const Gamma0256 = (x) => S(x, 7) ^ S(x, 18) ^ R(x, 3); + const Gamma1256 = (x) => S(x, 17) ^ S(x, 19) ^ R(x, 10); function coreSha256(m, l) { const K = new Array(