[mirotalk] - rb
This commit is contained in:
+5
-15
@@ -453,22 +453,12 @@ app.use((err, req, res, next) => {
|
||||
});
|
||||
return res.status(400).send({ status: 404, message: err.message }); // Bad request
|
||||
}
|
||||
|
||||
// Remove multiple leading slashes & normalize path
|
||||
let cleanPath = req.path.replace(/^\/+/, ''); // Removes all leading slashes
|
||||
let query = req.url.slice(req.path.length);
|
||||
|
||||
// Prevent open redirect attacks by checking if the path is an external domain
|
||||
if (/^([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}/.test(cleanPath)) {
|
||||
return res.status(400).send('Bad Request: Potential Open Redirect Detected');
|
||||
if (req.path.substr(-1) === '/' && req.path.length > 1) {
|
||||
let query = req.url.slice(req.path.length);
|
||||
res.redirect(301, req.path.slice(0, -1) + query);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
|
||||
// If a trailing slash exists, redirect to a clean version
|
||||
if (req.path.endsWith('/') && req.path.length > 1) {
|
||||
return res.redirect(301, '/' + cleanPath + query);
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
// OpenID Connect - Dynamically set baseURL based on incoming host and protocol
|
||||
|
||||
Reference in New Issue
Block a user