@@ -214,7 +214,6 @@ app.get('*', function (next) {
214
214
next ( ) ;
215
215
} ) ;
216
216
217
- // Remove trailing slashes in url handle bad requests
218
217
app . use ( ( err , req , res , next ) => {
219
218
if ( err instanceof SyntaxError || err . status === 400 || 'body' in err ) {
220
219
log . error ( 'Request Error' , {
@@ -224,29 +223,18 @@ app.use((err, req, res, next) => {
224
223
} ) ;
225
224
return res . status ( 400 ) . send ( { status : 404 , message : err . message } ) ; // Bad request
226
225
}
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 - z A - Z 0 - 9 - ] + \. ) + [ a - z A - 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 ) ;
240
229
} else {
241
230
log . debug ( 'New request' , {
242
231
// headers: req.headers,
243
232
// body: req.body,
244
233
method : req . method ,
245
234
path : req . originalUrl ,
246
235
} ) ;
236
+ next ( ) ;
247
237
}
248
-
249
- next ( ) ;
250
238
} ) ;
251
239
252
240
// OpenID Connect - Dynamically set baseURL based on incoming host and protocol
0 commit comments