Repository navigation
fix(ui): escape and pin the ledger innerHTML sink (#107) - #114
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #107
Summary
Closes the last unpinned
innerHTMLsink in the UI bundle.src/ui/virtual.jsfeeds server-provided row data into
element.innerHTMLviarenderRow→ledgerRowHtml; until now no test asserted that that escaping actually holds,so a future
renderRowchange interpolating a field raw would regresssilently (invisible both to Snyk and to the suite).
What changed
src/ui/app.jsledgerRowHtmlis now exported so it is directly testable.row.turn.index,row.turn.steps.lengthandrow.step?.index ?? "?"are wrapped inescapeHtml(...)— output isbyte-identical for real data (digits survive escaping unchanged).
row?.typeoptional access plusif (!row?.event) return "";, so a bad row can no longer throw aTypeErrorinside the virtual-listrequestAnimationFrameframe.statusClass(...)— a whitelist of fivefixed tokens — rather than escaping, by design.
test/security.test.ts— new behavioural pin(
ledgerRowHtml escapes hostile row fields before the virtual-list sink):renderRow: (row) => ledgerRowHtml(row)inapp.js;element.innerHTML = this.renderRow(row, index);and exactlyone
.innerHTML =assignment insrc/ui/virtual.js;<img src=x onerror=alert(1)>and aquote-breaking
" onmouseover=payload, plus a bare-handler token;of a benign same-shape row, so any raw
</>reaching the output failsthe test regardless of which tag appears;
rendered class token, and step index
0is pinned for??semantics.One intentional deviation
A literal
assert.doesNotMatch(html, /onerror/)would be wrong after correctescaping:
escapeHtmlleaves letters intact, soonerrorsurvives as inerttext inside
<img ...>. The pin instead asserts that no live handlerreaches 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✅Notes
dist-tui/anddist-server/are unaffected:app.jsis served unbundled(
src/ui/index.htmlloads it as a module), so no bundle-freshness gate.