diff --git a/bible-local/02-architecture.md b/bible-local/02-architecture.md index 831df1c..91d0ee0 100644 --- a/bible-local/02-architecture.md +++ b/bible-local/02-architecture.md @@ -349,4 +349,7 @@ Rules: quoted attributes. Never interpolate data into JavaScript event attributes. Cart and rental controls carry escaped LOT values in `data-lot` and dispatch through delegated listeners. Sync errors are escaped as text; toast messages use -`textContent`. Run `node scripts/tests/html-security.cjs` for the regression check. +`textContent`. Run `node scripts/tests/html-security.cjs` for the fast regression check and +`node scripts/tests/html-security-browser.cjs` for real DOM parsing and delegated +events in headless Chrome (`CHROME_BIN` overrides the executable). The browser +check uses synthetic data, controlled API responses and a temporary profile. diff --git a/bible-local/issue-plan-2026-10-26.md b/bible-local/issue-plan-2026-10-26.md index e402881..84d1cf1 100644 --- a/bible-local/issue-plan-2026-10-26.md +++ b/bible-local/issue-plan-2026-10-26.md @@ -10,7 +10,7 @@ on `fix/issue-acceptance-and-migration-safety`. | Order | Issue | Implementation and acceptance | Status | | --- | --- | --- | --- | | 1 | [#2](https://git.mchus.pro/mchus/QuoteForge/issues/2) | Block foreign Host/Origin/Referer and cross-site browser requests in both routers; validate API body types; refuse saved-password reuse for a changed host/port/user. Middleware and real setup/runtime router tests reject attacks without changing saved credentials or user data. | Acceptance passed | -| 2 | [#4](https://git.mchus.pro/mchus/QuoteForge/issues/4) | Move LOT-bearing cart/rental events to delegated listeners and escaped data attributes; escape BOM and sync output; share HTML escaping; render toast as text. Malicious LOT regression checks and template tests must pass. | Implemented | +| 2 | [#4](https://git.mchus.pro/mchus/QuoteForge/issues/4) | Move LOT-bearing cart/rental events to delegated listeners and escaped data attributes; escape BOM and sync output; share HTML escaping; render toast as text. Malicious LOT regression checks and headless Chrome DOM checks pass. | Acceptance passed | | 3 | [#7](https://git.mchus.pro/mchus/QuoteForge/issues/7) | Require a fresh verified archive outside rotation before reset, refuse unsynced/legacy states without explicit force, use transactional deletion, remove environment-triggered reset. Verify refusal, ZIP restore, backup failure and rollback. | Implemented | | 4 | [#5](https://git.mchus.pro/mchus/QuoteForge/issues/5) | Persist TLS mode/CA in SQLite, expose setup controls, share policy across setup/sync/migration DSNs. Verify certificate trust, hostname checks, plaintext fallback policy and settings round-trip. | Implemented | | 5 | [#3](https://git.mchus.pro/mchus/QuoteForge/issues/3) | Keep each migration file in one session, execute verify headers before history insertion, propagate FK failures. Verify failed queries/checks never enter history. | Implemented | @@ -57,3 +57,14 @@ password reuse for a changed destination. Local reads still succeed. Saved credentials, project/configuration counts and the pending queue remain unchanged. The setup router construction was extracted without changing its routes so this regression exercises the same middleware registration as startup. + +### Issue #4 + +`node scripts/tests/html-security-browser.cjs` passes in headless Chrome with +an isolated temporary profile. It executes the actual template rendering +functions in a browser DOM with controlled API responses. Both cart layouts, +rental, parsed BOM, toast, pending sync errors, error history and repair errors +preserve malicious strings as text. Real click/change/focus events preserve +LOT values through delegated handlers; no injected elements or payload execution +are observed. This is a rendering integration check, not a full application +navigation test. Set `CHROME_BIN` outside macOS to select a Chrome executable. diff --git a/scripts/tests/html-security-browser.cjs b/scripts/tests/html-security-browser.cjs new file mode 100644 index 0000000..faea707 --- /dev/null +++ b/scripts/tests/html-security-browser.cjs @@ -0,0 +1,98 @@ +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const {spawnSync} = require('node:child_process'); + +const index = fs.readFileSync('web/templates/index.html', 'utf8'); +const base = fs.readFileSync('web/templates/base.html', 'utf8'); +function extract(source, name) { + const match = source.match(new RegExp(`^( *)(?:async )?function ${name}\\(`, 'm')); + assert(match, `Missing function ${name}`); + const end = source.indexOf(`\n${match[1]}}`, match.index); + assert(end > match.index); + return source.slice(match.index, end + match[1].length + 2); +} + +const functions = [ + ...['renderMultiSelectTab', 'renderMultiSelectTabWithSections', 'renderRentalTab', '_renderBOMParsedTable'].map(n => extract(index, n)), + ...['showToast', 'loadSyncInfo', 'repairPendingChanges'].map(n => extract(base, n)), +].join('\n'); +const ids = new Set([...functions.matchAll(/getElementById\('([^']+)'\)/g)].map(m => m[1])); +const fixtures = [...ids].map(id => id.endsWith('-body') ? `
` : `
`).join(''); +const listeners = index.split('`); +const chrome = process.env.CHROME_BIN || '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; +try { + const result = spawnSync(chrome, ['--headless', '--disable-gpu', '--no-first-run', '--disable-background-networking', + '--user-data-dir=' + path.join(directory, 'profile'), '--virtual-time-budget=1000', '--dump-dom', 'file://' + target], {encoding: 'utf8', timeout: 30000}); + assert.ifError(result.error); + assert.equal(result.status, 0, result.stderr); + const outcome = result.stdout.match(/
([\s\S]*?)<\/pre>/)?.[1];
+    assert.equal(outcome, 'PASS', outcome || 'Browser did not finish');
+    console.log('Browser HTML security regressions passed');
+} finally {
+    fs.rmSync(directory, {recursive: true, force: true});
+}