Skip to content

fix(ui): escape and pin the ledger innerHTML sink (#107) - #114

Merged
NicoGenti merged 1 commit into
mainfrom
feat/issue-107-ledger-innerhtml-pin
Nov 20, 2026
Merged

NicoGenti merged 1 commit into
mainfrom
feat/issue-107-ledger-innerhtml-pin

Conversation

@NicoGenti

Copy link
Copy Markdown
Owner

Closes #107

Summary

Closes the last unpinned innerHTML sink in the UI bundle. src/ui/virtual.js
feeds server-provided row data into element.innerHTML via renderRow →
ledgerRowHtml; until now no test asserted that that escaping actually holds,
so a future renderRow change interpolating a field raw would regress
silently (invisible both to Snyk and to the suite).

What changed

  • src/ui/app.js
    • ledgerRowHtml is now exported so it is directly testable.
    • Raw interpolations of row.turn.index, row.turn.steps.length and
      row.step?.index ?? "?" are wrapped in escapeHtml(...) — output is
      byte-identical for real data (digits survive escaping unchanged).
    • Malformed-row guard: row?.type optional access plus
      if (!row?.event) return "";, so a bad row can no longer throw a
      TypeError inside the virtual-list requestAnimationFrame frame.
    • The class attributes stay on statusClass(...) — a whitelist of five
      fixed tokens — rather than escaping, by design.
  • test/security.test.ts — new behavioural pin
    (ledgerRowHtml escapes hostile row fields before the virtual-list sink):
    • wiring pin: renderRow: (row) => ledgerRowHtml(row) in app.js;
    • sink pin: element.innerHTML = this.renderRow(row, index); and exactly
      one .innerHTML = assignment in src/ui/virtual.js;
    • hostile turn/step/event rows: <img src=x onerror=alert(1)> and a
      quote-breaking " onmouseover= payload, plus a bare-handler token;
    • a tag-skeleton comparison: the hostile row's tag sequence must equal that
      of a benign same-shape row, so any raw </> reaching the output fails
      the test regardless of which tag appears;
    • the statusClass whitelist is pinned both on the function and on the
      rendered class token, and step index 0 is pinned for ?? semantics.

One intentional deviation

A literal assert.doesNotMatch(html, /onerror/) would be wrong after correct
escaping: escapeHtml leaves letters intact, so onerror survives as inert
text inside &lt;img ...&gt;. The pin instead asserts that no live handler
reaches an attribute position (quote-aware parse) and that the tag skeleton is
unchanged — stricter in the meaningful sense.

Verification

  • npm run check — typecheck + typecheck:tui + full suite: 829/829 pass ✅
  • node --test test/security.test.ts — 44/44 pass ✅
  • Code review: approved (no required findings remaining).

Notes

  • dist-tui/ and dist-server/ are unaffected: app.js is served unbundled
    (src/ui/index.html loads it as a module), so no bundle-freshness gate.

@NicoGenti
NicoGenti merged commit 2e2dfc6 into main Nov 20, 2026
7 checks passed
@NicoGenti
NicoGenti deleted the feat/issue-107-ledger-innerhtml-pin branch November 20, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui: pin innerHTML sink in virtual.js renderRow (unescaped-interpolation guard)

1 participant