Skip to content

Commit

Permalink
Bugfix: Prefix the sessionStorage data with pathname
Browse files Browse the repository at this point in the history
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
  • Loading branch information
timeu committed Jan 12, 2024
1 parent 7f448ab commit 9ee37bc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
9 changes: 2 additions & 7 deletions html5/connect.html
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,7 @@ <h4 class="panel-title">Advanced options</h4>

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") {
Expand Down Expand Up @@ -1618,7 +1613,7 @@ <h4 class="panel-title">Advanced options</h4>
});
//delete session params:
try {
sessionStorage.clear();
sessionStorage.removeItem(Utilities.getSessionStoragePrefix());
} catch (e) {
//ignore
}
Expand Down
10 changes: 3 additions & 7 deletions html5/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -793,12 +793,12 @@ <h2>Xpra Bug Report</h2>
}

try {
sessionStorage.removeItem("password");
Utilities.setSessionStorageValue("password",null);
} catch (e) {
//ignore
}
try {
sessionStorage.removeItem("token");
Utilities.setSessionStorageValue("token",null);
} catch (e) {
//ignore
}
Expand Down Expand Up @@ -1033,11 +1033,7 @@ <h2>Xpra Bug Report</h2>
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 = "";
Expand Down
28 changes: 25 additions & 3 deletions html5/js/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {};
Expand Down

0 comments on commit 9ee37bc

Please sign in to comment.