Skip to content

Commit

Permalink
[mirotalksfu] - fix
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Feb 10, 2025
1 parent 50e6dfa commit 4966798
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,20 +414,19 @@ function startServer() {
body: req.body,
error: err.message,
});
return res.status(400).send({ status: 404, message: err.message }); // Bad request
return res.status(400).send({ status: 404, message: err.message });
}

// Remove multiple leading slashes & normalize path
let cleanPath = req.path.replace(/^\/+/, ''); // Removes all leading slashes
let cleanPath = req.path.replace(/^\/+/, ''); // Removes leading slashes
let query = req.url.slice(req.path.length);

// Prevent open redirect attacks by checking if the path is an external domain
// Prevent open redirect attacks
if (/^([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}/.test(cleanPath)) {
return res.status(400).send('Bad Request: Potential Open Redirect Detected');
}

// If a trailing slash exists, redirect to a clean version
if (req.path.endsWith('/') && req.path.length > 1) {
// Avoid infinite redirects by checking if req.path is already clean
if (req.path.endsWith('/') && req.path.length > 1 && cleanPath + query !== req.url) {
return res.redirect(301, '/' + cleanPath + query);
}

Expand Down

0 comments on commit 4966798

Please sign in to comment.