From dd6e4f4f8a999e08fb932015e7dbbff19de8f9d0 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Thu, 5 Nov 2026 21:24:26 +0100 Subject: [PATCH] Fix CodeQL code-scanning alerts - Values pasted into eval'd or inline-script code go through lit() (scripts/lib/js-literal.js), which escapes <, >, /, U+2028 and U+2029 after JSON.stringify - build test and i18n-check read script tags with a DOM parser or a plain search, not HTML regexes - mcp.js parses the Authorization header without a backtracking regex --- scripts/dev.js | 3 ++- scripts/gpu-bench.js | 3 ++- scripts/i18n-check.js | 13 ++++++++++++- scripts/lib/js-literal.js | 5 +++++ scripts/lib/scenario-bot.js | 5 +++-- scripts/lib/scenario-ref.js | 3 ++- scripts/mcp.js | 5 +++-- scripts/perf-bench.js | 3 ++- scripts/weekly-architect.js | 17 +++++++++-------- scripts/weekly-puzzle.js | 17 +++++++++-------- scripts/weekly-scenario.js | 11 ++++++----- tests/agent-relay.test.js | 3 ++- tests/agent-settings.test.js | 3 ++- tests/any-home-city.test.js | 3 ++- tests/automation.test.js | 5 +++-- tests/backbone-core.test.js | 3 ++- tests/badges-variants.test.js | 7 ++++--- tests/bilbao-landing.test.js | 3 ++- tests/build.test.js | 9 +++++---- tests/cache-ports.test.js | 3 ++- tests/call-the-bank.test.js | 7 ++++--- tests/chaos-monkey.test.js | 3 ++- tests/compute-idempotent.test.js | 3 ++- tests/customer-lifecycle.test.js | 9 +++++---- tests/ddos-floods.test.js | 3 ++- tests/ddos-model.test.js | 11 ++++++----- tests/ddos-scrub-clean.test.js | 7 ++++--- tests/diagnostic-info.test.js | 5 +++-- tests/find-city.test.js | 3 ++- tests/gameplay-rules.test.js | 5 +++-- tests/gangnam.test.js | 3 ++- tests/gpu-bench.test.js | 5 +++-- tests/i18n.test.js | 5 +++-- tests/intern-optics.test.js | 7 ++++--- tests/intern-ports.test.js | 3 ++- tests/issues.test.js | 11 ++++++----- tests/latency-offers.test.js | 3 ++- tests/levels.test.js | 3 ++- tests/link-preconditions.test.js | 7 ++++--- tests/load-time.test.js | 3 ++- tests/map-2d-sprite-budget.test.js | 3 ++- tests/map-2d.test.js | 17 +++++++++-------- tests/mcp-parity.test.js | 3 ++- tests/modes.test.js | 9 +++++---- tests/noc-window.test.js | 7 ++++--- tests/own-asn.test.js | 3 ++- tests/peering-desk.test.js | 3 ++- tests/persist.test.js | 7 ++++--- tests/pop-standard.test.js | 3 ++- tests/puzzles.test.js | 7 ++++--- tests/regions.test.js | 15 ++++++++------- tests/release-story.test.js | 3 ++- tests/route-cache.test.js | 3 ++- tests/route-fuzz.test.js | 3 ++- tests/route-server-peers.test.js | 3 ++- tests/route-skip.test.js | 7 ++++--- tests/route-worker.test.js | 3 ++- tests/routing-reference.test.js | 3 ++- tests/rules-locked.test.js | 9 +++++---- tests/rules.test.js | 7 ++++--- tests/sales-desk.test.js | 5 +++-- tests/sales-trial.test.js | 15 ++++++++------- tests/save-size.test.js | 3 ++- tests/save-slots.test.js | 15 ++++++++------- tests/save-text.test.js | 3 ++- tests/scenarios-playtest.test.js | 3 ++- tests/sea-routing.test.js | 7 ++++--- tests/services.test.js | 3 ++- tests/specialist.test.js | 5 +++-- tests/speed.test.js | 5 +++-- tests/standing-orders.test.js | 5 +++-- tests/tier1-cone.test.js | 3 ++- tests/traceroute-modes.test.js | 3 ++- tests/unbuilt-pops.test.js | 7 ++++--- tests/utilities-caches.test.js | 3 ++- tests/utilities.test.js | 5 +++-- tests/webgl-coast.test.js | 3 ++- tests/webgl-context-restore.test.js | 3 ++- tests/webgl-frame-garbage.test.js | 3 ++- tests/webgl-line-joins.test.js | 3 ++- tests/webgl-map.test.js | 9 +++++---- tests/webgl-out-of-memory.test.js | 7 ++++--- tests/webgl-sprites.test.js | 3 ++- tests/webgl-zoom-sprites.test.js | 3 ++- tests/weekly-architect.test.js | 9 +++++---- tests/weekly-puzzle.test.js | 23 ++++++++++++----------- tests/weekly-scenario.test.js | 17 +++++++++-------- tests/where-things-happen.test.js | 3 ++- tests/world-layer-firefox.test.js | 5 +++-- 89 files changed, 316 insertions(+), 213 deletions(-) create mode 100644 scripts/lib/js-literal.js diff --git a/scripts/dev.js b/scripts/dev.js index 2a5ffda..2f4fab5 100644 --- a/scripts/dev.js +++ b/scripts/dev.js @@ -12,6 +12,7 @@ const http = require('node:http'); const path = require('node:path'); const { assemble, ROOT } = require('./lib/page'); const { createRelay } = require('./agent/relay'); +const { lit } = require('./lib/js-literal'); // --host/--port; a bare --host binds loopback (never undefined, which would listen on every interface). const argOf = (k) => { const i = process.argv.indexOf(k); return i >= 0 && process.argv[i + 1] && !process.argv[i + 1].startsWith('--') ? process.argv[i + 1] : null; }; @@ -27,7 +28,7 @@ const clients = new Set(); function page() { const { html, map } = assemble({ dev: true }); // Errors report a line of the assembled page; the console also says which file under src/ that is. - const hint = ``; + const hint = ``; return html.replace('', `${hint}${RELOAD}`); } diff --git a/scripts/gpu-bench.js b/scripts/gpu-bench.js index b2e45ff..59ed482 100644 --- a/scripts/gpu-bench.js +++ b/scripts/gpu-bench.js @@ -15,6 +15,7 @@ const os = require('node:os'); const http = require('node:http'); const path = require('node:path'); const { assemble, ROOT } = require('./lib/page'); +const { lit } = require('./lib/js-literal'); const args = process.argv.slice(2); const opt = (k, d) => { const i = args.indexOf('--' + k); return i >= 0 ? args[i + 1] : d; }; @@ -27,7 +28,7 @@ const TYPES = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; ch // An exported save is {app, version, S}; a plain one is S itself. const save = (() => { const d = JSON.parse(fs.readFileSync(SAVE, 'utf8')); return JSON.stringify({ S: d && d.S && d.S.pops ? d.S : d }); })(); const client = fs.readFileSync(path.join(__dirname, 'lib', 'gpu-bench-client.js'), 'utf8'); -const page = () => assemble().html.replace('', ``); +const page = () => assemble().html.replace('', ``); /* Only the page this server hands out may talk to it. Any other site open in the same browser could otherwise POST results (printed to this terminal, written to --out) or, through DNS rebinding, read the save. So the Host diff --git a/scripts/i18n-check.js b/scripts/i18n-check.js index eacf61a..7db2676 100644 --- a/scripts/i18n-check.js +++ b/scripts/i18n-check.js @@ -20,10 +20,21 @@ const SITE = path.join(__dirname, '..', 'site'); const page = () => require('./lib/page').assemble({ dev: true }).html; const LABEL = /^[a-z0-9_]+(\.[a-z0-9_]+)+$/; +// The bodies of the page's bare ', i += 8); + if (end < 0) break; + out.push(html.slice(i, end)); i = end; + } + return out; +} + // The labels the game uses, with problems in how they are used. function sourceLabels(html) { const labels = new Set(), problems = []; - const scripts = [...html.matchAll(/