Skip to content

Commit 494265c

Browse files
committed
WIP - show warning if multihost is allowed
1 parent 8010b87 commit 494265c

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

pkg/static/login.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
<span id="banner-message" class="pf-v5-c-alert__title"></span>
2222
</div>
2323

24+
<div id="multihost-warning" class="pf-v5-c-alert pf-m-info pf-m-inline dialog-error" aria-label="inline danger alert" hidden="true">
25+
<svg fill="currentColor" viewBox="0 0 448 512" aria-hidden="true">
26+
<path d="M224 512c35.32 0 63.97-28.65 63.97-64H160.03c0 35.35 28.65 64 63.97 64zm215.39-149.71c-19.32-20.76-55.47-51.99-55.47-154.29 0-77.7-54.48-139.9-127.94-155.16V32c0-17.67-14.32-32-31.98-32s-31.98 14.33-31.98 32v20.84C118.56 68.1 64.08 130.3 64.08 208c0 102.3-36.15 133.53-55.47 154.29-6 6.45-8.66 14.16-8.61 21.71.11 16.4 12.98 32 32.1 32h383.8c19.12 0 32-15.6 32.1-32 .05-7.55-2.61-15.27-8.61-21.71z" />
27+
</svg>
28+
<p id="multihost-message" class="pf-v5-c-alert__title"></p>
29+
<button id="multihost-get-me-there" class="pf-v5-c-button">Go there</button>
30+
</div>
31+
2432
<span id="badge"></span>
2533

2634
<div class="container" id="main">

pkg/static/login.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -338,21 +338,41 @@ import "./login.scss";
338338
event.stopPropagation();
339339
}
340340

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.
343345

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");
348347

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")
351356
login_reload("/");
352-
} else if (cur_machine && !window.location.pathname.startsWith("/=" + cur_machine)) {
357+
else
353358
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');
354370
}
355371
}
372+
}
373+
374+
function boot() {
375+
window.onload = null;
356376

357377
translate();
358378
if (window.cockpit_po && window.cockpit_po[""]) {
@@ -361,6 +381,8 @@ import "./login.scss";
361381
document.documentElement.dir = window.cockpit_po[""]["language-direction"];
362382
}
363383

384+
deal_with_multihost();
385+
364386
setup_path_globals(window.location.pathname);
365387

366388
/* Determine if we are nested or not, and switch styles */
@@ -420,6 +442,7 @@ import "./login.scss";
420442
oauth_auto_login();
421443
}
422444
} else if (logout_intent) {
445+
window.localStorage.removeItem("current-machine");
423446
show_login(logout_reason);
424447
} else if (need_host()) {
425448
show_login();

pkg/static/login.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,14 @@ label.checkbox {
354354
display: none;
355355
}
356356

357-
.login-pf #banner {
357+
.login-pf #banner, .login-pf #multihost-warning {
358358
margin-block: 1rem 0.5rem;
359359
margin-inline: 0;
360360
grid-area: banner;
361361
inline-size: 100%;
362362
}
363363

364-
#banner-message {
364+
#banner-message, #multihost-message {
365365
white-space: pre-wrap;
366366
max-block-size: 12em;
367367
overflow: auto;

0 commit comments

Comments
 (0)