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
This commit is contained in:
Frederic Jung 2026-11-05 21:24:26 +01:00
parent e7729d0a1e
commit dd6e4f4f8a
No known key found for this signature in database
89 changed files with 316 additions and 213 deletions

View file

@ -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 <script> tags. Our own assembled page, so a plain search is enough.
function inlineScripts(html) {
const out = [];
for (let i = html.indexOf('<script>'); i >= 0; i = html.indexOf('<script>', i)) {
const end = html.indexOf('</script>', 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(/<script>([\s\S]*?)<\/script>/g)].map((m) => m[1]).join('\n');
const scripts = inlineScripts(html).join('\n');
for (const m of scripts.matchAll(CALL)) {
const l = m[2].slice(1, -1);
if (!LABEL.test(l)) problems.push(`${m[1]}(${m[2].slice(0, 60)}…): not a label like 'area.some_words'`);