From 9e9107093ef9b97758465f44f8780ce936f4f341 Mon Sep 17 00:00:00 2001 From: poli0981 <127664709+poli0981@users.noreply.github.com> Date: Sun, 26 Jul 2026 14:44:08 +0700 Subject: [PATCH] fix: close the eight findings the Phase 5 review confirmed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .github/workflows/ci.yml | 6 +++ .github/workflows/release.yml | 11 +++++ README.md | 6 ++- docs/09_SECURITY_PRIVACY.md | 26 +++++++--- docs/12_CI_CD.md | 10 ++++ package.json | 1 + scripts/check-manifest.mjs | 74 ++++++++++++++++++++++++++++ src/lib/browser/open-url.ts | 16 ++++++ src/lib/components/EditTab.svelte | 16 +++++- src/lib/components/TabBar.svelte | 11 +++-- src/lib/components/TreeRow.svelte | 29 +++++++++-- src/lib/edit/edit-node.ts | 3 ++ src/lib/i18n/locales/en.ts | 1 + src/lib/i18n/locales/ja.ts | 1 + src/lib/i18n/locales/vi.ts | 1 + tests/unit/browser/clipboard.test.ts | 69 ++++++++++++++++++++++++++ tests/unit/edit/edit-node.test.ts | 6 +++ tests/unit/manifest.test.ts | 15 ++++++ tests/unit/styles/contrast.test.ts | 6 ++- 19 files changed, 285 insertions(+), 23 deletions(-) create mode 100644 scripts/check-manifest.mjs create mode 100644 tests/unit/browser/clipboard.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index acecfa9..444e834 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2a3ea4d..a4a2319 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,6 +37,10 @@ jobs: - run: npm run zip # wxt zip → .output/--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 diff --git a/README.md b/README.md index c214e41..73c44b3 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docs/09_SECURITY_PRIVACY.md b/docs/09_SECURITY_PRIVACY.md index e0b5b70..fe6cd37 100644 --- a/docs/09_SECURITY_PRIVACY.md +++ b/docs/09_SECURITY_PRIVACY.md @@ -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) diff --git a/docs/12_CI_CD.md b/docs/12_CI_CD.md index 7f4d2a0..313fe2c 100644 --- a/docs/12_CI_CD.md +++ b/docs/12_CI_CD.md @@ -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 diff --git a/package.json b/package.json index fac1b50..1a2862c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/check-manifest.mjs b/scripts/check-manifest.mjs new file mode 100644 index 0000000..b21142d --- /dev/null +++ b/scripts/check-manifest.mjs @@ -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.`, +); diff --git a/src/lib/browser/open-url.ts b/src/lib/browser/open-url.ts index 7ace7c8..cb5e2e8 100644 --- a/src/lib/browser/open-url.ts +++ b/src/lib/browser/open-url.ts @@ -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. * diff --git a/src/lib/components/EditTab.svelte b/src/lib/components/EditTab.svelte index 6ee51a4..88ce9c9 100644 --- a/src/lib/components/EditTab.svelte +++ b/src/lib/components/EditTab.svelte @@ -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 { + 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 { 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)} diff --git a/src/lib/components/TabBar.svelte b/src/lib/components/TabBar.svelte index d7d9782..8092697 100644 --- a/src/lib/components/TabBar.svelte +++ b/src/lib/components/TabBar.svelte @@ -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); diff --git a/src/lib/components/TreeRow.svelte b/src/lib/components/TreeRow.svelte index 0df1765..a9a971e 100644 --- a/src/lib/components/TreeRow.svelte +++ b/src/lib/components/TreeRow.svelte @@ -1,4 +1,5 @@