@@ -338,21 +338,41 @@ import "./login.scss";
338
338
event . stopPropagation ( ) ;
339
339
}
340
340
341
- function boot ( ) {
342
- window . onload = null ;
341
+ function deal_with_multihost ( ) {
342
+ // If we are currently logged in to some machine, but still
343
+ // end up on the login page, we are about to load resources
344
+ // from two machines into the same browser origin.
343
345
344
- if ( ! environment . page . allow_multi_host ) {
345
- // If we are currently logged in, we do not want to allow
346
- // another login to a different machine. So we redirect to
347
- // the current login.
346
+ const cur_machine = window . localStorage . getItem ( "current-machine" ) ;
348
347
349
- const cur_machine = window . localStorage . getItem ( "current-machine" ) ;
350
- if ( cur_machine == "localhost" && window . location . pathname . startsWith ( "/=" ) ) {
348
+ // Protect against outdated cur_machine values.
349
+ if ( cur_machine == "localhost" && ! window . location . pathname . startsWith ( "/=" ) )
350
+ return ;
351
+ if ( cur_machine && cur_machine != "localhost" && window . location . pathname . startsWith ( "/=" + cur_machine ) )
352
+ return ;
353
+
354
+ function redirect_to_current_machine ( ) {
355
+ if ( cur_machine == "localhost" )
351
356
login_reload ( "/" ) ;
352
- } else if ( cur_machine && ! window . location . pathname . startsWith ( "/=" + cur_machine ) ) {
357
+ else
353
358
login_reload ( "/=" + cur_machine ) ;
359
+ }
360
+
361
+ environment . page . allow_multi_host = true ; // XXX
362
+
363
+ if ( cur_machine ) {
364
+ if ( ! environment . page . allow_multi_host )
365
+ redirect_to_current_machine ( ) ;
366
+ else {
367
+ id ( "multihost-message" ) . textContent = format ( _ ( "You are already connected to '$0' in this browser session. Connecting to other hosts will allow them to execute arbitrary code on each other. Please be careful." ) , cur_machine ) ;
368
+ id ( "multihost-get-me-there" ) . addEventListener ( "click" , redirect_to_current_machine ) ;
369
+ show ( '#multihost-warning' ) ;
354
370
}
355
371
}
372
+ }
373
+
374
+ function boot ( ) {
375
+ window . onload = null ;
356
376
357
377
translate ( ) ;
358
378
if ( window . cockpit_po && window . cockpit_po [ "" ] ) {
@@ -361,6 +381,8 @@ import "./login.scss";
361
381
document . documentElement . dir = window . cockpit_po [ "" ] [ "language-direction" ] ;
362
382
}
363
383
384
+ deal_with_multihost ( ) ;
385
+
364
386
setup_path_globals ( window . location . pathname ) ;
365
387
366
388
/* Determine if we are nested or not, and switch styles */
@@ -420,6 +442,7 @@ import "./login.scss";
420
442
oauth_auto_login ( ) ;
421
443
}
422
444
} else if ( logout_intent ) {
445
+ window . localStorage . removeItem ( "current-machine" ) ;
423
446
show_login ( logout_reason ) ;
424
447
} else if ( need_host ( ) ) {
425
448
show_login ( ) ;
0 commit comments