fix: close the eight findings the Phase 5 review confirmed

Five lenses filed 20; 8 survived verification.

**release.yml would have failed on the first tag.** The `announce` job called
the ops reusable with no `with:` block, but that reusable resolves
TAG="${INPUT_TAG:-$EVENT_TAG}" where EVENT_TAG is github.event.release.tag_name
-- empty, because this workflow is triggered by `on: push: tags`, not
`on: release`. The job would have exited 1 on "No release tag available" for
every release. Filed independently by three lenses and confirmed against the
reusable's actual source; docs/12 §2.3 had the same omission and is fixed too.
Ironically the comment right above it explains why the workflow deliberately is
not event-driven -- which is exactly what makes tag_override mandatory.

**Nothing checked the BUILT manifest.** The unit test reads wxt.config.ts,
which proves what we ask for, not what WXT emits. Those differ: a dev build of
this same config carries ["bookmarks","storage","tabs","scripting"] and
host_permissions ["http://localhost/*"]. Production is clean, but that is
WXT's behaviour, not ours. scripts/check-manifest.mjs now gates the artifact
and runs in both CI and release; verified by editing a built manifest. The
README sentence claiming a test asserted the built manifest was false and is
corrected -- the same overclaim I had already made once verbally.

**The contrast test I added last commit could not see its own bypass.**
TabBar's `.locked { opacity: 0.65 }` composites --fg-muted against the page and
drops the label to 2.83:1. The test reads token values, so alpha applied on top
is invisible to it. Opacity removed; the padlock and title already carried the
signal. TEXT_PAIRS also widened to check the status colours on --bg, not only
--bg-raised.

**docs/09 T3 was signed off with half its mitigation unbuilt.** The row has
always specified a ⚠ badge for dangerous schemes; only the blocking existed. A
`javascript:` bookmark titled "Your bank" rendered identically to a safe one
and its Open button silently did nothing. isBlockedUrl now drives a badge, and
a refused open raises a toast.

Also: the five row action buttons had glyphs as their accessible names (content
beats title in accname), so voice control could not address them; the manifest
test's literal-harvesting regex would have passed a spread or identifier;
resolveNewFolderParent returned a focused unmodifiable folder's id, which every
create rejects; and clipboard.ts was the only new module with no test.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Opus 5 committed 2026-07-26 14:57:15 +07:00
1 parent 6a8ede7373
commit 674ac341e5
19 files changed
+285 -23

No files matched your search

+6
View File
@@ -37,6 +37,12 @@ jobs:
- run: npm run coverage # vitest --coverage, thresholds per docs/11 §1
- run: npm run guard # the canonical grep gate, docs/08 §3
# The unit test proves what wxt.config.ts ASKS for. Only this proves what
# WXT actually emitted — a dev build of the same config carries
# tabs/scripting/host_permissions that never appear in the config file.
- run: npm run build
- run: npm run check:manifest
build:
name: Build + package
needs: quality
+11
View File
@@ -37,6 +37,10 @@ jobs:
- run: npm run zip # wxt zip → .output/<name>-<version>-chrome.zip
# Gate the artifact, not just the config it was built from. A tag is the
# last point at which an unintended permission can still be stopped.
- run: npm run check:manifest
- name: Verify tag matches manifest version
run: |
set -euo pipefail
@@ -77,4 +81,11 @@ jobs:
uses: poli0981/.github/.github/workflows/announce-release.yml@main
permissions:
contents: read
with:
# REQUIRED here, and only because of the comment above. The reusable
# resolves `TAG="${INPUT_TAG:-$EVENT_TAG}"` with EVENT_TAG =
# github.event.release.tag_name — which is empty under `on: push: tags`,
# so without this the job exits 1 on "No release tag available" and the
# announcement never fires for any release.
tag_override: ${{ github.ref_name }}
secrets: inherit
+4 -2
View File
@@ -35,8 +35,10 @@ This is the whole point of the project, so it is worth being precise.
There is no server. A grep gate (`npm run guard`) fails the build if anyone
adds `fetch`, `XMLHttpRequest`, `WebSocket`, `EventSource` or `sendBeacon`.
- **Exactly two permissions**: `bookmarks` and `storage`. No host permissions,
no content scripts, no background worker. A test asserts the built manifest
against that list.
no content scripts, no background worker. Two gates enforce it: a unit test
over `wxt.config.ts`, and `npm run check:manifest`, which CI runs against the
**built** `manifest.json` — because a build can add what the config never
asked for.
- **Zero runtime dependencies.** Nothing third-party ships in the extension.
- Settings use `chrome.storage.local`, never `storage.sync`, so even your
preferences stay off any vendor cloud.
+18 -8
View File
@@ -32,22 +32,32 @@
|---|---|
| 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`. |
| T3 | `malformed/js-url.html` at parse level, `tests/unit/browser/open-url.test.ts` at the point of use — `javascript:`, `data:`, `file:`, `chrome:`, `vbscript:` and case-shouted variants are refused before `tabs.create` — and the ⚠ badge this row has always specified, which `isBlockedUrl` now drives in `TreeRow`. A refused open also raises a toast; it used to do nothing at all, which read as a broken button rather than a deliberate refusal. |
| 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
Three gaps this pass closed, all 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.
- **The permission list had no gate at all.** Two now exist, and both are
needed. `tests/unit/manifest.test.ts` asserts `['bookmarks', 'storage']`
against `wxt.config.ts` — what we *ask* for. `scripts/check-manifest.mjs`
asserts the **built** artifact, which is not the same thing: a dev build of
this identical config emits
`"permissions": ["bookmarks","storage","tabs","scripting"]` and
`"host_permissions": ["http://localhost/*"]`, because WXT injects them.
Production is clean today, but that is WXT's behaviour, not our enforcement.
Both were verified to fail — one by adding `'tabs'` to the config, the other
by editing the built manifest.
- **"Copy URL" did not exist**, so T8 described the mitigation for a feature
that was never shipped.
- **T3's ⚠ badge did not exist either.** The blocking half was real and tested;
the "mark dangerous schemes in the UI" half was not, so a `javascript:`
bookmark titled "Your bank" rendered exactly like a safe one and its Open
button silently did nothing.
## 3. Secure coding rules (enforced)
+10
View File
@@ -63,6 +63,8 @@ jobs:
- run: npm run knip
- run: npm run coverage # vitest --coverage, thresholds per 11 §1
- run: npm run guard # canonical grep gate, 08_MV3 §3
- run: npm run build
- run: npm run check:manifest # the BUILT artifact, not just the config
build:
name: Build + package
@@ -194,9 +196,17 @@ jobs:
uses: poli0981/.github/.github/workflows/announce-release.yml@main
permissions:
contents: read
with:
tag_override: ${{ github.ref_name }}
secrets: inherit
```
`tag_override` is **required here**, and for the same reason the announcement
is a job rather than a caller. The reusable resolves
`TAG="${INPUT_TAG:-$EVENT_TAG}"` with `EVENT_TAG = github.event.release.tag_name`
— empty under `on: push: tags` — so omitting it makes the job exit 1 on
"No release tag available" and the announcement never fires for any release.
The announcement is a **job inside this workflow**, not a separate
`on: release: [published]` caller. A Release created by `gh release create`
under the default `GITHUB_TOKEN` does not emit an event that starts new
+1
View File
@@ -28,6 +28,7 @@
"lint:fix": "biome check --write .",
"knip": "knip",
"guard": "node scripts/guard.mjs",
"check:manifest": "node scripts/check-manifest.mjs",
"icons": "node scripts/gen-icons.mjs",
"test": "vitest run",
"test:watch": "vitest",
+74
View File
@@ -0,0 +1,74 @@
/**
* Assert the BUILT manifest — CLAUDE.md hard rule 1, docs/08 §2.
*
* The unit test in `tests/unit/manifest.test.ts` reads `wxt.config.ts`, which
* proves what we ASKED for. It cannot prove what WXT emitted. Those differ:
* a dev build of this exact config produces
* "permissions": ["bookmarks","storage","tabs","scripting"]
* "host_permissions": ["http://localhost/*"]
* because WXT injects them for its dev server. Production is clean today, but
* that is a property of WXT's dev/prod branch, not of anything this repo
* enforces — so the shipped artifact needs its own gate.
*
* Run after `npm run build` (or `npm run zip`). Zero dependencies, Node stdlib.
*/
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
const MANIFEST = join(process.cwd(), '.output', 'chrome-mv3', 'manifest.json');
/** Exactly this, in any order. Adding one is a minor-version event (docs/09 §4). */
const ALLOWED_PERMISSIONS = ['bookmarks', 'storage'];
/** Keys that would widen the extension's reach. None may be present. */
const FORBIDDEN_KEYS = [
'host_permissions',
'optional_permissions',
'optional_host_permissions',
'content_scripts',
'background',
'web_accessible_resources',
'externally_connectable',
'declarative_net_request',
'devtools_page',
'chrome_url_overrides',
];
let manifest;
try {
manifest = JSON.parse(readFileSync(MANIFEST, 'utf8'));
} catch (cause) {
console.error(`check-manifest: cannot read ${MANIFEST} — run \`npm run build\` first.`);
console.error(` ${cause.message}`);
process.exit(1);
}
const problems = [];
if (manifest.manifest_version !== 3) {
problems.push(`manifest_version is ${manifest.manifest_version}, expected 3`);
}
const permissions = [...(manifest.permissions ?? [])].sort();
if (permissions.join(',') !== [...ALLOWED_PERMISSIONS].sort().join(',')) {
problems.push(
`permissions are ${JSON.stringify(manifest.permissions)}, expected ${JSON.stringify(ALLOWED_PERMISSIONS)}`,
);
}
for (const key of FORBIDDEN_KEYS) {
if (key in manifest) problems.push(`declares "${key}": ${JSON.stringify(manifest[key])}`);
}
if (problems.length > 0) {
for (const problem of problems) {
console.error(`::error::check-manifest: ${problem}`);
console.error(` ${problem}`);
}
console.error('\nSee CLAUDE.md hard rule 1 and docs/09 §4 before changing this.');
process.exit(1);
}
console.warn(
`check-manifest: clean — MV3, permissions ${JSON.stringify(manifest.permissions)}, no reach-widening keys.`,
);
+16
View File
@@ -12,6 +12,22 @@ import { browser } from 'wxt/browser';
/** Schemes allowed to reach the browser. Everything else is display-only. */
const ALLOWED_SCHEMES = new Set(['http:', 'https:']);
/**
* Whether this URL would be refused — so the row can warn BEFORE the click.
*
* docs/09 T3 asks for both halves: block the navigation, and mark the bookmark
* so a `javascript:` entry titled "Your bank" does not look like an ordinary
* link that simply does nothing.
*/
export function isBlockedUrl(url: string | undefined): boolean {
if (url === undefined) return false;
try {
return !ALLOWED_SCHEMES.has(new URL(url).protocol);
} catch {
return true;
}
}
/**
* Open `url` in a new tab if its scheme is allowed.
*
+14 -2
View File
@@ -183,13 +183,25 @@
}
case 'activate': {
const node = findNode(roots, action.id);
if (node?.url !== undefined) void openBookmarkUrl(node.url);
if (node?.url !== undefined) void openUrl(node.url);
else if (node !== undefined) toggle(node.id);
break;
}
}
}
/**
* Open a bookmark, saying so when the scheme is refused.
*
* The boolean was previously discarded with `void`, so clicking ↗ on a
* `javascript:` bookmark did nothing at all and looked like a broken button
* rather than a deliberate refusal (docs/09 T3).
*/
async function openUrl(url: string): Promise<void> {
if (url === '') return;
if (!(await openBookmarkUrl(url))) pushToast(t('edit.unsafeUrl'), 'danger');
}
/** 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;
@@ -343,7 +355,7 @@
onrename={(title) => void commitRename(row.node.id, title)}
oncancelRename={() => (renamingId = undefined)}
ondelete={() => (pendingDelete = row.node)}
onopen={() => void openBookmarkUrl(row.node.url ?? '')}
onopen={() => void openUrl(row.node.url ?? '')}
oncopyUrl={() => void copyUrl(row.node.url ?? '')}
onmoveTo={() => (movingNode = row.node)}
ondragstart={() => (draggingId = row.node.id)}
+6 -5
View File
@@ -69,11 +69,12 @@
cursor: not-allowed;
}
/* Reachable, but visibly not yet usable — clicking shows the gate. */
.locked {
opacity: 0.65;
}
/* Reachable, but visibly not yet usable — clicking shows the gate.
Deliberately NOT `opacity`, which composites the label against the page and
dropped --fg-muted from 5.98:1 to 2.83:1. The contrast test reads token
values out of tokens.css, so it cannot see an alpha applied on top: this
kind of dimming has to be avoided by hand. The padlock and the `title`
already carry the signal. */
.locked::after {
content: ' 🔒';
font-size: var(--fs-0);
+24 -5
View File
@@ -1,4 +1,5 @@
<script lang="ts">
import { isBlockedUrl } from '../browser/open-url';
import type { EditNode } from '../edit/patch-tree';
import { t } from '../i18n/index.svelte';
@@ -53,6 +54,7 @@
const isFolder = $derived(node.url === undefined);
const domain = $derived(hostOf(node.url));
const blocked = $derived(!isFolder && isBlockedUrl(node.url));
function hostOf(url: string | undefined): string {
if (url === undefined) return '';
@@ -119,47 +121,57 @@
{:else}
<span class="title">{node.title}</span>
{#if domain !== ''}<span class="domain">{domain}</span>{/if}
{#if blocked}
<!-- docs/09 T3: a javascript:/data: bookmark must not look like an
ordinary link that merely does nothing when clicked. -->
<span class="unsafe" title={t('edit.unsafeUrl')} aria-label={t('edit.unsafeUrl')}>⚠</span>
{/if}
<span class="actions">
{#if editable}
<button
title={t('edit.rename')}
aria-label={t('edit.rename')}
onclick={(e) => {
e.stopPropagation();
onstartRename();
}}>✎</button
}}><span aria-hidden="true">✎</span></button
>
{/if}
{#if !isFolder}
<button
title={t('edit.open')}
aria-label={t('edit.open')}
onclick={(e) => {
e.stopPropagation();
onopen();
}}>↗</button
}}><span aria-hidden="true">↗</span></button
>
<button
title={t('edit.copyUrl')}
aria-label={t('edit.copyUrl')}
onclick={(e) => {
e.stopPropagation();
oncopyUrl();
}}>⧉</button
}}><span aria-hidden="true">⧉</span></button
>
{/if}
{#if editable}
<button
title={t('edit.moveTo')}
aria-label={t('edit.moveTo')}
onclick={(e) => {
e.stopPropagation();
onmoveTo();
}}>⇄</button
}}><span aria-hidden="true">⇄</span></button
>
<button
title={t('edit.delete')}
aria-label={t('edit.delete')}
onclick={(e) => {
e.stopPropagation();
ondelete();
}}>🗑</button
}}><span aria-hidden="true">🗑</span></button
>
{/if}
</span>
@@ -221,6 +233,13 @@
white-space: nowrap;
}
.unsafe {
flex-shrink: 0;
font-size: var(--fs-0);
color: var(--warn);
cursor: help;
}
.rename {
font: inherit;
flex: 1;
+3
View File
@@ -63,6 +63,9 @@ export function resolveNewFolderParent(
): string | undefined {
const writableRoot = roots.find((root) => root.unmodifiable === undefined)?.id;
if (focused === undefined) return writableRoot;
// A policy-managed folder rejects every create, so falling back is the only
// way "New folder" does anything at all while one is selected.
if (focused.unmodifiable !== undefined) return writableRoot;
if (focused.url === undefined) return focused.id;
return focused.parentId ?? writableRoot;
}
+1
View File
@@ -111,6 +111,7 @@ const dict = {
rename: 'Rename',
open: 'Open',
copyUrl: 'Copy link',
unsafeUrl: 'This address uses a scheme BookmarkMagic will not open.',
copied: 'Link copied',
copyFailed: 'Could not copy the link.',
moveTo: 'Move to…',
+1
View File
@@ -104,6 +104,7 @@ export default {
rename: '名前を変更',
open: '開く',
copyUrl: 'リンクをコピー',
unsafeUrl: 'このアドレスは BookmarkMagic が開かない形式です。',
copied: 'リンクをコピーしました',
copyFailed: 'リンクをコピーできませんでした。',
moveTo: '移動先…',
+1
View File
@@ -103,6 +103,7 @@ export default {
rename: 'Đổi tên',
open: 'Mở',
copyUrl: 'Sao chép liên kết',
unsafeUrl: 'Địa chỉ này dùng lược đồ mà BookmarkMagic sẽ không mở.',
copied: 'Đã sao chép liên kết',
copyFailed: 'Không sao chép được liên kết.',
moveTo: 'Chuyển tới…',
+69
View File
@@ -0,0 +1,69 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { copyToClipboard } from '@/lib/browser/clipboard';
/**
* The docs/09 T8 surface. jsdom provides no `navigator.clipboard`, so every
* case here installs one — which also exercises the "no clipboard at all" path
* that a non-secure context would take.
*/
function stubClipboard(impl: ((text: string) => Promise<void>) | undefined): string[] {
const written: string[] = [];
if (impl === undefined) {
Object.defineProperty(globalThis.navigator, 'clipboard', {
value: undefined,
configurable: true,
});
return written;
}
Object.defineProperty(globalThis.navigator, 'clipboard', {
value: {
writeText: async (text: string) => {
written.push(text);
await impl(text);
},
},
configurable: true,
});
return written;
}
afterEach(() => {
Reflect.deleteProperty(globalThis.navigator, 'clipboard');
vi.restoreAllMocks();
});
describe('copyToClipboard', () => {
it('writes the text and reports success', async () => {
const written = stubClipboard(async () => {});
expect(await copyToClipboard('https://example.com/')).toBe(true);
expect(written).toEqual(['https://example.com/']);
});
it('reports failure instead of throwing when the write rejects', async () => {
// The real one this guards: Chrome rejects with NotAllowedError
// ("Document is not focused") if the manager page lost focus between the
// click and the promise. The user gets a toast, not an unhandled rejection.
stubClipboard(async () => {
throw new DOMException('Document is not focused', 'NotAllowedError');
});
await expect(copyToClipboard('https://example.com/')).resolves.toBe(false);
});
it('reports failure when there is no clipboard API at all', async () => {
stubClipboard(undefined);
await expect(copyToClipboard('https://example.com/')).resolves.toBe(false);
});
it('never reads the clipboard', async () => {
// docs/09 T8 is explicit: write only. A readText call here would be a
// privacy regression that no other test would notice.
const readText = vi.fn();
Object.defineProperty(globalThis.navigator, 'clipboard', {
value: { writeText: async () => {}, readText },
configurable: true,
});
await copyToClipboard('https://example.com/');
expect(readText).not.toHaveBeenCalled();
});
});
+6
View File
@@ -109,6 +109,12 @@ describe('resolveNewFolderParent', () => {
it('treats a focused root as the target folder itself', () => {
expect(resolveNewFolderParent(ROOTS, BAR)).toBe('1');
});
it('falls back rather than targeting a focused UNMODIFIABLE folder', () => {
// A managed folder rejects every create, so returning its id made "New
// folder" silently do nothing whenever one happened to be selected.
expect(resolveNewFolderParent(ROOTS, MANAGED)).toBe('1');
});
});
describe('countDescendants', () => {
+15
View File
@@ -35,6 +35,21 @@ const FORBIDDEN_KEYS = [
];
describe('manifest', () => {
it('declares the permissions array exactly once', () => {
// Two arrays (e.g. a browser-specific override) would mean this file only
// ever checks the first, which might not be the one that ships.
expect(CONFIG.match(/(?<![a-z_])permissions:/gi)?.length ?? 0).toBe(1);
});
it('builds the permissions array from string literals only', () => {
// Without this, a spread, an identifier or a `.concat()` tail would be
// dropped by the literal-harvesting regex below and the assertion would
// still pass while extra permissions shipped.
const match = CONFIG.match(/permissions:\s*\[([^\]]*)\]/);
const residue = (match?.[1] ?? '').replace(/'[^']*'|"[^"]*"|[\s,]/g, '');
expect(residue, 'permissions array contains non-literal entries').toBe('');
});
it('requests exactly ["bookmarks", "storage"]', () => {
const match = CONFIG.match(/permissions:\s*\[([^\]]*)\]/);
expect(match?.[1], 'no permissions array found in wxt.config.ts').toBeDefined();
+5 -1
View File
@@ -55,10 +55,14 @@ const TEXT_PAIRS: [fg: string, bg: string][] = [
['--accent', '--bg'],
['--accent', '--bg-raised'],
// Rendered as text: DuplicatePanel counts, TreePreviewNode badges,
// WarningList's summary.
// WarningList's summary, TreeRow's ⚠ unsafe-scheme marker. Checked against
// BOTH surfaces — a row sits on --bg until it is hovered or focused.
['--danger', '--bg-raised'],
['--danger', '--bg'],
['--success', '--bg-raised'],
['--success', '--bg'],
['--warn', '--bg-raised'],
['--warn', '--bg'],
// Ink on a filled control: Button .primary/.danger, ConfirmDialog .danger,
// ThemeToggle .selected.
['--accent-fg', '--accent'],