Repository navigation
fix(viewer): escape ts and superseded_by cells; badge() escapes at the helper (#11) - #33
Merged
Merged
Conversation
…e helper Issue #11 (stored-XSS defense-in-depth). The row template renders via innerHTML and every field passed esc() except the ts cell and the superseded badge (badge() interpolated its text raw). A hostile store value could execute in the viewer's own origin, inheriting its same-origin write access to the whole store. - extract the pure render helpers (esc, badge, new tsCell) into a DOM-free <script id="viewer-helpers"> block so tests can eval the SHIPPED code; badge now escapes text and class; tsCell escapes both segments (slice-then-escape order preserved). - row template: ts cell -> tsCell(m.ts); superseded badge -> badge(); type/scope call sites pass raw (badge escapes once, no double-escape). - audited remaining sinks: toast/askModal use textContent; option lists and data-attributes already escaped. - viewer.test.ts evals the helpers block from page.html and asserts escaping of hostile values plus source tripwires (no ${m.ts.} or ${m.superseded_by} interpolation, helpers precede main script).
|
🎉 This PR is included in version 0.6.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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 #11 (stored-XSS defense-in-depth in the viewer, from the 2026-10-21 security review).
Problem
The row template renders store data via
innerHTML. Every field passed throughesc()except two cells:${m.ts.split("T")[0]}<br>${(m.ts.split("T")[1] || "").slice(0,8)}badge(... \superseded → ${m.superseded_by.slice(0,8)}`)—badge()` interpolated its text raw.ts/superseded_byare normally code-written ISO strings, but the reader must not trust the store: a hostile file on disk (or the pre-#9 import route) planting<img src=x onerror=…>would execute in the viewer's own origin, inheriting its same-origin write access to the whole store.Fix
<script id="viewer-helpers">block inpage.htmlholding the pure, DOM-free render helpers:esc,badge(now escapes both its text and its class argument), and a newtsCell(ts)that escapes the date and time segments. Inline scripts share global scope, so the main script uses them unchanged.${tsCell(m.ts)}andbadge("status-superseded", "superseded → " + m.superseded_by.slice(0,8)).badge("type"/"scope", …)call sites pass raw values (badge escapes once — no double-escaping).toast()andaskModal()usetextContent, option lists and data-attributes already usedesc().Tests
test/viewer.test.tsgains a describe block that evals the shipped helpers block (extracted frompage.html, not a copy) and asserts:badge()neutralizes<img src=x onerror="alert(1)">to the exact escaped string; class argument escaped too;tsCell()escapes both segments — including the slice-before-escape order ("2026-01-01T<img…" → "2026-01-01<br><img src") — and renders a normal ISO ts unchanged;${m.ts.or${m.superseded_byinterpolation, uses${tsCell(m.ts)}, and the helpers block precedes the main script.Gate: 256 pass / 4 skip / 0 fail,
tscclean, biome clean (advisory warnings unchanged).Compatibility
Visual output for well-formed rows is byte-identical; only hostile values change (they render as inert text now). No server/API change.