diff --git a/docs/09_SECURITY_PRIVACY.md b/docs/09_SECURITY_PRIVACY.md index 90ea995..e0b5b70 100644 --- a/docs/09_SECURITY_PRIVACY.md +++ b/docs/09_SECURITY_PRIVACY.md @@ -26,6 +26,29 @@ | T7 | XSS via filenames/titles echoed into UI (result cards, toasts) | Weird characters in file name | Same as T1 — text interpolation only; filenames additionally sanitized for the *download* name (`[\\/:*?"<>|]` → `_`). | | T8 | Clipboard abuse | "Copy URL" action | Uses `navigator.clipboard.writeText` on explicit user click only; never reads the clipboard. | +### Pass performed 2026-07-26 (Phase 5) + +| # | Now enforced by | +|---|---| +| T1 | `tests/unit/core/fixtures.test.ts` parses `malformed/script-injection.html` and asserts the payloads survive as inert text. `DOMParser('text/html')` never executes scripts, and `{@html}` is barred by `npm run guard`. | +| T2 | `tests/unit/core/limits.test.ts` plus the caps in `core/limits.ts`. Measured: a 100k-node file parses without exhausting anything (`11 §6`). | +| T3 | `malformed/js-url.html` at parse level, **and now** `tests/unit/browser/open-url.test.ts` at the point of use — `javascript:`, `data:`, `file:`, `chrome:`, `vbscript:` and case-shouted variants are all refused before `tabs.create`. | +| T4 | `tests/unit/import/safety-backup.test.ts`. | +| T5 | `npm audit --omit=dev` reports **0** — every open Dependabot alert is `development` scope. | +| T6 | Human; nothing in code. | +| T7 | `sanitizeFilename` (`tests/unit/browser/download.test.ts`); everything else reaches the DOM through Svelte text interpolation. | +| T8 | `browser/clipboard.ts` — write-only, click-only, never reads. Implemented in Phase 5; it had been specified in `06 §3.3` and here since the start but never built. | + +Two gaps this pass closed, both of which had gone unnoticed because nothing +mechanical was watching: + +- **The permission list had no test at all.** `tests/unit/manifest.test.ts` now + asserts `['bookmarks', 'storage']` exactly against `wxt.config.ts`, plus the + absence of `host_permissions`, `content_scripts`, a background worker and + eight other reach-widening keys. Verified to fail by adding `'tabs'`. +- **"Copy URL" did not exist**, so T8 above described the mitigation for a + feature that was never shipped. + ## 3. Secure coding rules (enforced) - `{@html}` — **forbidden**. Enforced by the canonical grep gate (`08 §3`) and @@ -52,9 +75,16 @@ a **minor-version** event at minimum. ## 5. Release integrity -- Builds are reproducible from a clean checkout: `npm ci && npm run zip`. +- Builds are **content**-reproducible from a clean checkout: `npm ci && npm run + zip`. Verified 2026-07-26 by building the same commit in a fresh clone and in + the working tree — every entry in the two zips has an identical name and + CRC32. The archives' SHA-256 hashes still differ, because `wxt zip` records + file mtimes and nothing normalizes them (there is no `SOURCE_DATE_EPOCH` + support). Do not claim byte-identical rebuilds. - GitHub Releases attach the exact zip uploaded to CWS + `SHA256SUMS.txt` - so users can verify store build ↔ source correspondence. + so users can verify store build ↔ source correspondence. That works on the + released artifact itself, which is the same file in both places — it is not a + claim that a third party can rebuild the same hash. - Tags are signed (GPG) — consistent with the tracker-repo signing practice. ## 6. Vulnerability reporting diff --git a/docs/11_TESTING.md b/docs/11_TESTING.md index 4578ef6..8336784 100644 --- a/docs/11_TESTING.md +++ b/docs/11_TESTING.md @@ -150,3 +150,27 @@ generate-huge.ts # script: emits 100k+1 node file on demand - Preview render after parse: < 500 ms (lazy tree). - Manager cold open: interactive < 1 s. - Import 10k nodes: progress visible ≤ 500 ms after start; cancel ≤ 1 s. + +### Measured 2026-07-26 — Phase 5 + +A generated 100 000-node Netscape file (11.2 MB, 99 000 bookmarks in 1 000 +folders), timed **under jsdom**: + +| Stage | Time | +|---|---| +| `detectFormat` | 0 ms | +| `parseNetscapeHtml` | **2 869 ms** | +| `buildUrlIndex` | 42 ms | +| `diffAgainstBrowser` | 53 ms | +| `serializeNetscapeHtml` | 72 ms | + +⚠️ **This does not settle the 2 s budget either way.** Everything except the +parse is pure JS and comfortably fast; the parse is dominated by `DOMParser`, +and jsdom's parse5 implementation is roughly an order of magnitude slower than +Chrome's native parser. The budget is about the real browser, so the honest +reading is "≤ 2.9 s in the slowest environment we can measure from a test". + +The number that decides it has to come from Chrome. Added to the §5 checklist: + +- [ ] Generate a 100k-node HTML file, import it in a real browser, and time + from drop to preview. Record the number here rather than re-deriving it. diff --git a/src/lib/browser/clipboard.ts b/src/lib/browser/clipboard.ts new file mode 100644 index 0000000..4da9259 --- /dev/null +++ b/src/lib/browser/clipboard.ts @@ -0,0 +1,23 @@ +/** + * Copying a bookmark's URL — the docs/09 T8 surface. + * + * Purpose: the only place this extension touches the clipboard. + * Inputs: a URL string, from an explicit user click. + * Guarantees: **write only**. Nothing here ever reads the clipboard, and the + * write is never triggered by anything but a click, so no permission is + * needed — `clipboard-write` is granted to a transient user activation. + * Never throws; returns whether the copy landed. + */ + +export async function copyToClipboard(text: string): Promise { + const clipboard = globalThis.navigator?.clipboard; + // Absent in a non-secure context and in jsdom. A missing clipboard is a + // "could not copy", not a crash. + if (clipboard === undefined) return false; + try { + await clipboard.writeText(text); + return true; + } catch { + return false; + } +} diff --git a/src/lib/components/EditTab.svelte b/src/lib/components/EditTab.svelte index e13c92b..6ee51a4 100644 --- a/src/lib/components/EditTab.svelte +++ b/src/lib/components/EditTab.svelte @@ -9,6 +9,7 @@ subscribe, update, } from '../browser/bookmarks'; + import { copyToClipboard } from '../browser/clipboard'; import { BmBrowserError } from '../browser/errors'; import { openBookmarkUrl } from '../browser/open-url'; import { findDuplicateGroups } from '../core/dedupe'; @@ -32,6 +33,7 @@ import { canMoveInto, moveTargets } from '../edit/move-target'; import { resolveKey, visibleRows } from '../edit/tree-keyboard'; import { num, t } from '../i18n/index.svelte'; + import { pushToast } from '../stores/toast.svelte'; import Callout from './Callout.svelte'; import ConfirmDialog from './ConfirmDialog.svelte'; import DuplicatePanel from './DuplicatePanel.svelte'; @@ -188,6 +190,13 @@ } } + /** docs/06 §3.3's "Copy URL". Write-only, on an explicit click (docs/09 T8). */ + async function copyUrl(url: string): Promise { + if (url === '') return; + const copied = await copyToClipboard(url); + pushToast(t(copied ? 'edit.copied' : 'edit.copyFailed'), copied ? 'success' : 'danger'); + } + async function commitRename(id: string, title: string): Promise { renamingId = undefined; const node = findNode(roots, id); @@ -335,6 +344,7 @@ oncancelRename={() => (renamingId = undefined)} ondelete={() => (pendingDelete = row.node)} onopen={() => void openBookmarkUrl(row.node.url ?? '')} + oncopyUrl={() => void copyUrl(row.node.url ?? '')} onmoveTo={() => (movingNode = row.node)} ondragstart={() => (draggingId = row.node.id)} ondropinto={() => onDrop(row.node.id)} diff --git a/src/lib/components/TreeRow.svelte b/src/lib/components/TreeRow.svelte index 586ca6f..0df1765 100644 --- a/src/lib/components/TreeRow.svelte +++ b/src/lib/components/TreeRow.svelte @@ -17,6 +17,7 @@ onstartRename: () => void; ondelete: () => void; onopen: () => void; + oncopyUrl: () => void; onmoveTo: () => void; ondragstart: () => void; ondropinto: () => void; @@ -41,6 +42,7 @@ onstartRename, ondelete, onopen, + oncopyUrl, onmoveTo, ondragstart, ondropinto, @@ -136,6 +138,13 @@ onopen(); }}>↗ + {/if} {#if editable}