From f8d6d5c4423b14f8deb8d91116897d3a6b10e55c Mon Sep 17 00:00:00 2001 From: 00Fjongl <65314359+00Fjongl@users.noreply.github.com> Date: Sat, 10 Aug 2024 02:33:42 -0500 Subject: [PATCH] Disable ghetto randomization for now while going on potential hiatus --- src/config.json | 2 +- src/server.mjs | 122 +++++++++++++++++++++++++----------------------- 2 files changed, 64 insertions(+), 60 deletions(-) diff --git a/src/config.json b/src/config.json index 9cab5d35..d872df33 100644 --- a/src/config.json +++ b/src/config.json @@ -2,6 +2,6 @@ "title": "HU LTS", "host": "0.0.0.0", "minifyScripts": true, - "randomizeIdentifiers": true, + "randomizeIdentifiers": false, "production": false } diff --git a/src/server.mjs b/src/server.mjs index 6fb4ceb3..9cc3c64d 100644 --- a/src/server.mjs +++ b/src/server.mjs @@ -249,70 +249,74 @@ app.get('/github/:redirect', (req, reply) => { else reply.code(404).type('text/html').send(preloaded404); }); -const encodingTable = (() => { - let yummyOneBytes = ''; - for (let i = 0; i < 128; i++) - if ( - JSON.stringify(JSON.stringify(String.fromCodePoint(i)).slice(1, -1)) - .length < 6 - ) - yummyOneBytes += String.fromCodePoint(i); - return yummyOneBytes; - })(), - randomValue = crypto - .randomUUID() - .split('-') - .map((gibberish) => { - let randomNumber = parseInt(gibberish, 16), - output = ''; - while (randomNumber >= encodingTable.length) { - output += - encodingTable[Math.floor(randomNumber) % encodingTable.length]; - randomNumber = randomNumber / encodingTable.length; - } - return output + Math.floor(randomNumber); - }) - .join(''), - randomizeGlobal = config.randomizeIdentifiers - ? (file) => - tryReadFile(file, import.meta.url).replace( - /(["'`])\{\{__uv\$config\}\}\1/g, - JSON.stringify(randomValue) +if (config.randomizeIdentifiers) { + const encodingTable = (() => { + let yummyOneBytes = ''; + for (let i = 0; i < 128; i++) + if ( + JSON.stringify(JSON.stringify(String.fromCodePoint(i)).slice(1, -1)) + .length < 6 ) - : (file) => - tryReadFile(file, import.meta.url).replace( - /(["'`])\{\{__uv\$config\}\}\1/g, - JSON.stringify('__uv$config') - ); + yummyOneBytes += String.fromCodePoint(i); + return yummyOneBytes; + })(), + randomValue = crypto + .randomUUID() + .split('-') + .map((gibberish) => { + let randomNumber = parseInt(gibberish, 16), + output = ''; + while (randomNumber >= encodingTable.length) { + output += + encodingTable[Math.floor(randomNumber) % encodingTable.length]; + randomNumber = randomNumber / encodingTable.length; + } + return output + Math.floor(randomNumber); + }) + .join(''), + randomizeGlobal = config.randomizeIdentifiers + ? (file) => + tryReadFile(file, import.meta.url).replace( + /(["'`])\{\{__uv\$config\}\}\1/g, + JSON.stringify(randomValue) + ) + : (file) => + tryReadFile(file, import.meta.url).replace( + /(["'`])\{\{__uv\$config\}\}\1/g, + JSON.stringify('__uv$config') + ); -app.get('/assets/js/common-16451543478.js', (req, reply) => { - reply - .type('text/javascript') - .send( - randomizeGlobal( - '../views' + (config.minifyScripts ? '/dist' : '') + req.url - ) - ); -}); + app.get('/assets/js/common-16451543478.js', (req, reply) => { + reply + .type('text/javascript') + .send( + randomizeGlobal( + '../views' + (config.minifyScripts ? '/dist' : '') + req.url + ) + ); + }); -app.get('/uv/:file.js', (req, reply) => { - const destination = existsSync(fileURLToPath(new URL('../views' + req.url, import.meta.url))) - ? '../views' + (config.minifyScripts ? '/dist' : '') + req.url - : uvPath + '/' + req.params.file + '.js'; - reply - .type('text/javascript') - .send( - randomizeGlobal(destination).replace( - /(["'`])\{\{ultraviolet-error\}\}\1/g, - JSON.stringify( - tryReadFile( - '../views/pages/proxnav/ultraviolet-error.html', - import.meta.url + app.get('/uv/:file.js', (req, reply) => { + const destination = existsSync( + fileURLToPath(new URL('../views' + req.url, import.meta.url)) + ) + ? '../views' + (config.minifyScripts ? '/dist' : '') + req.url + : uvPath + '/' + req.params.file + '.js'; + reply + .type('text/javascript') + .send( + randomizeGlobal(destination).replace( + /(["'`])\{\{ultraviolet-error\}\}\1/g, + JSON.stringify( + tryReadFile( + '../views/pages/proxnav/ultraviolet-error.html', + import.meta.url + ) ) ) - ) - ); -}); + ); + }); +} // Set an error page for invalid paths outside the query string system. app.setNotFoundHandler((req, reply) => {