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

@ -5,6 +5,7 @@ const { execFileSync } = require('node:child_process');
const { load } = require('./harness');
const OUT = require('node:fs').mkdtempSync(require('node:path').join(require('node:os').tmpdir(), 'tubes-build-'));
const { lit } = require('../scripts/lib/js-literal');
const root = path.join(__dirname, '..');
function playedGame() {
@ -113,13 +114,13 @@ test('in-app release notes stay short and link to the full notes on GitHub', ()
const { ev, errors } = load();
const long = ['Tier 1 networks can lay their own subsea cable (#22). Pick two cities with a landing station, pay a lot, wait.',
'Short one.', 'A 1.6T wave is now cheaper. More text here.', 'Four.', 'Five.', 'Six.', 'Seven.'];
const h = ev(`notesHtml(${JSON.stringify(long)},'9.9.9')`);
const h = ev(`notesHtml(${lit(long)},'9.9.9')`);
assert.match(h, /lay their own subsea cable \(#22\)\./);
assert.doesNotMatch(h, /Pick two cities/, 'only the first sentence');
assert.match(h, /A 1\.6T wave is now cheaper\./, 'decimals do not end a sentence');
assert.match(h, /and 2 more changes/);
assert.match(h, /releases\/tag\/v9\.9\.9/, 'links to the full notes');
const short = ev(`notesHtml(${JSON.stringify(['One fix.', 'Another fix.'])},'9.9.9')`);
const short = ev(`notesHtml(${lit(['One fix.', 'Another fix.'])},'9.9.9')`);
assert.doesNotMatch(short, /releases\/tag/, 'short notes need no link');
assert.equal(ev(`slimNote('${'x'.repeat(300)}')`).length <= 140, true);
assert.deepEqual(errors, []);
@ -129,7 +130,7 @@ test('the big-network benchmark save loads cleanly and routes traffic', () => {
const fs = require('node:fs'), path = require('node:path');
const save = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
const { ev, errors } = load();
ev(`S=migrate(JSON.parse(${JSON.stringify(save)}));UI.started=true;compute();renderAll()`);
ev(`S=migrate(JSON.parse(${lit(save)}));UI.started=true;compute();renderAll()`);
assert.ok(ev('Object.keys(S.pops).length') >= 100 && ev('S.pni.length') >= 900 && ev('S.caches.length') >= 800, 'still a big network');
assert.ok(ev('R.served') > 10000, 'and it carries traffic');
assert.deepEqual(errors, []);