From 9ee37bcf5fe21e7b234c1a946dff592c9ecaf64d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Seren?= Date: Fri, 12 Jan 2024 15:31:22 +0100 Subject: [PATCH] Bugfix: Prefix the sessionStorage data with pathname In case of multiple xpra sessions behind a single domain (i.e. reverse proxy), the sessions will overwrite their settings inside the sessionStorage when the user navigates between the sessions within a browser tab. This change will store the sessionStorage data prefixed with the pathname of the xpra session. This fixes #278 --- html5/connect.html | 9 ++------- html5/index.html | 10 +++------- html5/js/Utilities.js | 28 +++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/html5/connect.html b/html5/connect.html index c241d9c3..bf552024 100644 --- a/html5/connect.html +++ b/html5/connect.html @@ -617,12 +617,7 @@

Advanced options

function add_prop(prop, value, first) { if (Utilities.hasSessionStorage()) { - //we're using sessionStorage, no need for URL - if (value === null || value === "undefined") { - sessionStorage.removeItem(prop); - } else { - sessionStorage.setItem(prop, value); - } + Utilities.setSessionStorageValue(prop, value); return ""; } if (value === null || value === "undefined") { @@ -1618,7 +1613,7 @@

Advanced options

}); //delete session params: try { - sessionStorage.clear(); + sessionStorage.removeItem(Utilities.getSessionStoragePrefix()); } catch (e) { //ignore } diff --git a/html5/index.html b/html5/index.html index 990eb02a..e00ab381 100644 --- a/html5/index.html +++ b/html5/index.html @@ -793,12 +793,12 @@

Xpra Bug Report

} try { - sessionStorage.removeItem("password"); + Utilities.setSessionStorageValue("password",null); } catch (e) { //ignore } try { - sessionStorage.removeItem("token"); + Utilities.setSessionStorageValue("token",null); } catch (e) { //ignore } @@ -1033,11 +1033,7 @@

Xpra Bug Report

const has_session_storage = Utilities.hasSessionStorage(); function add_prop(prop, value) { if (has_session_storage) { - if (value === null || value === "undefined") { - sessionStorage.removeItem(prop); - } else { - sessionStorage.setItem(prop, value); - } + Utilities.setSessionStorageValue(prop, value); } else { if (value === null || value === "undefined") { value = ""; diff --git a/html5/js/Utilities.js b/html5/js/Utilities.js index 09e022f3..d8082632 100644 --- a/html5/js/Utilities.js +++ b/html5/js/Utilities.js @@ -590,9 +590,7 @@ const Utilities = { } let value = getParameter(property); try { - if (value === undefined && typeof sessionStorage !== "undefined") { - value = sessionStorage.getItem(property); - } + value = Utilities.getessionStorageValue(property); } catch { value = null; } @@ -623,6 +621,30 @@ const Utilities = { } }, + getessionStorageValue(property) { + const params = JSON.parse(sessionStorage.getItem(Utilities.getSessionStoragePrefix())) + if (property in params) { + return params[property] + } + return null; + }, + + setSessionStorageValue(property, value) { + const prefix = Utilities.getSessionStoragePrefix(); + let params = JSON.parse(sessionStorage.getItem(prefix)) || {} + if (value === null || value === "undefined") { + delete params[property]; + } else { + params[property] = value; + } + sessionStorage.setItem(prefix, JSON.stringify(params)); + }, + + getSessionStoragePrefix() { + const urlPath = new URL(window.location.href).pathname + return urlPath.substring(0, urlPath.lastIndexOf("/")); + }, + getConnectionInfo() { if (!Object.hasOwn(navigator, "connection")) { return {};