feat(security): close the two gaps the T1-T8 pass found
Walking docs/09's threat model against the shipped code turned up two things that had gone unnoticed because nothing mechanical was watching either. **The permission list had no test.** "Exactly bookmarks + storage" is CLAUDE.md's first hard rule, the README's headline privacy claim, the store's privacy-tab answer and a line in the privacy policy -- and a single added string in wxt.config.ts would have shipped silently. tests/unit/manifest.test.ts now asserts the list exactly, plus the absence of host_permissions, content_scripts, a background worker and eight other reach-widening keys. Verified to fail by sneaking in 'tabs'. It reads the config as text, with comments stripped, so the assertion cannot be satisfied by something computed at build time -- and because the file's own header says "No host_permissions, no content_scripts", a naive substring check failed on the prose promising the very thing it checks. **"Copy URL" was never built.** docs/06 §3.3 lists it in the row menu and docs/09 T8 describes its mitigation, so the threat model documented a control for a feature that did not exist. Now implemented in browser/clipboard.ts: write-only, on an explicit click, never reads the clipboard, and needs no permission because a transient user activation grants clipboard-write. Also records the measured pass in docs/09 §2 and the reproducibility finding in §5: content-identical rebuilds (every zip entry matches by CRC32) but not byte-identical, because wxt zip records mtimes. The old wording implied more than is true. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
9 files changed
+182
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -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.
|
||||
@@ -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<boolean> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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<void> {
|
||||
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<void> {
|
||||
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)}
|
||||
|
||||
@@ -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();
|
||||
}}>↗</button
|
||||
>
|
||||
<button
|
||||
title={t('edit.copyUrl')}
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
oncopyUrl();
|
||||
}}>⧉</button
|
||||
>
|
||||
{/if}
|
||||
{#if editable}
|
||||
<button
|
||||
|
||||
@@ -110,6 +110,9 @@ const dict = {
|
||||
collapseAll: 'Collapse all',
|
||||
rename: 'Rename',
|
||||
open: 'Open',
|
||||
copyUrl: 'Copy link',
|
||||
copied: 'Link copied',
|
||||
copyFailed: 'Could not copy the link.',
|
||||
moveTo: 'Move to…',
|
||||
moveToBody: 'Move "{title}" into which folder?',
|
||||
noMoveTargets: 'No other folder is available.',
|
||||
|
||||
@@ -103,6 +103,9 @@ export default {
|
||||
collapseAll: 'すべて折りたたむ',
|
||||
rename: '名前を変更',
|
||||
open: '開く',
|
||||
copyUrl: 'リンクをコピー',
|
||||
copied: 'リンクをコピーしました',
|
||||
copyFailed: 'リンクをコピーできませんでした。',
|
||||
moveTo: '移動先…',
|
||||
moveToBody: '「{title}」をどのフォルダへ移動しますか?',
|
||||
noMoveTargets: '他に利用できるフォルダがありません。',
|
||||
|
||||
@@ -102,6 +102,9 @@ export default {
|
||||
collapseAll: 'Thu gọn tất cả',
|
||||
rename: 'Đổi tên',
|
||||
open: 'Mở',
|
||||
copyUrl: 'Sao chép liên kết',
|
||||
copied: 'Đã sao chép liên kết',
|
||||
copyFailed: 'Không sao chép được liên kết.',
|
||||
moveTo: 'Chuyển tới…',
|
||||
moveToBody: 'Chuyển "{title}" vào thư mục nào?',
|
||||
noMoveTargets: 'Không có thư mục nào khác.',
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
/**
|
||||
* The permission list is the product's most load-bearing public claim: it is in
|
||||
* the README, the privacy policy, the store listing's privacy tab, and
|
||||
* CLAUDE.md's first hard rule. Until this file existed, nothing enforced it —
|
||||
* a single added string in wxt.config.ts would have shipped silently.
|
||||
*
|
||||
* Read as text rather than imported, so the assertion cannot be satisfied by a
|
||||
* value computed at build time; what ships is what is written here.
|
||||
*/
|
||||
|
||||
const RAW = readFileSync(join(process.cwd(), 'wxt.config.ts'), 'utf8');
|
||||
/**
|
||||
* Comments stripped first. The file's own header says "No host_permissions, no
|
||||
* content_scripts", so a naive substring check fails on the prose that promises
|
||||
* the very thing it is checking.
|
||||
*/
|
||||
const CONFIG = RAW.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/[^\n]*/g, '');
|
||||
|
||||
/** Anything that widens the extension's reach beyond bookmarks + storage. */
|
||||
const FORBIDDEN_KEYS = [
|
||||
'host_permissions',
|
||||
'optional_permissions',
|
||||
'optional_host_permissions',
|
||||
'content_scripts',
|
||||
'web_accessible_resources',
|
||||
'externally_connectable',
|
||||
'content_security_policy',
|
||||
'declarative_net_request',
|
||||
'devtools_page',
|
||||
'chrome_url_overrides',
|
||||
];
|
||||
|
||||
describe('manifest', () => {
|
||||
it('requests exactly ["bookmarks", "storage"]', () => {
|
||||
const match = CONFIG.match(/permissions:\s*\[([^\]]*)\]/);
|
||||
expect(match?.[1], 'no permissions array found in wxt.config.ts').toBeDefined();
|
||||
|
||||
const requested = [...(match?.[1] ?? '').matchAll(/'([^']+)'|"([^"]+)"/g)].map(
|
||||
(entry) => entry[1] ?? entry[2],
|
||||
);
|
||||
// Adding one is a minor-version event that also requires updating docs
|
||||
// 08/09/13 and the store privacy tab (docs/09 §4). Update this list last.
|
||||
expect(requested).toEqual(['bookmarks', 'storage']);
|
||||
});
|
||||
|
||||
it.each(FORBIDDEN_KEYS)('declares no %s', (key) => {
|
||||
expect(CONFIG).not.toContain(key);
|
||||
});
|
||||
|
||||
it('declares no background service worker', () => {
|
||||
// docs/15 decision log, 2026-07-03: no background worker in v1. One would
|
||||
// also change the store review posture.
|
||||
expect(CONFIG).not.toMatch(/\bbackground\s*:/);
|
||||
});
|
||||
|
||||
it('keeps the manifest at v3 by not overriding WXT’s default', () => {
|
||||
// WXT emits manifest_version 3 for the chrome-mv3 target. An explicit
|
||||
// downgrade here would be the only way to lose it.
|
||||
expect(CONFIG).not.toMatch(/manifest_version\s*:\s*2/);
|
||||
});
|
||||
|
||||
it('still points default_locale at the three shipped dictionaries', () => {
|
||||
expect(CONFIG).toMatch(/default_locale:\s*'en'/);
|
||||
for (const locale of ['en', 'vi', 'ja']) {
|
||||
const path = join(process.cwd(), 'src/public/_locales', locale, 'messages.json');
|
||||
const messages: unknown = JSON.parse(readFileSync(path, 'utf8'));
|
||||
expect(messages, `${locale}/messages.json`).toHaveProperty('appName');
|
||||
expect(messages, `${locale}/messages.json`).toHaveProperty('appDesc');
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user