From a42db4128a50583bcc8f4bb0f8548a6dcd153e57 Mon Sep 17 00:00:00 2001 From: dr-carlos Date: Sat, 18 Sep 2021 06:26:29 +0930 Subject: [PATCH] Fix unsafe location.hash usage in saveBuild --- builder.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builder.js b/builder.js index 9363376..55bd800 100644 --- a/builder.js +++ b/builder.js @@ -889,14 +889,15 @@ function saveBuild() { if (player_build) { let savedBuilds = window.localStorage.getItem("builds") === null ? {} : JSON.parse(window.localStorage.getItem("builds")); let saveName = document.getElementById("build-name").value; - if ((!Object.keys(savedBuilds).includes(saveName) || document.getElementById("saved-error").textContent !== "") && location.hash !== "") { - savedBuilds[saveName] = location.hash.replace("#", ""); + let encodedBuild = encodeBuild(); + if ((!Object.keys(savedBuilds).includes(saveName) || document.getElementById("saved-error").textContent !== "") && encodedBuild !== "") { + savedBuilds[saveName] = encodedBuild.replace("#", ""); window.localStorage.setItem("builds", JSON.stringify(savedBuilds)); document.getElementById("saved-error").textContent = ""; document.getElementById("saved-build").textContent = "Build saved"; } else { - if (location.hash === "") + if (encodedBuild === "") document.getElementById("saved-error").textContent = "Empty build"; else document.getElementById("saved-error").textContent = "Exists. Overwrite?";