diff --git a/scripts/adjudicate/adjudicate.mjs b/scripts/adjudicate/adjudicate.mjs index 0484e2e..e5d3a49 100644 --- a/scripts/adjudicate/adjudicate.mjs +++ b/scripts/adjudicate/adjudicate.mjs @@ -95,6 +95,7 @@ function parsePatch(text) { aPath: m ? m[1] : null, bPath: m ? m[2] : null, added: [], isNew: false, isDeleted: false, isRename: false, modeExec: false, isSymlink: false, isSubmodule: false, + isBinary: false, }; files.push(cur); newLine = 0; @@ -105,6 +106,13 @@ function parsePatch(text) { if (line.startsWith("deleted file mode ")) { cur.isDeleted = true; flagMode(cur, line); continue; } if (line.startsWith("old mode ") || line.startsWith("new mode ")) { flagMode(cur, line); continue; } if (line.startsWith("rename from ") || line.startsWith("rename to ")) { cur.isRename = true; continue; } + // A file arriving as a binary patch contributes NO added lines, so every + // scan that reads `added` silently sees an empty file rather than skipping + // a known-unreadable one. Recorded so the caller can tell the difference. + if (line.startsWith("GIT binary patch") || /^Binary files .* differ$/.test(line)) { + cur.isBinary = true; + continue; + } if (line.startsWith("--- ")) { if (line === "--- /dev/null") cur.isNew = true; continue; } if (line.startsWith("+++ ")) { if (line === "+++ /dev/null") cur.isDeleted = true; @@ -204,6 +212,28 @@ function main() { gate("1 scope: no symlinks added", symlinks.length === 0, symlinks.join(", ")); gate("1 scope: no submodules added", submodules.length === 0, submodules.join(", ")); + // Source that arrives as a binary patch is source nothing downstream can + // read. Every scan works from the patch's added lines, so a file with none + // is indistinguishable from an empty file — the capability scan reports + // `(none)` and reads as a clean result rather than as an unread one. + // + // The route is an in-addon `.gitattributes` saying `*.js -diff`, which is now + // a sensitive path above; this gate is the second layer, because the attribute + // can also be set elsewhere and because a gate should not depend on having + // enumerated every way of reaching it. + const SCANNABLE_EXT = /\.(ts|tsx|js|jsx|mjs|cjs|html|css|json|md|txt|ya?ml)$/i; + const binarySource = files + .filter((f) => f.isBinary && SCANNABLE_EXT.test(pathOf(f) || "")) + .map(pathOf); + gate( + "1 scope: no text file delivered as a binary patch", + binarySource.length === 0, + binarySource.length + ? `${binarySource.join(", ")} — these carry no readable diff, so every scan below sees them ` + + `as empty rather than as unread` + : "", + ); + // ── Stage 2: applies cleanly to base ────────────────────────────────────── let applies = false; try { @@ -384,21 +414,69 @@ function main() { } // ── Stage 5: capability scan → JUDGMENT QUEUE (never a gate) ────────────── + // Prose is not code. A README sentence containing the word "WebSocket" is + // not an egress site, and a link in it is not a host the add-on contacts. + // Reading the two as one list is how video-chat (#21) enumerated as + // reaching `localhost` and `github.com` — both from its README — while its + // actual relay and STUN server appeared nowhere in the list at all. + const isDoc = (p) => /\.(md|markdown|txt)$/i.test(p) || /(^|\/)(LICENSE|NOTICE)$/.test(p); + + // A lockfile's `resolved` URLs are build-time fetches, and stage 4c already + // gates every one of them as registry-hosted and pinned. Repeating them here + // buries the handful of run-time hosts this list exists to surface: the + // Studio's own two became nine once npm's were mixed in. + const isLockfile = (p) => /(^|\/)package-lock\.json$/.test(p); + // `xmlns="http://www.w3.org/2000/svg"` names an XML namespace. Nothing is + // fetched from it, and an icon file is not an egress site. + // + // Only the ATTRIBUTE is removed, not the line. Dropping the whole line let a + // real host hide behind the token: `fetch("https://evil.tld/x") /* xmlns= */` + // disappeared from the list entirely, and stage 5 does not strip comments. + const withoutNamespaceDecls = (t) => t.replace(/\bxmlns(:\w+)?\s*=\s*(["'])[^"']*\2/g, " "); + const hosts = new Set(); + const docHosts = new Set(); for (const cat of SCAN_CATEGORIES) { const items = []; for (const f of files) { const p = pathOf(f); for (const { line, text } of f.added) { - if (cat.patterns.some((re) => re.test(text))) items.push({ file: p, line, text: text.trim().slice(0, 160) }); + if (cat.patterns.some((re) => re.test(text))) { + // DOCUMENTATION IS SCANNED, AND LABELLED. An earlier version of this + // skipped doc files for every category, which opened a blind spot + // rather than closing a false positive: Node's CJS `require('./NOTICE')` + // and `node tools/build.txt` both execute those files as JavaScript, so + // a payload kept in one would have been invisible to every category. + // Verified: a `.txt` containing `child_process`, `exec(` and an + // exfiltration host returned "no items flagged". + // + // The prose problem this was reaching for is real, but it is a problem + // about HOSTS, and that is handled below by reporting documentation + // hosts separately. Here the fix is to say where the match came from, + // so a reviewer can discount a README sentence without the scan having + // to guess for them. + items.push({ + file: isDoc(p) ? `${p} (documentation — not necessarily code)` : p, + line, + text: text.trim().slice(0, 160), + }); + } } } if (items.length) queue.push({ category: cat.label, key: cat.key, items }); } - for (const f of files) - for (const { text } of f.added) - for (const m of text.matchAll(URL_RE)) hosts.add(m[1]); - if (hosts.size) notes.push(`Network hosts referenced (no allowlist exists yet — judge each): ${[...hosts].join(", ")}`); + for (const f of files) { + const p = pathOf(f); + if (isLockfile(p)) continue; + const into = isDoc(p) ? docHosts : hosts; + for (const { text } of f.added) { + for (const m of withoutNamespaceDecls(text).matchAll(URL_RE)) into.add(m[1] ?? m[2]); + } + } + for (const h of hosts) docHosts.delete(h); + if (hosts.size) notes.push(`Network hosts referenced in code (no allowlist exists yet — judge each): ${[...hosts].join(", ")}`); + else notes.push("No network host appears in the submitted code — judge that against what the add-on says it does."); + if (docHosts.size) notes.push(`Hosts named only in documentation, never in code: ${[...docHosts].join(", ")}`); // ── optional: vocabulary drift check against the app source ─────────────── if (args.appSrc) checkVocabDrift(args.appSrc); diff --git a/scripts/adjudicate/policy.mjs b/scripts/adjudicate/policy.mjs index e8c663f..fdb7129 100644 --- a/scripts/adjudicate/policy.mjs +++ b/scripts/adjudicate/policy.mjs @@ -81,6 +81,23 @@ export const SENSITIVE_PATH_PATTERNS = [ { re: /(^|\/)pnpm-workspace\.yaml$/, why: "pnpm workspace config" }, { re: /(^|\/)\.pnpmfile\.cjs$/, why: "pnpm hook file — executes during install" }, { re: /(^|\/)bunfig\.toml$/, why: "bun config — can re-point the registry for the build" }, + + // Git configuration that changes what a DIFF shows, which is a different + // kind of danger from the ones above: it does not alter what the build does, + // it alters what a reviewer sees. + // + // `.gitattributes` inside the addon's own directory, containing `*.js -diff`, + // makes `git format-patch` emit `GIT binary patch` for every JavaScript file + // in the submission. The parsed patch then has no added lines, so the stage 5 + // capability scan has nothing to read and the judgment queue comes back + // `(none)`. Verified 2026-11-27: a file containing `child_process`, `exec(`, + // `eval(` and a `wss://` exfiltration host produced `VERDICT: PASS — no items + // flagged`. The gates that read the tree rather than the patch are + // unaffected, so this hides the report rather than passing a gate — but the + // report is the reviewer's agenda, and a scan that silently reads nothing is + // worse than no scan. + { re: /(^|\/)\.gitattributes$/, why: "git attributes — can suppress the diff a reviewer reads" }, + { re: /(^|\/)\.mailmap$/, why: "git mailmap — can rewrite the authorship a reviewer sees" }, ]; // The complete set of `scripts` keys an addon's package.json may declare. @@ -202,7 +219,13 @@ export const SCAN_CATEGORIES = [ patterns: [ /\bchild_process\b/, /\bspawn(Sync)?\s*\(/, - /\bexec(File)?(Sync)?\s*\(/, + // `.exec(` on its own is RegExp.prototype.exec, which any scanner, + // validator or syntax highlighter uses — so a dotted bare `exec` is + // excluded and only the unqualified call is kept. The named variants + // have no RegExp counterpart and stay matchable either way; a + // `cp.execSync()` is still reached through child_process above. + /(?