mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 14:30:52 +00:00
fix(web-app-docs): encode line breaks in redirects, navigate by built URLs
- py/http-response-splitting (server.py:87): _redirect percent-encodes CR and LF in the Location header - js/xss-through-dom (versions.js:82, languages.js:25): both switchers navigate to the URL they built instead of select.value The new cases in test_server.py, versions.test.js and languages.test.js fail without the fix and pass with it. 🎯 Fix: 92 % 💥 Break: 3 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: 100 % 🏆 Score: 89 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d9c278ce46
commit
6e045bced8
6 files changed
+79
-16
No files matched your search
@@ -20,7 +20,10 @@ function select(dataset) {
|
||||
return {
|
||||
dataset,
|
||||
children: [],
|
||||
value: "",
|
||||
selectedIndex: -1,
|
||||
get value() {
|
||||
return this.children[this.selectedIndex]?.value ?? "";
|
||||
},
|
||||
listeners: {},
|
||||
replaceChildren(...nodes) {
|
||||
this.children = nodes;
|
||||
@@ -72,7 +75,17 @@ test("the switcher lists every built language and keeps the page", async () => {
|
||||
test("choosing a language navigates to the same page in it", async () => {
|
||||
const { switcher, window } = await load({ version: "v14.1.0", language: "en", page: "index" });
|
||||
|
||||
switcher.value = switcher.children[1].value;
|
||||
switcher.selectedIndex = 1;
|
||||
switcher.listeners.change();
|
||||
|
||||
assert.equal(window.location.href, "/v14.1.0/de/index.html");
|
||||
});
|
||||
|
||||
test("navigation follows the built page url, never the option value read back from the DOM", async () => {
|
||||
const { switcher, window } = await load({ version: "v14.1.0", language: "en", page: "index" });
|
||||
|
||||
switcher.children[1].value = "javascript:alert(document.domain)";
|
||||
switcher.selectedIndex = 1;
|
||||
switcher.listeners.change();
|
||||
|
||||
assert.equal(window.location.href, "/v14.1.0/de/index.html");
|
||||
|
||||
@@ -35,9 +35,21 @@ function element(tag, fields = {}) {
|
||||
addEventListener(type, handler) {
|
||||
this.listeners[type] = handler;
|
||||
},
|
||||
fire(type) {
|
||||
this.listeners[type]?.();
|
||||
this[`on${type}`]?.();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function switcher(dataset) {
|
||||
return Object.defineProperty(element("select", { dataset, selectedIndex: -1 }), "value", {
|
||||
get() {
|
||||
return this.children[this.selectedIndex]?.value ?? "";
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function load(selectors = {}) {
|
||||
let ready = null;
|
||||
const window = {
|
||||
@@ -136,18 +148,31 @@ test("build page shows progress and the failure log, reloads once built", () =>
|
||||
});
|
||||
|
||||
test("start wires the switcher and polls only on overview and build pages", async () => {
|
||||
const select = element("select", { dataset: { current: "latest", page: "index" } });
|
||||
const select = switcher({ current: "latest", page: "index" });
|
||||
const sidebarOnly = load({ "select.docs-version-switcher": [select] });
|
||||
sidebarOnly.start();
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
|
||||
assert.equal(select.children.length, 4);
|
||||
assert.deepEqual(sidebarOnly.window.intervals, []);
|
||||
select.value = "/v14.0.0/index.html";
|
||||
select.listeners.change();
|
||||
select.selectedIndex = 1;
|
||||
select.fire("change");
|
||||
assert.equal(sidebarOnly.window.location.href, "/v14.0.0/index.html");
|
||||
|
||||
const overview = load({ "tbody[data-versions]": [element("tbody")] });
|
||||
overview.start();
|
||||
assert.deepEqual(overview.window.intervals, [2000]);
|
||||
});
|
||||
|
||||
test("switching follows the built version url, never the option value read back from the DOM", async () => {
|
||||
const select = switcher({ current: "latest", page: "index" });
|
||||
const { window, start } = load({ "select.docs-version-switcher": [select] });
|
||||
start();
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
|
||||
select.children[1].value = "javascript:alert(document.domain)";
|
||||
select.selectedIndex = 1;
|
||||
select.fire("change");
|
||||
|
||||
assert.equal(window.location.href, "/v14.0.0/index.html");
|
||||
});
|
||||
Reference in new issue
Block a user