@@ -21,6 +21,12 @@ const controllerHelpers = require.main.require('./src/controllers/helpers');
2121const SocketPlugins = require . main . require ( './src/socket.io/plugins' ) ;
2222
2323const atob = base64str => Buffer . from ( base64str , 'base64' ) . toString ( 'binary' ) ;
24+ const guard = ( path ) => {
25+ let url = new URL ( path , nconf . get ( 'url' ) ) ;
26+ url = url . hostname === nconf . get ( 'url_parsed' ) . hostname ? url : nconf . get ( 'url' ) ;
27+
28+ return url . toString ( ) ;
29+ } ;
2430
2531const plugin = {
2632 _f2l : undefined ,
@@ -57,15 +63,15 @@ plugin.init = async (params) => {
5763 delete req . session . tfaForce ;
5864 req . session . meta . datetime = Date . now ( ) ;
5965 user . auth . addSession ( req . uid , req . sessionID , req . session . meta . uuid ) ;
60- res . redirect ( nconf . get ( 'relative_path' ) + ( req . query . next || '/' ) ) ;
66+ res . redirect ( guard ( nconf . get ( 'relative_path' ) + ( req . query . next || '/' ) ) ) ;
6167 } ) ;
6268 hostHelpers . setupPageRoute ( router , '/login/2fa/authn' , [ hostMiddleware . ensureLoggedIn ] , controllers . renderAuthnChallenge ) ;
6369
6470 // 2fa backups codes
6571 hostHelpers . setupPageRoute ( router , '/login/2fa/backup' , [ hostMiddleware . ensureLoggedIn ] , controllers . renderBackup ) ;
6672 router . post ( '/login/2fa/backup' , hostMiddleware . ensureLoggedIn , controllers . processBackup , ( req , res ) => {
6773 req . session . tfa = true ;
68- res . redirect ( nconf . get ( 'relative_path' ) + ( req . query . next || '/' ) ) ;
74+ res . redirect ( guard ( nconf . get ( 'relative_path' ) + ( req . query . next || '/' ) ) ) ;
6975 } ) ;
7076 router . put ( '/login/2fa/backup' , hostMiddleware . requireUser , middlewares . requireSecondFactor , hostMiddleware . applyCSRF , controllers . generateBackupCodes ) ;
7177
@@ -167,7 +173,7 @@ plugin.addRoutes = async ({ router, middleware, helpers }) => {
167173 req . session . meta . datetime = Date . now ( ) ;
168174
169175 helpers . formatApiResponse ( 200 , res , {
170- next : req . query . next || '/' ,
176+ next : guard ( req . query . next || '/' ) ,
171177 } ) ;
172178 } ) ;
173179
0 commit comments