Skip to content

Commit

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

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

// 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');
}

// 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);
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();
}

next();
});

// OpenID Connect - Dynamically set baseURL based on incoming host and protocol
Expand Down

0 comments on commit 9b1d79c

Please sign in to comment.