Skip to content

Commit a157ded

Browse files
[mirotalkbro] - rb
1 parent f350bae commit a157ded

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

app/server.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ app.get('*', function (next) {
214214
next();
215215
});
216216

217-
// Remove trailing slashes in url handle bad requests
218217
app.use((err, req, res, next) => {
219218
if (err instanceof SyntaxError || err.status === 400 || 'body' in err) {
220219
log.error('Request Error', {
@@ -224,29 +223,18 @@ app.use((err, req, res, next) => {
224223
});
225224
return res.status(400).send({ status: 404, message: err.message }); // Bad request
226225
}
227-
228-
// Remove multiple leading slashes & normalize path
229-
let cleanPath = req.path.replace(/^\/+/, ''); // Removes all leading slashes
230-
let query = req.url.slice(req.path.length);
231-
232-
// Prevent open redirect attacks by checking if the path is an external domain
233-
if (/^([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}/.test(cleanPath)) {
234-
return res.status(400).send('Bad Request: Potential Open Redirect Detected');
235-
}
236-
237-
// If a trailing slash exists, redirect to a clean version
238-
if (req.path.endsWith('/') && req.path.length > 1) {
239-
return res.redirect(301, '/' + cleanPath + query);
226+
if (req.path.substr(-1) === '/' && req.path.length > 1) {
227+
let query = req.url.slice(req.path.length);
228+
res.redirect(301, req.path.slice(0, -1) + query);
240229
} else {
241230
log.debug('New request', {
242231
// headers: req.headers,
243232
// body: req.body,
244233
method: req.method,
245234
path: req.originalUrl,
246235
});
236+
next();
247237
}
248-
249-
next();
250238
});
251239

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

0 commit comments

Comments
 (0)