diff --git a/pkg/static/login.html b/pkg/static/login.html
index d91201916952..3740f0a7e490 100644
--- a/pkg/static/login.html
+++ b/pkg/static/login.html
@@ -21,6 +21,14 @@
+
+
diff --git a/pkg/static/login.js b/pkg/static/login.js
index e3956d0f9286..e3db47a7b963 100644
--- a/pkg/static/login.js
+++ b/pkg/static/login.js
@@ -338,21 +338,41 @@ import "./login.scss";
event.stopPropagation();
}
- function boot() {
- window.onload = null;
+ function deal_with_multihost() {
+ // If we are currently logged in to some machine, but still
+ // end up on the login page, we are about to load resources
+ // from two machines into the same browser origin.
- if (!environment.page.allow_multi_host) {
- // If we are currently logged in, we do not want to allow
- // another login to a different machine. So we redirect to
- // the current login.
+ const cur_machine = window.localStorage.getItem("current-machine");
- const cur_machine = window.localStorage.getItem("current-machine");
- if (cur_machine == "localhost" && window.location.pathname.startsWith("/=")) {
+ // Protect against outdated cur_machine values.
+ if (cur_machine == "localhost" && !window.location.pathname.startsWith("/="))
+ return;
+ if (cur_machine && cur_machine != "localhost" && window.location.pathname.startsWith("/=" + cur_machine))
+ return;
+
+ function redirect_to_current_machine() {
+ if (cur_machine == "localhost")
login_reload("/");
- } else if (cur_machine && !window.location.pathname.startsWith("/=" + cur_machine)) {
+ else
login_reload("/=" + cur_machine);
+ }
+
+ environment.page.allow_multi_host = true; // XXX
+
+ if (cur_machine) {
+ if (!environment.page.allow_multi_host)
+ redirect_to_current_machine();
+ else {
+ 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);
+ id("multihost-get-me-there").addEventListener("click", redirect_to_current_machine);
+ show('#multihost-warning');
}
}
+ }
+
+ function boot() {
+ window.onload = null;
translate();
if (window.cockpit_po && window.cockpit_po[""]) {
@@ -361,6 +381,8 @@ import "./login.scss";
document.documentElement.dir = window.cockpit_po[""]["language-direction"];
}
+ deal_with_multihost();
+
setup_path_globals(window.location.pathname);
/* Determine if we are nested or not, and switch styles */
@@ -420,6 +442,7 @@ import "./login.scss";
oauth_auto_login();
}
} else if (logout_intent) {
+ window.localStorage.removeItem("current-machine");
show_login(logout_reason);
} else if (need_host()) {
show_login();
diff --git a/pkg/static/login.scss b/pkg/static/login.scss
index 33e664562fa9..b1fddb29d11f 100644
--- a/pkg/static/login.scss
+++ b/pkg/static/login.scss
@@ -354,14 +354,14 @@ label.checkbox {
display: none;
}
-.login-pf #banner {
+.login-pf #banner, .login-pf #multihost-warning {
margin-block: 1rem 0.5rem;
margin-inline: 0;
grid-area: banner;
inline-size: 100%;
}
-#banner-message {
+#banner-message, #multihost-message {
white-space: pre-wrap;
max-block-size: 12em;
overflow: auto;