Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
Security findings no longer show their file, line or reason in PR bodies (GST-3076) (#4486)
Garry Tan01097037979b
diff --git a/bin/gstack-ship-receipt b/bin/gstack-ship-receiptindex 985b2ecf9..c7f9f0adb 100755--- a/bin/gstack-ship-receipt+++ b/bin/gstack-ship-receipt@@ -61,8 +61,9 @@ import { RISK_CLASSES, type RiskClass } from '../lib/review-risk';import { checkReceiptProse, proseLine } from '../lib/ship-receipt-prose';import { resolveStateRoot } from '../lib/state-root';import { readPause, receiptBaseRed } from '../lib/base-red';-import { readRuledNotes, ruledNoteText } from '../lib/ruled-notes';-import { appliedGateDispositions, gateDispositionText } from '../lib/gate-dispositions';+import { publicRuledNote, readRuledNotes, ruledNoteText } from '../lib/ruled-notes';+import { appliedGateDispositions, gateDispositionText, publicGateDisposition } from '../lib/gate-dispositions';+import { securityFingerprints } from '../lib/security-findings';import { laneExceptionBodyLines } from '../lib/test-lane-exception';import { grantedStop, grantMarker, historyLine, placeRunEntry, prReviewHistory, reviewRoute, runStub, stopFrom, stopMarker } from '../lib/pr-review-history';import { grantFor, readReviewRoundGrants, type ReviewRoundGrant } from '../lib/review-round-grant';@@ -308,6 +309,8 @@ function cmdWrite(rest: string[], json: boolean): number {const line = reviewLoopExceptionLine(loopException.exception);if (bodyFile && !bodyText.split(/\r?\n/).some(l => l.trim() === line)) return refuse(`${bodyFile} does not carry the exception line verbatim: ${JSON.stringify(line)}`);}+ const leaked = securityFingerprints(bodyText);+ if (leaked.length) { process.stderr.write(resultLine('gstack-ship-receipt write', 'RECEIPT_INVALID', `${bodyFile} names security finding ${leaked.join(', ')}: a PR body is public, so a security finding appears only as the redacted line gstack-approvals rulings, dispositions or gstack-review-scope render prints, and its location and reason stay in the private record (docs/troubleshooting.md#security-finding-in-body); nothing written`) + '\n'); return EXIT.fail; }const ruledNotes = readRuledNotes(repoRoot);const unlisted = bodyFile ? ruledNotes.map(n => `Ruled note: ${ruledNoteText(n)}`).find(l => !bodyText.split(/\r?\n/).some(b => b.trim() === l)) : undefined;if (unlisted) { process.stderr.write(resultLine('gstack-ship-receipt write', 'RECEIPT_INVALID', `${bodyFile} does not list ruled note ${JSON.stringify(unlisted)} (gstack-approvals rulings prints each line the body carries); nothing written`) + '\n'); return EXIT.fail; }@@ -381,7 +384,7 @@ function cmdWrite(rest: string[], json: boolean): number {policy: flag(rest, '--policy') ?? tree?.policy, queue_mode: flag(rest, '--queue-mode'), preregistration: flag(rest, '--preregistration'), history: flag(rest, '--history'),...pregate, issues: issuesFile ? receiptIssuesFrom(issuesFile) : undefined, approval: approval.kind === 'ok' ? approval.approval : undefined,review_loop: reviewLoop, ...(docs?.ok ? { docs: docs.docs } : {}), ...product,- gstack_version: installedGstackVersion(), review_depth: reviewDepth, review_loop_exception: loopException?.ok ? loopException.exception : undefined, review_round_grants: roundGrantsFor(repoRoot, flag(rest, '--pr')), ruled_notes: ruledNotes.length ? ruledNotes : undefined, gate_dispositions: gateDispositions, mechanical: mechanical.length ? mechanical : undefined, review_targeted: targeted?.ok ? targeted.targeted : undefined,+ gstack_version: installedGstackVersion(), review_depth: reviewDepth, review_loop_exception: loopException?.ok ? loopException.exception : undefined, review_round_grants: roundGrantsFor(repoRoot, flag(rest, '--pr')), ruled_notes: ruledNotes.length ? ruledNotes.map(publicRuledNote) : undefined, gate_dispositions: gateDispositions.map(publicGateDisposition), mechanical: mechanical.length ? mechanical : undefined, review_targeted: targeted?.ok ? targeted.targeted : undefined,design: review.frontend ? { mode: 'static', reason: 'no preview declared' } : undefined,base_red: pause ? receiptBaseRed(pause) : undefined,review_exclude: receiptExclude(review.exclude),diff --git a/changelog.d/security-findings-stay-out-of-pr-bodies.md b/changelog.d/security-findings-stay-out-of-pr-bodies.mdnew file mode 100644index 000000000..51b0b23a5--- /dev/null+++ b/changelog.d/security-findings-stay-out-of-pr-bodies.md@@ -0,0 +1,4 @@+---+important: security+---+- **A security finding's location and reason no longer go into a PR body.** When an owner ruled a security review finding a note, or a review deferred one in code the PR did not change, the PR body, its receipt block and the `Ruled note:`, `Gate disposition:` and deferred-findings lines named the file, line and reason, which on a public repository points at a live exposure. Findings whose category is `security`, `auth`, `secret` or `red-team` now print an opaque id and "security finding, details recorded privately"; the details stay in the private approval record (`gstack-approvals list`) and the local review files. `gstack-ship-receipt write` and `gstack-post` also refuse text that names a raw `path:line:security` fingerprint. Other findings print exactly as before.diff --git a/docs/ship-policy.md b/docs/ship-policy.mdindex aba79c318..e409604bf 100644--- a/docs/ship-policy.md+++ b/docs/ship-policy.md@@ -1733,6 +1733,27 @@ Pre-Landing Review and the PR body, `gstack-ship-receipt write` records them as`ruled_notes` (each with its `head`) and refuses a `--body` that does not carry eachline word for word, and the READY block prints each as `RULED_NOTE:`.+<a id="security-findings-stay-private"></a>+**Security findings stay private (GST-3076).** A PR body keeps every earlier+version in its edit history, and a ruled, dispositioned, deferred or noted+security finding is often a live exposure outside the PR's change. So every line+gstack renders for a finding whose category is `security`, `auth`, `secret` or+`red-team` (by its category, its reviewer or its `path:line:category`+fingerprint) names no location and no reason: a ruling prints+`Ruled note: redacted at <head12> ruled by <who> at <time>: security finding,+details recorded privately (approval <id>)`, a gate disposition drops its owner+words the same way, and `gstack-review-scope render` lists a deferred finding or+review note as `` `sf-<id>` security finding, details recorded privately ``. The+receipt's `ruled_notes` and `gate_dispositions` hold the same redacted form. The+fingerprint and reason stay in the private approval record (`gstack-approvals+list`, mirrored to Drive on Capy) and in the local deferred and classified+files. This holds on every repository, whatever its visibility: these lines are+compared word for word at receipt write and at land, so they cannot depend on a+visibility lookup that can fail or change, and a private repository can go+public with its PR history. As a backstop, `gstack-ship-receipt write` refuses a+`--body` and `gstack-post` refuses any text that names a raw security+fingerprint such as `src/x.ts:12:security`. Other findings print as before.+<a id="gate-dispositions"></a>**Gate dispositions (GST-2491).** A ruling never closes a gate finding (a loosenedgate the review logged with a `gate` tag and the hunk identity `gate_id`). In andiff --git a/docs/troubleshooting.md b/docs/troubleshooting.mdindex d2d07fece..e67dc8bf8 100644--- a/docs/troubleshooting.md+++ b/docs/troubleshooting.md@@ -3960,10 +3960,19 @@ finish's `MECHANICAL:` lines as `Mechanical retake: …`, and accept's([ruled notes](ship-policy.md#ruled-notes),[gate dispositions](ship-policy.md#gate-dispositions),[test-lane exceptions](ship-policy.md#test-lane-exceptions)).+<a id="security-finding-in-body"></a>+It also refuses a body that names a raw security finding fingerprint, such as+`src/x.ts:12:security` (category `security`, `auth`, `secret` or `red-team`),+and `gstack-post` refuses to send such text, exit 1: a PR body and every GitHub+post are public, so a security finding appears only in the redacted form gstack+renders ([security findings stay private](ship-policy.md#security-findings-stay-private)).**Fix.** Regenerate it with `gstack-ship-receipt write`; never hand-edit theblock. For a missing body line, add the line the refusal quotes to the body and-write again. For the `--head` refusal, check out that commit and write there. For a+write again. For a security fingerprint, replace the text that names it with the+line `gstack-approvals rulings`, `gstack-approvals dispositions` or+`gstack-review-scope render` prints, keep the details in your private report,+and write again. For the `--head` refusal, check out that commit and write there. For atargeted refusal, run the targeted reader on HEAD, `gstack-review-dispatch verify--targeted-out .gstack/tmp/targeted.json`, and write again with`--review-targeted @.gstack/tmp/targeted.json`.diff --git a/lib/approval-record.ts b/lib/approval-record.tsindex a1f8f2be2..68b271dee 100644--- a/lib/approval-record.ts+++ b/lib/approval-record.ts@@ -37,6 +37,7 @@ import { firstTitle } from './markdown-sections';import { scan, type Finding } from './redact-engine';import type { ResultCodeName } from './result-codes';import { resolveStateRoot } from './state-root';+import { isSecurityFinding, REDACTED_FINDING, REDACTED_REASON, REDACTED_WORDS } from './security-findings';export const OUTCOMES = ['approved', 'rejected', 'pending', 'standing'] as const;export type Outcome = typeof OUTCOMES[number];@@ -325,6 +326,14 @@ export function pathLabels(text: string): string {});}+/** A ruled_note or gate_disposition row for a security-class finding, as the full table may show it: no fingerprint, reason or owner words (GST-3076). */+function publicRow(r: ApprovalRow): ApprovalRow {+ const fp = /^(?:ruled_note|gate_disposition) (\S+) /.exec(r.scope)?.[1];+ if (!fp || !isSecurityFinding(fp)) return r;+ const ask = r.ask.indexOf(': ') < 0 ? r.ask : r.ask.slice(0, r.ask.indexOf(': '));+ return { ...r, ask: `${ask.replace(fp, REDACTED_FINDING)}: ${REDACTED_REASON}`, scope: r.scope.replace(fp, REDACTED_FINDING), words: REDACTED_WORDS };+}+export function renderRecord(read: ReadResult, loc: StoreLocation, o: { heading?: boolean; mode?: 'full' | 'redacted' } = {}): string {const head = o.heading === false ? [] : ['## Approvals', ''];if (o.mode === 'redacted' && read.rows.length) {@@ -335,7 +344,8 @@ export function renderRecord(read: ReadResult, loc: StoreLocation, o: { heading?if (read.state === 'unavailable') return [...head, `Record unavailable on this machine: no approval record for branch ${cell(loc.branch)} here, and the state root is ephemeral with no Drive mirror, so this is not proof that nothing was approved.`, ''].join('\n');if (!read.rows.length) return [...head, `No approvals recorded for branch ${cell(loc.branch)}.`, ''].join('\n');const lines = [APPROVALS_TABLE_HEADER, '|---|---|---|---|---|---|'];- for (const r of read.rows) {+ for (const row of read.rows) {+ const r = publicRow(row);const outcome = r.outcome === 'standing' ? 'standing approval' : r.outcome;lines.push(`| ${r.date} | ${cell(pathLabels(r.ask))} | “${cell(r.words, 280)}” (${cell(r.by)}) | ${outcome} | ${cell(pathLabels(r.scope))} | ${cell(pathLabels(r.pending))} |`);}diff --git a/lib/gate-dispositions.ts b/lib/gate-dispositions.tsindex df871ec5f..708ef64df 100644--- a/lib/gate-dispositions.ts+++ b/lib/gate-dispositions.ts@@ -20,6 +20,7 @@ import { appendRows, locate, readRecord, type ApprovalRow, type Env, type Recordimport type { ShipReceipt } from './headless-artifacts';import type { ResultCodeName } from './result-codes';import { GSTACK_ACTOR } from './ruled-notes';+import { isSecurityFinding, REDACTED_FINDING, REDACTED_REASON, REDACTED_WORDS } from './security-findings';import { BIN_DIR, runScriptSync } from './script-invocation';export interface GateDisposition { finding: string; gate_id: string; head: string; by: string; reason: string; words: string; at: string; approval: string }@@ -185,8 +186,11 @@ export function gateAcceptance(o: { cwd: string; branch: string; pin: string; boreturn problems.length ? { lines, applied, failure: { code: 'QUEUE_GATE_DISPOSITION', message: problems.join('; '), fix } } : { lines, applied };}-/** The one-line form finish prints after `GATE_DISPOSITION: ` and the PR body carries after `Gate disposition: `. */-export const gateDispositionText = (d: GateDisposition) => `${d.finding} [gate ${d.gate_id}] at ${d.head.slice(0, 12)} by ${d.by} at ${d.at}: ${d.reason} — "${d.words}" (approval ${d.approval})`;+/** The disposition as public text may carry it: a security-class finding's fingerprint, reason and owner words stay in the approval record (GST-3076). */+export const publicGateDisposition = (d: GateDisposition): GateDisposition => isSecurityFinding(d.finding) ? { ...d, finding: REDACTED_FINDING, reason: REDACTED_REASON, words: REDACTED_WORDS } : d;++/** The one-line form finish prints after `GATE_DISPOSITION: ` and the PR body carries after `Gate disposition: `, from publicGateDisposition. */+export const gateDispositionText = (disposition: GateDisposition) => { const d = publicGateDisposition(disposition); return `${d.finding} [gate ${d.gate_id}] at ${d.head.slice(0, 12)} by ${d.by} at ${d.at}: ${d.reason} — "${d.words}" (approval ${d.approval})`; };/*** The dispositions that close a review row's gate findings: the same fingerprint and gate_id on a gate finding the logger leftdiff --git a/lib/gstack-post.ts b/lib/gstack-post.tsindex fd56b04da..ca88db844 100644--- a/lib/gstack-post.ts+++ b/lib/gstack-post.ts@@ -21,7 +21,7 @@* plain-title policy (lib/plain-title.ts); a refused title posts nothing.* The scan runs on the merged bytes, which are the bytes sent.*- * Exit codes: 0 posted; 1 HIGH finding (or oversize input) refused;+ * Exit codes: 0 posted; 1 HIGH finding, a raw security finding fingerprint (GST-3076) or oversize input refused;* 2 MEDIUM findings need confirmation, printed as `RULE:` lines plus a* `TOKEN:` that binds the bytes, destination, operation and findings;* 3 `gh`/`glab` failed; 4 the title breaks the plain-title policy, printed as@@ -41,6 +41,7 @@ import type { ShipReceipt } from "./headless-artifacts";import { canonicalRemote } from "./remote-identity";import { parseChangelog } from "./changelog-check";import { versionWidth } from "./version-source";+import { securityFingerprints } from "./security-findings";export const OPS = ["pr-comment", "issue-comment", "reply", "pr-title", "pr-body", "pr-create", "issue-create", "fold"] as const;export type Op = (typeof OPS)[number];@@ -83,7 +84,7 @@ export const USAGE = `usage: gstack-post <op> [<target>] [options]pr-title and pr-create check the title against ${PLAIN_TITLE_POLICY_PATH}(gstack-plain-title) first; a repository without that file is not checked.- Exit: 0 posted · 1 HIGH finding refused · 2 MEDIUM findings need+ Exit: 0 posted · 1 HIGH finding or security fingerprint refused · 2 MEDIUM findings needconfirmation (RULE:/TOKEN: lines on stdout) · 3 gh/glab failed ·4 the title is not plain words (PLAIN_TITLE: lines; rewrite the title file)or the body breaks the shape (PLAIN_BODY: lines; rewrite the body file), or@@ -763,6 +764,11 @@ export function runPost(argv: string[], env: PostEnv, configBin = "gstack-configconst parts: Array<[Part, string]> = [];if (title !== undefined) parts.push(["title", title]);if (body !== undefined) parts.push(["body", body]);+ const leaked = parts.flatMap(([, text]) => securityFingerprints(text));+ if (leaked.length) {+ env.err(`gstack-post: refused, the text names security finding ${[...new Set(leaked)].join(", ")}. GitHub text is public: write the security finding as the redacted line gstack prints (security finding, details recorded privately) and keep its location and reason in the private record (docs/troubleshooting.md#security-finding-in-body). Nothing was posted.\n`);+ return EXIT.refused;+ }const vis = visibility(env, req, remote.kind, configBin);const email = env.run("git", ["config", "user.email"]);diff --git a/lib/review-scope.ts b/lib/review-scope.tsindex cf8191900..31909ab0c 100644--- a/lib/review-scope.ts+++ b/lib/review-scope.ts@@ -17,6 +17,7 @@import * as path from 'node:path';import { SPECIALISTS } from './review-depth';import { quarantinedIds, rank, readLedger, type LedgerBlocker } from './review-ledger';+import { isSecurityFinding, opaqueFindingId, REDACTED_REASON } from './security-findings';import { parseSpecialistOutput } from './state-matrix';export type Locus = 'diff' | 'fix-range' | 'outside';@@ -250,25 +251,30 @@ function findingText(f: ScopeFinding): string {return oneLine(f.summary ?? f.problem ?? f.category ?? 'review finding');}-export interface DeferredRecord { fingerprint: string; path: string; severity: string; stated?: string; summary: string }+export interface DeferredRecord { fingerprint: string; path: string; severity: string; stated?: string; summary: string; security?: true }/** The PR's record of a deferred finding: `severity` stays the collected label, `stated` carries what the reviewer wrote beside it. */export function deferredRecord(f: ScopedFinding): DeferredRecord {const said = [typeof f.stated?.severity === 'string' ? `Severity: ${oneLine(f.stated.severity)}` : '', typeof f.stated?.blocks === 'string' ? `Blocks: ${oneLine(f.stated.blocks)}` : ''].filter(Boolean);- return { fingerprint: findingIdentity(f), path: findingWhere(f), severity: String(f.severity ?? 'unrated'), ...(said.length ? { stated: said.join(', ') } : {}), summary: String(f.summary ?? f.problem ?? f.category ?? '') };+ return { fingerprint: findingIdentity(f), path: findingWhere(f), severity: String(f.severity ?? 'unrated'), ...(said.length ? { stated: said.join(', ') } : {}), summary: String(f.summary ?? f.problem ?? f.category ?? ''), ...(isSecurityFinding(f) ? { security: true as const } : {}) };}-/** The PR-body section for deferred findings, which stay on the PR: no issue is filed and no closing keyword is written. Only `frozen` defers. */+/**+ * The PR-body section for deferred findings, which stay on the PR: no issue is filed and no closing keyword is written. Only `frozen` defers.+ * A security-class finding lists only an opaque id and lib/security-findings.ts's REDACTED_REASON; its path and summary stay in the local+ * deferred and classified files (GST-3076).+ */export function renderDeferredSection(deferred: readonly DeferredRecord[], noted: readonly ScopeFinding[] = []): string {const out: string[] = [];if (deferred.length) {out.push('## Deferred findings', '', 'Blocking findings in code this PR did not change (review scope: frozen). They stay on this PR and are not filed as issues.', '');- for (const d of deferred) out.push(`- Deferred: ${oneLine(d.severity)}${d.stated ? ` (the reviewer wrote ${oneLine(d.stated)})` : ''} \`${oneLine(d.path)}\` ${oneLine(d.summary)}`);+ for (const d of deferred) out.push(d.security || isSecurityFinding(d) ? `- Deferred: ${oneLine(d.severity)} \`${opaqueFindingId(d.fingerprint, d.summary)}\` ${REDACTED_REASON}`+ : `- Deferred: ${oneLine(d.severity)}${d.stated ? ` (the reviewer wrote ${oneLine(d.stated)})` : ''} \`${oneLine(d.path)}\` ${oneLine(d.summary)}`);out.push('');}if (noted.length) {out.push('## Review notes', '', 'Below the blocking floor (advisory, informational, test-gap or wording items); recorded here and not fixed in this PR.', '');- for (const n of noted) out.push(`- ${oneLine(n.severity ?? 'INFORMATIONAL')}${n.advisory ? ' [ADVISORY]' : ''} \`${findingWhere(n)}\` ${findingText(n)}`);+ for (const n of noted) out.push(`- ${oneLine(n.severity ?? 'INFORMATIONAL')}${n.advisory ? ' [ADVISORY]' : ''} ${isSecurityFinding(n) ? `\`${opaqueFindingId(findingIdentity(n), findingText(n))}\` ${REDACTED_REASON}` : `\`${findingWhere(n)}\` ${findingText(n)}`}`);out.push('');}return out.join('\n');diff --git a/lib/ruled-notes.ts b/lib/ruled-notes.tsindex 4b24e9c41..f5b044491 100644--- a/lib/ruled-notes.ts+++ b/lib/ruled-notes.ts@@ -9,6 +9,7 @@ import { spawnSync } from 'node:child_process';import * as fs from 'node:fs';import * as path from 'node:path';import { locate, readRecord, type ApprovalRow, type Env } from './approval-record';+import { isSecurityFinding, REDACTED_FINDING, REDACTED_REASON } from './security-findings';export interface RuledNote { finding: string; head: string; by: string; reason: string; at: string; approval: string }@@ -39,8 +40,11 @@ export function readRuledNotes(cwd: string, env: Env = process.env): RuledNote[]return 'code' in loc ? [] : ruledNotes(readRecord(loc).rows);}-/** The one-line form finish prints after `RULED_NOTE: ` and the PR body carries after `Ruled note: `. */-export const ruledNoteText = (n: RuledNote) => `${n.finding} at ${n.head.slice(0, 12)} ruled by ${n.by} at ${n.at}: ${n.reason} (approval ${n.approval})`;+/** The ruling as public text may carry it: a security-class finding's fingerprint and reason stay in the approval record (GST-3076). */+export const publicRuledNote = (n: RuledNote): RuledNote => isSecurityFinding(n.finding) ? { ...n, finding: REDACTED_FINDING, reason: REDACTED_REASON } : n;++/** The one-line form finish prints after `RULED_NOTE: ` and the PR body carries after `Ruled note: `, from publicRuledNote. */+export const ruledNoteText = (note: RuledNote) => { const n = publicRuledNote(note); return `${n.finding} at ${n.head.slice(0, 12)} ruled by ${n.by} at ${n.at}: ${n.reason} (approval ${n.approval})`; };/** The /ship run open on this checkout (its marker in the git dir, which finish removes), if any. */export function openShipRun(cwd: string): string | undefined {diff --git a/lib/security-findings.ts b/lib/security-findings.tsnew file mode 100644index 000000000..bd7c92a9a--- /dev/null+++ b/lib/security-findings.ts@@ -0,0 +1,32 @@+/**+ * Security findings stay out of public text (GST-3076). A PR body keeps every earlier version in its edit history, and a+ * ruled, dispositioned, deferred or noted security finding is often a live exposure outside the PR's own change, so its+ * location and reason never go into a line gstack renders for a PR body, its receipt block or a GitHub post. The public+ * form is an opaque id and REDACTED_REASON; the fingerprint and reason stay where they were recorded, in the private+ * approval record (`gstack-approvals list`) or the local review files. This holds on every repository, whatever its+ * visibility: the rendered lines are compared word for word at receipt write and at land, so they cannot depend on a+ * visibility lookup that can fail or change, and a private repository can go public with its PR history.+ */+import { createHash } from 'node:crypto';++/** The finding categories that are security class: the security, red-team and targeted auth and secret reviewers. */+export const SECURITY_CATEGORIES: readonly string[] = ['security', 'auth', 'secret', 'red-team'];+export const REDACTED_FINDING = 'redacted';+export const REDACTED_REASON = 'security finding, details recorded privately';+export const REDACTED_WORDS = 'recorded privately';++const FINGERPRINT_CATEGORY = /^.+:\d*:([^:\s]+)$/;+const RAW_FINGERPRINT = new RegExp(`[^\\s\`'"(\\[<>|]+:\\d+:(?:${SECURITY_CATEGORIES.join('|')})(?![\\w-])`, 'gi');++/** Whether a finding is security class, by its category, its reviewer or its fingerprint's `path:line:category`. */+export function isSecurityFinding(f: string | { fingerprint?: unknown; category?: unknown; specialist?: unknown }): boolean {+ const o = typeof f === 'string' ? { fingerprint: f } : f;+ const fromPrint = typeof o.fingerprint === 'string' ? FINGERPRINT_CATEGORY.exec(o.fingerprint)?.[1] : undefined;+ return [o.category, o.specialist, fromPrint].some(c => typeof c === 'string' && SECURITY_CATEGORIES.includes(c.toLowerCase()));+}++/** An id for a finding that names neither its location nor its text, and that cannot be guessed from the repository's paths alone. */+export const opaqueFindingId = (fingerprint: string, detail: string) => 'sf-' + createHash('sha256').update(`${fingerprint}\u0000${detail}`).digest('hex').slice(0, 12);++/** Every raw security-class fingerprint (`path:line:security` and the like) in text bound for a public surface. */+export const securityFingerprints = (text: string): string[] => [...new Set(text.match(RAW_FINGERPRINT) ?? [])];diff --git a/ship/sections/pr-body.md b/ship/sections/pr-body.mdindex 21e2f71ee..79bc554f2 100644--- a/ship/sections/pr-body.md+++ b/ship/sections/pr-body.md@@ -127,6 +127,7 @@ with its ruler and reason; each `Gate disposition: …` line `gstack-approvals d`UNAVAILABLE — ...`; never `none detected` for partial or UNAVAILABLE. Under it, eachkept finding's `gate`, path and `reason`, and each open finding's `gate` and path.Identity and reason only; no hunk text.>+<A security finding (category security, auth, secret or red-team) never appears anywhere in the body by path, line or reason, and on the gate line above a security gate finding shows only its `gate`: use the redacted line gstack prints ("security finding, details recorded privately") and put the details in your private report (docs/ship-policy.md#security-findings-stay-private).><Outside review: its verdict; `unverified` or `unavailable` is listed as missing coverage with its reason, never as passed.><Step 9.4's saved `## Deferred findings` and `## Review notes` sections, verbatim, as their owndiff --git a/ship/sections/pr-body.md.tmpl b/ship/sections/pr-body.md.tmplindex d54a2f404..bd582d2a8 100644--- a/ship/sections/pr-body.md.tmpl+++ b/ship/sections/pr-body.md.tmpl@@ -118,6 +118,7 @@ with its ruler and reason; each `Gate disposition: …` line `gstack-approvals d`UNAVAILABLE — ...`; never `none detected` for partial or UNAVAILABLE. Under it, eachkept finding's `gate`, path and `reason`, and each open finding's `gate` and path.Identity and reason only; no hunk text.>+<A security finding (category security, auth, secret or red-team) never appears anywhere in the body by path, line or reason, and on the gate line above a security gate finding shows only its `gate`: use the redacted line gstack prints ("security finding, details recorded privately") and put the details in your private report (docs/ship-policy.md#security-findings-stay-private).><Outside review: its verdict; `unverified` or `unavailable` is listed as missing coverage with its reason, never as passed.><Step 9.4's saved `## Deferred findings` and `## Review notes` sections, verbatim, as their owndiff --git a/test/review-scope.test.ts b/test/review-scope.test.tsindex d544246e3..6d2035872 100644--- a/test/review-scope.test.ts+++ b/test/review-scope.test.ts@@ -169,13 +169,13 @@ describe('deferral rendering', () => {test('a deferred record keeps the collected label as its severity and the reviewer\'s stated severity and Blocks beside it (GST-766)', () => {expect(deferredRecord({ ...finding, stated: { severity: 'Low', blocks: 'no' } })).toMatchObject({ severity: 'CRITICAL', stated: 'Severity: Low, Blocks: no' });expect(deferredRecord({ ...finding, stated: { blocks: 'yes\n- **Injected:** x' } })).toMatchObject({ severity: 'CRITICAL', stated: 'Blocks: yes - **Injected:** x' });- expect(deferredRecord(finding)).toEqual({ fingerprint: 'lib/legacy.ts:7:data-loss', path: 'lib/legacy.ts:7', severity: 'CRITICAL', summary: 'Unbounded delete\nwithout a where clause' });+ expect(deferredRecord(finding)).toEqual({ fingerprint: 'lib/legacy.ts:7:data-loss', path: 'lib/legacy.ts:7', severity: 'CRITICAL', summary: 'Unbounded delete\nwithout a where clause', security: true });});test('deferred findings stay on the PR: the body section lists them, says no issue was filed, and never closes anything (R85)', () => {const section = renderDeferredSection([{ fingerprint: 'lib/legacy.ts:7:data-loss', path: 'lib/legacy.ts:7', severity: 'CRITICAL', summary: 'Unbounded delete' },- { fingerprint: 'lib/old.ts:1:auth', path: 'lib/old.ts:1', severity: 'CRITICAL', stated: 'Blocks: no', summary: 'Missing owner\ncheck' }],+ { fingerprint: 'lib/old.ts:1:correctness', path: 'lib/old.ts:1', severity: 'CRITICAL', stated: 'Blocks: no', summary: 'Missing owner\ncheck' }],[{ path: 'src/auth.ts', line: 42, severity: 'INFORMATIONAL', summary: 'rename b', advisory: true }]);expect(section).toContain('## Deferred findings');expect(section).toContain('not filed as issues');diff --git a/test/security-finding-redaction.test.ts b/test/security-finding-redaction.test.tsnew file mode 100644index 000000000..191323a80--- /dev/null+++ b/test/security-finding-redaction.test.ts@@ -0,0 +1,151 @@+/**+ * Security findings stay out of public text (GST-3076): a PR body, its receipt block and every line gstack prints for one+ * carry no finding location (`path:line`) and no reason when the finding is security class (category security, auth,+ * secret or red-team). The public form is an opaque id and "security finding, details recorded privately"; the fingerprint+ * and reason stay in the private approval record or the local review files. Every other finding prints as before.+ * Synthetic fixtures only.+ */+import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';+import * as fs from 'node:fs';+import * as path from 'node:path';+import { renderRecord, type ApprovalRow, type ReadResult, type StoreLocation } from '../lib/approval-record';+import { EXIT } from '../lib/headless-artifacts';+import { gateDispositionText, type GateDisposition } from '../lib/gate-dispositions';+import { EXIT as POST_EXIT, runPost, type PostEnv } from '../lib/gstack-post';+import { deferredRecord, renderDeferredSection } from '../lib/review-scope';+import { ruledNoteRow, ruledNoteText, type RuledNote } from '../lib/ruled-notes';+import { securityFingerprints } from '../lib/security-findings';+import { RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';++setDefaultTimeout(90_000);+const BIN = path.dirname(RELEASE);+const ships: ShipFx[] = [];+afterEach(() => { while (ships.length) ships.pop()!.cleanup(); });++const HEAD = 'c0ffee0000000000000000000000000000000001';+const SECRET_REASON = 'session token logged by the retry handler';+const SEC = 'src/net/retry.ts:42:security';+const note = (finding: string, reason: string): RuledNote => ({ finding, head: HEAD, by: 'Fixture Owner', reason, at: '2026-11-18T00:00:00Z', approval: 'a-0123456789ab' });+const leaks = (text: string, where: string, reason: string) => [text.includes(where), text.includes(reason)];++// Value: protects=a ruled security finding's location and reason never reach a public line (GST-3076, a public repo's PR body+// showed file:line:security and why it was left); fails_when=ruledNoteText prints the fingerprint or reason of a security,+// auth, secret or red-team finding, or changes a non-security line; seam=the one renderer every Ruled note line goes through+describe('ruled notes', () => {+ test('a security-class ruling prints an opaque id and the private-record phrase; other rulings print as before', () => {+ for (const cat of ['security', 'auth', 'secret', 'red-team']) {+ const line = ruledNoteText(note(`src/net/retry.ts:42:${cat}`, SECRET_REASON));+ expect(leaks(line, 'src/net/retry.ts', SECRET_REASON)).toEqual([false, false]);+ expect(line).toBe('redacted at c0ffee000000 ruled by Fixture Owner at 2026-11-18T00:00:00Z: security finding, details recorded privately (approval a-0123456789ab)');+ }+ expect(ruledNoteText(note('src/x.ts:1:naming', 'naming ships as a note'))).toBe('src/x.ts:1:naming at c0ffee000000 ruled by Fixture Owner at 2026-11-18T00:00:00Z: naming ships as a note (approval a-0123456789ab)');+ });+});++// Value: protects=a gate disposition on a security finding shows no location, reason or owner words, and the lander's+// receipt-vs-store comparison still matches; fails_when=the line carries them, or a non-security line changes;+// seam=gateDispositionText+describe('gate dispositions', () => {+ test('a security-class disposition is redacted; another prints as before', () => {+ const d = (finding: string): GateDisposition => ({ finding, gate_id: '69c7c3432501', head: HEAD, by: 'Fixture Owner', reason: SECRET_REASON, words: 'ship it, the token path is next', at: '2026-11-18T00:00:00Z', approval: 'a-0123456789ab' });+ const sec = gateDispositionText(d(SEC));+ expect([...leaks(sec, 'src/net/retry.ts', SECRET_REASON), sec.includes('token path')]).toEqual([false, false, false]);+ expect(sec).toContain('security finding, details recorded privately');+ expect(gateDispositionText(d('tests/b.test.ts:3:gate-integrity'))).toBe('tests/b.test.ts:3:gate-integrity [gate 69c7c3432501] at c0ffee000000 by Fixture Owner at 2026-11-18T00:00:00Z: session token logged by the retry handler — "ship it, the token path is next" (approval a-0123456789ab)');+ });+});++// Value: protects=a deferred or noted security finding in code the PR did not change (a live exposure out of scope) is listed+// without its path or summary; fails_when=the PR-body section names either, or a non-security line changes; seam=renderDeferredSection+describe('deferred findings and review notes', () => {+ test('security-class entries are redacted to an opaque id; others print as before', () => {+ const out = renderDeferredSection(+ [{ fingerprint: SEC, path: 'src/net/retry.ts:42', severity: 'CRITICAL', summary: SECRET_REASON }, { fingerprint: 'src/a.ts:3:correctness', path: 'src/a.ts:3', severity: 'CRITICAL', summary: 'off by one' }],+ [{ fingerprint: 'src/auth/login.ts:9:auth', path: 'src/auth/login.ts', line: 9, severity: 'INFORMATIONAL', category: 'auth', summary: 'cookie lacks SameSite' }, { path: 'src/b.ts', line: 2, severity: 'INFORMATIONAL', category: 'security', summary: 'unescaped echo' }, { path: 'src/c.ts', line: 4, severity: 'INFORMATIONAL', category: 'naming', summary: 'rename x' }],+ );+ for (const s of ['src/net/retry.ts', SECRET_REASON, 'src/auth/login.ts', 'SameSite', 'src/b.ts', 'unescaped echo']) expect([s, out.includes(s)]).toEqual([s, false]);+ expect(out.match(/`sf-[0-9a-f]{12}` security finding, details recorded privately/g)?.length).toBe(3);+ expect(out).toContain('- Deferred: CRITICAL `src/a.ts:3` off by one');+ expect(out).toContain('- INFORMATIONAL `src/c.ts:4` rename x');+ });++ test('a lineless security fingerprint and a security reviewer\'s other category are redacted when deferred', () => {+ const f = { severity: 'CRITICAL', path: 'src/a.ts', line: 7, category: 'injection', specialist: 'security', summary: SECRET_REASON, scope: 'defer' as const, locus: 'outside' as const, kind: 'defect' as const, blocking: true };+ const out = renderDeferredSection([JSON.parse(JSON.stringify(deferredRecord(f))), { fingerprint: 'src/x.ts::auth', path: 'src/x.ts', severity: 'CRITICAL', summary: 'cookie lacks SameSite' }]);+ for (const s of ['src/a.ts', 'src/x.ts', SECRET_REASON, 'SameSite']) expect([s, out.includes(s)]).toEqual([s, false]);+ expect(ruledNoteText(note('src/x.ts::security', SECRET_REASON))).not.toContain('src/x.ts');+ });+});++// Value: protects=the whole path on a synthetic public repository: gstack-approvals rule, rulings, receipt write and the receipt+// block keep a security ruling's fingerprint and reason out, the private record keeps them, and write refuses a body that+// pastes a raw security fingerprint; fails_when=any public output carries them or the record loses them;+// seam=gstack-approvals rule|rulings|list and gstack-ship-receipt write+describe('a security ruling on a public repository', () => {+ test.skipIf(process.platform === 'win32')('nothing public names the finding; the private record still does', () => {+ const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n' });+ ships.push(f);+ const gh = path.join(f.root, 'stub', 'gh');+ fs.writeFileSync(gh, '#!/bin/sh\ncase "$*" in *visibility*) echo PUBLIC ;; *) exit 1 ;; esac\n', { mode: 0o755 });+ const run = (bin: string, args: string[]) => f.run(path.join(BIN, bin), args, { GSTACK_APPROVALS_MIRROR: '0' });+ const head = f.git('rev-parse', 'HEAD').stdout.trim();+ const ruled = run('gstack-approvals', ['rule', '--finding', 'src/x.ts:1:security', '--head', head, '--reason', SECRET_REASON, '--words', 'note it', '--by', 'Fixture Owner']);+ expect(ruled.status, ruled.stderr).toBe(0);+ expect(leaks(ruled.stdout + ruled.stderr, 'src/x.ts:1', SECRET_REASON)).toEqual([false, false]);+ const rulings = run('gstack-approvals', ['rulings']);+ const line = rulings.stdout.trim();+ expect([line.startsWith('Ruled note: redacted at '), ...leaks(line, 'src/x.ts:1', SECRET_REASON)]).toEqual([true, false, false]);+ const rendered = run('gstack-approvals', ['render']).stdout;+ expect(leaks(rendered, 'src/x.ts:1', SECRET_REASON)).toEqual([false, false]);+ expect(leaks(run('gstack-approvals', ['list']).stdout, 'src/x.ts:1:security', SECRET_REASON)).toEqual([true, true]);+ const body = path.join(f.root, 'body.md');+ const write = () => f.run(path.join(BIN, 'gstack-ship-receipt'), ['write', '--pr', '7', '--base', 'main', '--version', '1.0.0', '--session-kind', 'unattended', '--body', body], { GSTACK_APPROVALS_MIRROR: '0' });+ fs.writeFileSync(body, `## Pre-Landing Review\n\n${line}\nLeft open: src/x.ts:1:security\n`);+ const pasted = write();+ expect([pasted.status, pasted.stderr]).toEqual([EXIT.fail, expect.stringContaining('src/x.ts:1:security')]);+ fs.writeFileSync(body, `## Pre-Landing Review\n\n${line}\n`);+ const ok = write();+ expect(ok.status, ok.stderr).toBe(EXIT.ok);+ expect(leaks(ok.stdout, 'src/x.ts:1', SECRET_REASON)).toEqual([false, false]);+ });+});++// Value: protects=gstack-post never sends a body that carries a raw security fingerprint to GitHub; fails_when=it posts one,+// or refuses a body with a non-security fingerprint; seam=runPost before any gh call+describe('gstack-post', () => {+ const post = (body: string) => {+ const calls: string[][] = [], err: string[] = [];+ const env: PostEnv = {+ run(cmd, args) {+ calls.push([cmd, ...args]);+ if (cmd === 'git' && args[0] === 'remote') return { status: 0, stdout: '[email protected]:acme/widget.git\n', stderr: '' };+ if (cmd === 'cfg') return { status: 0, stdout: 'public\n', stderr: '' };+ return { status: cmd === 'git' ? 1 : 0, stdout: '', stderr: '' };+ },+ readFile: () => body, out: () => {}, err: t => { err.push(t); },+ };+ return { code: runPost(['pr-comment', '7', '--body-file', 'b.md'], env, 'cfg'), posted: calls.some(c => c[0] === 'gh' && c[1] === 'pr' && c[2] === 'comment'), err: err.join('') };+ };+ test('a raw security fingerprint is refused; another fingerprint posts', () => {+ const sec = post('Left open: `src/net/retry.ts:42:security`.\n');+ expect([sec.code, sec.posted, sec.err]).toEqual([POST_EXIT.refused, false, expect.stringContaining('security finding')]);+ const other = post('Left open: `src/a.ts:3:naming`.\n');+ expect([other.code, other.posted]).toEqual([POST_EXIT.posted, true]);+ expect(post('Left open: `src/x.ts:4:Auth`.\n').posted).toBe(false);+ expect(post('Moves the check into `crate::auth`.\n').posted).toBe(true);+ });+});++// Value: protects=a private repository's full Approvals table (the one /ship puts in the PR body) shows a security ruling+// without its fingerprint or reason, so receipt write's guard does not refuse that standard body; fails_when=the full table+// prints the raw ask or scope of a security ruled_note row, or changes another row; seam=renderRecord full mode+describe('the full approvals table', () => {+ test('a security ruling row is redacted in full mode; another row prints as before', () => {+ const row = (finding: string, reason: string): ApprovalRow => ({ schema_version: 1, id: 'a-0123456789ab', date: '2026-11-18', ...ruledNoteRow(finding, HEAD, reason), words: 'note it', by: 'Fixture Owner', outcome: 'approved', pending: '', source: '', branch: 'feat', recorded_at: '2026-11-18T00:00:00Z' } as ApprovalRow);+ const read = { rows: [row(SEC, SECRET_REASON), row('src/x.ts:1:naming', 'naming ships as a note')], state: 'ok' } as unknown as ReadResult;+ const out = renderRecord(read, { branch: 'feat', file: 'f' } as StoreLocation, { mode: 'full' });+ expect([...leaks(out, 'src/net/retry.ts', SECRET_REASON), securityFingerprints(out)]).toEqual([false, false, []]);+ expect(out).toContain(`ruled_note redacted at ${HEAD}: security finding, details recorded privately`);+ expect(out).toContain(`ruled_note src/x.ts:1:naming at ${HEAD}: naming ships as a note`);+ });+});diff --git a/test/size-ledger/ship/security-findings-stay-out-of-pr-bodies.json b/test/size-ledger/ship/security-findings-stay-out-of-pr-bodies.jsonnew file mode 100644index 000000000..f3a9b74b4--- /dev/null+++ b/test/size-ledger/ship/security-findings-stay-out-of-pr-bodies.json@@ -0,0 +1,4 @@+{+ "bytes": 383,+ "why": "pr-body: security findings never appear in the PR body by path, line or reason (GST-3076)"+}