1
0
Fork 0
forked from svrjs/svrjs

Lint out the codebase.

This commit is contained in:
Dorian Niemiec 2024-08-24 20:45:17 +02:00
parent 2075d41ab3
commit e94391f197
4 changed files with 34 additions and 29 deletions

View file

@ -2,30 +2,33 @@ const fs = require("fs");
module.exports = (req, res, logFacilities, config, next) => { module.exports = (req, res, logFacilities, config, next) => {
// Trailing slash redirection // Trailing slash redirection
if ( if (
!req.isProxy && !req.isProxy &&
!config.disableTrailingSlashRedirects && !config.disableTrailingSlashRedirects &&
req.parsedURL.pathname[req.parsedURL.pathname.length - 1] != "/" && req.parsedURL.pathname[req.parsedURL.pathname.length - 1] != "/" &&
req.originalParsedURL.pathname[ req.originalParsedURL.pathname[req.originalParsedURL.pathname.length - 1] !=
req.originalParsedURL.pathname.length - 1 "/"
] != "/" ) {
) { fs.stat(
fs.stat( "." + decodeURIComponent(req.parsedURL.pathname),
"." + decodeURIComponent(req.parsedURL.pathname), function (err, stats) {
function (err, stats) { if (err || !stats.isDirectory()) {
if (err || !stats.isDirectory()) { try {
try { next();
next(); } catch (err) {
} catch (err) { res.error(500, err);
res.error(500, err);
}
} else {
res.redirect(req.originalParsedURL.pathname + "/" + req.parsedURL.search + req.parsedURL.hash);
} }
}, } else {
); res.redirect(
} else { req.originalParsedURL.pathname +
next(); "/" +
} req.parsedURL.search +
req.parsedURL.hash,
);
}
},
);
} else {
next();
}
}; };

View file

@ -125,7 +125,8 @@ module.exports = (req, res, logFacilities, config, next) => {
logFacilities.errmessage("Content blocked."); logFacilities.errmessage("Content blocked.");
return; return;
} else if (sHref != req.parsedURL.pathname) { } else if (sHref != req.parsedURL.pathname) {
var rewrittenAgainURL = sHref + req.parsedURL.search + req.parsedURL.hash; var rewrittenAgainURL =
sHref + req.parsedURL.search + req.parsedURL.hash;
logFacilities.resmessage( logFacilities.resmessage(
"URL sanitized: " + req.url + " => " + rewrittenAgainURL, "URL sanitized: " + req.url + " => " + rewrittenAgainURL,
); );

View file

@ -11,7 +11,8 @@ module.exports = (req, res, logFacilities, config, next) => {
// Check if URL is "dirty" // Check if URL is "dirty"
if (req.parsedURL.pathname != sanitizedHref && !req.isProxy) { if (req.parsedURL.pathname != sanitizedHref && !req.isProxy) {
let sanitizedURL = sanitizedHref + req.parsedURL.search + req.parsedURL.hash; let sanitizedURL =
sanitizedHref + req.parsedURL.search + req.parsedURL.hash;
logFacilities.resmessage( logFacilities.resmessage(
"URL sanitized: " + req.url + " => " + sanitizedURL, "URL sanitized: " + req.url + " => " + sanitizedURL,
); );

View file

@ -1,4 +1,3 @@
const url = require("url");
const createRegex = require("../utils/createRegex.js"); const createRegex = require("../utils/createRegex.js");
const ipMatch = require("../utils/ipMatch.js"); const ipMatch = require("../utils/ipMatch.js");
const sanitizeURL = require("../utils/urlSanitizer.js"); const sanitizeURL = require("../utils/urlSanitizer.js");
@ -113,7 +112,8 @@ module.exports = (req, res, logFacilities, config, next) => {
logFacilities.errmessage("Content blocked."); logFacilities.errmessage("Content blocked.");
return; return;
} else if (sHref != req.parsedURL.pathname) { } else if (sHref != req.parsedURL.pathname) {
let rewrittenAgainURL = sHref + req.parsedURL.search + req.parsedURL.hash; let rewrittenAgainURL =
sHref + req.parsedURL.search + req.parsedURL.hash;
logFacilities.resmessage( logFacilities.resmessage(
"URL sanitized: " + req.url + " => " + rewrittenAgainURL, "URL sanitized: " + req.url + " => " + rewrittenAgainURL,
); );