From bf2c126b553fe1943a6be858c616d4b0a7f29228 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Wed, 18 Nov 2026 22:57:04 +0800 Subject: [PATCH] gstack-post no longer reads /ship's own run ids and commit ids as phone numbers (#4480) (#4488) Posting a /ship PR body no longer stops on a phone-number warning for the run id and commit ids that /ship writes into it. Why: most /ship runs hit this confirm (#4480, and #4474), which turned a privacy guard into noise people click past. Nothing to do: the next /ship post goes through without `--confirm`. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: v1/outside-voice#1 reader=outside-voice Review-Finding: v1/adversarial-native#1 reader=adversarial-native --- .../post-skips-receipt-ids-as-phones.md | 1 + docs/troubleshooting.md | 14 ++++ lib/gstack-post.ts | 66 ++++++++++++++----- test/gstack-post.test.ts | 59 ++++++++++++++++- 4 files changed, 122 insertions(+), 18 deletions(-) create mode 100644 changelog.d/post-skips-receipt-ids-as-phones.md diff --git a/changelog.d/post-skips-receipt-ids-as-phones.md b/changelog.d/post-skips-receipt-ids-as-phones.md new file mode 100644 index 000000000..347751ab0 --- /dev/null +++ b/changelog.d/post-skips-receipt-ids-as-phones.md @@ -0,0 +1 @@ +- **`gstack-post` stops reading /ship's own receipt identifiers as phone numbers, so posting a /ship PR body no longer needs a confirm.** The receipt's session run id (`--<8 hex>`, read as an E.164 number when the pid has seven digits, #4480) and all-digit 12-character commit prefixes in its `pregate` and `requires_remote` values used to stop `gstack-post pr-body` with a MEDIUM `pii.phone.e164` finding. The same went for the `SHIP_RECEIPT:` and `CI_CARRY:` lines /ship prints (`heads=`, `carried_from=`, `base_red=`, `ci_carried=:/`). Only those exact values are exempt, in a receipt block the receipt writer rendered and on lines outside code blocks that open with `SHIP_RECEIPT:`, `CI_CARRY:`, `PREGATE:` or `READY_RECEIPT:`. A phone number in prose, in any other code block or field (a receipt line pasted inside one included), or in a hand-written receipt block still needs a confirm. diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index e67dc8bf8..955caa1f3 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -3252,6 +3252,20 @@ exact tokens it finds in these positions: the block, under any other key, a run-id field holding other text or a 10-digit number, or a hand-written, schema-invalid or malformed block still reports (GST-2047). +- inside that same writer-rendered block, the `run` value when it is a + session id `gstack-skill-start` minted (`--<8 hex>`, for example + `1234567-1794900000-0a1b2c3d`), and the 12-hex shas in the `pregate` value + (`@ ( checks, current for )`) and the `requires_remote` + values (`heads=`, `tree=`) (#4480); +- on a line outside any fenced code block that opens with `SHIP_RECEIPT:`, + `CI_CARRY:`, `PREGATE:` or `READY_RECEIPT:` (bare, after `- `, `* ` or + `> `, or after a backtick), the + 12-hex sha list after `heads=`, `head=`, `tree=`, `gated_tree=`, + `predecessor=`, `carried_from=` or `base_red=`, the run id of each + `ci_carried=:/` item, and the shas of the pregate + shape above (#4480). The same value on a line without that prefix, on a + receipt-prefixed line inside a hand-written or non-receipt code block, or a + phone number elsewhere on a receipt line still reports. A bare 11-digit number with none of that context, a 10-digit national number and an E.164 `+14155551234` still report, so the finding means the id stands diff --git a/lib/gstack-post.ts b/lib/gstack-post.ts index ca88db844..bc92ed112 100644 --- a/lib/gstack-post.ts +++ b/lib/gstack-post.ts @@ -546,19 +546,43 @@ function receiptDigitTokens(texts: string[]): string[] { return [...tokens]; } +/** A gstack-skill-start session id (bin/gstack-skill-start _SESSION_ID): parent pid, epoch seconds, then 8 random hex or the pid fallback. */ +const SESSION_ID = /^\d{1,10}-\d{10}-(?:[0-9a-f]{8}|\d{1,10})$/; +/** A line one of /ship's own tools prints (lib/ship-receipt.ts receiptSummaryLine, lib/pregate, lib/ship-queue), as pasted bare, in a list or a quote. */ +const RECEIPT_LINE = /^\s*(?:[-*>]\s+)?`?(?:SHIP_RECEIPT|CI_CARRY|PREGATE|READY_RECEIPT):/; /** - * Where a ship receipt's run-id fields hold GitHub Actions run ids, which pii.phone.e164 reads as phone numbers - * (GST-2047): the 1-based line and column span of each ci_carried[].run, flaky_exception[].runs[] and - * issues.flakes[].run value that is a run id (11 to 20 digits, with an optional /attempt), bounded to that value, in - * every closed ```gstack-ship-receipt``` block whose JSON passes the receipt schema and is byte-identical to - * renderReceiptBlock's rendering of it. Only the receipt writer's own output qualifies, so a - * hand-written, schema-invalid, malformed or unclosed block exempts nothing, and the same number in prose, beside the - * block or under any other key still reports. + * The writer fields of a receipt line that hold 12-hex sha prefixes or GitHub Actions run ids, each capture group one value: a sha list after + * heads=, head=, tree=, gated_tree=, predecessor=, carried_from= or base_red= (lib/run-evidence.ts runReceiptFields, receiptSummaryLine), the run id of + * each ci_carried=:/ item, and the two shas of the receipt's pregate field (bin/gstack-ship-receipt: `@ ( checks, + * current for )`). */ -function receiptRunIdSpans(text: string): Array<{ line: number; from: number; to: number }> { +const RECEIPT_LINE_IDS = [ + /(? RECEIPT_LINE_IDS.flatMap(re => [...text.matchAll(re)].flatMap(m => m.indices!.slice(1).flatMap(ix => ix ? [{ line, from: ix[0] + 1, to: ix[1] }] : []))); + +/** + * Where /ship's own receipt holds identifiers that pii.phone.e164 reads as phone numbers (GST-2047, gstack#4480): the 1-based line and column + * span of each value below. In every closed ```gstack-ship-receipt``` block whose JSON passes the receipt schema and is byte-identical to + * renderReceiptBlock's rendering of it: each ci_carried[].run, flaky_exception[].runs[] and issues.flakes[].run value that is a run id (11 to 20 + * digits, with an optional /attempt), the run value when it is a gstack-skill-start session id, and the RECEIPT_LINE_IDS values inside the + * pregate and requires_remote[] values. On every line outside a fenced code block that opens with a receipt-line prefix (RECEIPT_LINE), its RECEIPT_LINE_IDS values. Only + * those writers' own output qualifies, so a hand-written, schema-invalid, malformed or unclosed block exempts nothing, and the same number in + * prose, in any other code block (a receipt-prefixed line inside one included), on a line without a receipt prefix or under any other key still reports. + */ +function receiptIdSpans(text: string): Span[] { const lines = text.split("\n"); const rows = (v: unknown): number => v !== null && typeof v === "object" && Object.keys(v).length ? 2 + Object.values(v).reduce((n: number, c) => n + rows(c), 0) : 1; - const spans: Array<{ line: number; from: number; to: number }> = []; + let fence = ""; + const spans: Span[] = lines.flatMap((l, i) => { + const f = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(l); + if (f && !fence) { fence = f[1]!; return []; } + if (f && f[1]![0] === fence[0] && f[1]!.length >= fence.length && !f[2]!.trim()) { fence = ""; return []; } + return !fence && RECEIPT_LINE.test(l) ? lineIdSpans(l, i + 1) : []; + }); for (let open = 0; open < lines.length; open++) { if (lines[open] !== "```" + RECEIPT_FENCE) continue; const close = lines.indexOf("```", open + 1); @@ -567,20 +591,28 @@ function receiptRunIdSpans(text: string): Array<{ line: number; from: number; to let receipt: ShipReceipt; try { receipt = JSON.parse(raw); } catch { continue; } if (validateReceipt(receipt).length || renderReceiptBlock(receipt) !== "```" + RECEIPT_FENCE + "\n" + raw + "\n```\n") continue; - const span = (path: Array) => { - let at = open + 1; + const at = (path: Array) => { + let line = open + 1; let v: any = receipt; for (const key of path) { - at++; - for (const [k, c] of Object.entries(v)) { if (k === String(key)) break; at += rows(c); } + line++; + for (const [k, c] of Object.entries(v)) { if (k === String(key)) break; line += rows(c); } v = v[key]; } - if (!/^\d{11,20}(?:\/\d{1,4})?$/.test(typeof v === "number" ? String(v) : typeof v === "string" ? v : "")) return; - const t = lines[at]!; + return { line, v }; + }; + const span = (path: Array, shape = /^\d{11,20}(?:\/\d{1,4})?$/) => { + const { line, v } = at(path); + if (!shape.test(typeof v === "number" ? String(v) : typeof v === "string" ? v : "")) return; + const t = lines[line]!; const key = path.at(-1); const from = t.length - t.trimStart().length + (typeof key === "string" ? JSON.stringify(key).length + 2 : 0) + 1; - spans.push({ line: at + 1, from, to: from + JSON.stringify(v).length - 1 }); + spans.push({ line: line + 1, from, to: from + JSON.stringify(v).length - 1 }); }; + const ids = (path: Array) => { const { line } = at(path); spans.push(...lineIdSpans(lines[line]!, line + 1)); }; + span(["run"], SESSION_ID); + if (typeof receipt.pregate === "string") ids(["pregate"]); + receipt.requires_remote?.forEach((_, i) => ids(["requires_remote", i])); receipt.ci_carried?.forEach((_, i) => span(["ci_carried", i, "run"])); receipt.flaky_exception?.forEach((e, i) => e.runs.forEach((_, j) => span(["flaky_exception", i, "runs", j]))); receipt.issues?.flakes?.forEach((_, i) => span(["issues", "flakes", i, "run"])); @@ -596,7 +628,7 @@ function scanParts(parts: Array<[Part, string]>, vis: RepoVisibility, selfEmail: for (const [part, text] of parts) { const result = scan(text, { repoVisibility: vis, allowlist, ...(selfEmail ? { selfEmail } : {}) }); oversize ||= result.oversize; - const runIds = result.findings.some(f => f.id === "pii.phone.e164") ? receiptRunIdSpans(text) : []; + const runIds = result.findings.some(f => f.id === "pii.phone.e164") ? receiptIdSpans(text) : []; for (const finding of result.findings) { if (finding.id === "pii.phone.e164" && runIds.some(s => s.line === finding.line && s.from <= finding.col && finding.col <= s.to)) continue; found.push({ part, finding }); diff --git a/test/gstack-post.test.ts b/test/gstack-post.test.ts index 9ab7dd553..41ee0c0c0 100644 --- a/test/gstack-post.test.ts +++ b/test/gstack-post.test.ts @@ -11,7 +11,8 @@ import * as fs from "node:fs"; import * as os from "node:os"; import * as path from "node:path"; import { EXIT, attributionCallout, mergeBodySections, runPost, type PostEnv } from "../lib/gstack-post"; -import { extractReceipt, orderReceipt, placeReceipt, receiptRuns } from "../lib/ship-receipt"; +import { extractReceipt, orderReceipt, placeReceipt, receiptRuns, receiptSummaryLine } from "../lib/ship-receipt"; +import { runReceiptFields, type RunEvidence } from "../lib/run-evidence"; import type { ShipReceipt } from "../lib/headless-artifacts"; import { foldSections, unfoldSections } from "../lib/pr-body-shape"; @@ -354,6 +355,62 @@ describe("gstack-post owns the redaction scan", () => { } }); + // Value: protects=/ship's own receipt posts through pr-body without a pii.phone.e164 confirmation (gstack#4480): the writer-rendered block's + // run field holding a gstack-skill-start session id (--<8 hex>), its pregate and requires_remote values naming all-digit 12-hex + // shas, and the SHIP_RECEIPT:, CI_CARRY:, PREGATE: and READY_RECEIPT: lines the writers print (heads=, carried_from=, base_red=, + // ci_carried=:/), while a phone number in prose, in a non-receipt code block, in another field, in a field holding another + // shape, on a line without a receipt prefix or in a hand-written block still needs one; fails_when=every /ship body post with a 7-digit pid or + // an all-digit head prefix needs --confirm, or the exemption reaches past those exact values; why_new=the GST-2047 test covers only run-id + // fields, and the receipt lines' sha fields after heads=, carried_from= and base_red= were never allowlisted; seam=fake run; no_claim=real gh + test("a ship receipt's session id, its sha fields and the receipt lines /ship prints are not phone numbers; a phone number anywhere else still is", () => { + const HEAD = "2294465066182c2f99d64ba0016213463aaa0c14"; + const carry = "remote-gate tree=704992822996 tests=37713 skipped=105 " + runReceiptFields([{ run_id: 44231639842, run_attempt: 1, profile: "ci-reuse/free-tests", head_sha: HEAD } as RunEvidence], new Date("2026-11-18T03:48:28.588Z")); + const receipt = (extra: Partial = {}) => orderReceipt({ + schema_version: 1, pr: 4480, head: HEAD, base: "main", run: "1234567-1794900000-0a1b2c3d", + pregate: "requires-remote cleared @704992822996 (8 checks, current for 229446506618)", + requires_remote: [`pregate.json/remote_gate: ${carry}`], + ci_carried: [{ lane: "free-tests", run: 44231639842, attempt: 1, tree: "704992822996ab" }], + ...extra, + }); + const summary = receiptSummaryLine({ ...receipt(), predecessor: "381726354901aa", carry: { from: "381726354901ffee" }, base_red: { base: "381726354901ffee" }, ci_carried: [{ lane: "free-tests", run: 44231639842, attempt: 1, tree: "t" }, { lane: "windows-smoke", run: 44231645300, attempt: 2, tree: "t" }] } as ShipReceipt); + const lines = [summary, `CI_CARRY: accepted ${carry}`, `- CI_CARRY: cleared pregate.json/remote_gate ${carry}`, "PREGATE: requires-remote tree=704992822996 head=229446506618 checks=8 of 8", "READY_RECEIPT: .gstack/ready/acme-widget/4480-229446506618.json (ok)"]; + expect(summary).toContain("carried_from=381726354901 ci_carried=free-tests:44231639842/1,windows-smoke:44231645300/2 base_red=381726354901"); + const body = (r: ShipReceipt, prose = "Narrows one false positive.") => placeReceipt(`## What changed\n\n${prose}\n`, r); + const post = (text: string) => { + const f = fakeEnv({ files: { "/b": text }, visibility: "public" }); + return { code: run(["pr-body", "4480", "--replace", "--body-file", "/b"], f), phones: f.stdout().split("\n").filter(l => l.startsWith("RULE: pii.phone.e164 ")), f }; + }; + const lineOf = (text: string, needle: string) => text.split("\n").findIndex(l => l.includes(needle)) + 1; + + for (const text of [body(receipt()), body(receipt(), lines.join("\n"))]) { + expect(extractReceipt(text)).toMatchObject({ found: true, errors: [] }); + const { code, phones, f } = post(text); + expect([phones, code]).toEqual([[], EXIT.posted]); + expect(f.posts()).toHaveLength(1); + } + + const holds: Array<[string, string, string]> = [ + ["E.164 in prose", body(receipt(), "Call +14155552671 for the on-call."), "+14155552671"], + ["a session id in a json code block", body(receipt(), '```json\n{ "run": "1234567-1794900000-0a1b2c3d" }\n```'), '{ "run": "1234567'], + ["a number in a plain code block", body(receipt(), "```\ncall 14155552671\n```"), "call 14155552671"], + ["heads= on a line without a receipt prefix", body(receipt(), "heads=229446506618 ran"), "heads=229446506618"], + ["a phone on a receipt line", body(receipt(), "CI_CARRY: none (call +1 415 555 0123)"), "CI_CARRY: none"], + ["a 10-digit ci_carried run on a receipt line", body(receipt(), "SHIP_RECEIPT: pr=4480 ci_carried=free-tests:4155552671/1"), "SHIP_RECEIPT: pr=4480 ci_carried"], + ["a receipt line inside a plain code block", body(receipt(), "```text\nSHIP_RECEIPT: pr=4480 ci_carried=phone:14155552671/1\n```"), "SHIP_RECEIPT: pr=4480 ci_carried=phone"], + ["a receipt line inside a tilde code block", body(receipt(), "~~~\nCI_CARRY: accepted heads=229446506618\n~~~"), "CI_CARRY: accepted heads"], + ["a session id in the thread field", body(receipt({ thread: "1234567-1794900000-0a1b2c3d" })), '"thread": "1234567'], + ["a phone in the run field", body(receipt({ run: "+14155552671" })), '"run": "+14155552671"'], + ["a session id without its random suffix", body(receipt({ run: "1234567-1794900000" })), '"run": "1234567-1794900000"'], + ["a phone in the pregate field", body(receipt({ pregate: "requires-remote cleared, call 415-555-0100" })), "call 415-555-0100"], + ]; + holds.push(["hand-written one-line block", "## What changed\n\nOne fix.\n\n```gstack-ship-receipt\n" + JSON.stringify(receipt({ pregate: undefined, requires_remote: undefined, ci_carried: undefined })) + "\n```\n", '"run":"1234567']); + for (const [name, text, needle] of holds) { + const { code, phones, f } = post(text); + expect([name, phones, code]).toEqual([name, [`RULE: pii.phone.e164 LINE: ${lineOf(foldSections(text), needle)} PART: body`], EXIT.confirm]); + expect(f.posts()).toEqual([]); + } + }); + // Value: protects=a LOW privacy finding (a home path) is a stderr note and never holds a post, while a credential still refuses even inside a // writer-rendered receipt block, whose exemption covers only its run ids (GST-2047); fails_when=a home path needs --confirm, or a key in a // receipt field posts or only asks for confirmation; why_new=no test pinned LOW as non-holding or a key inside a generated block; seam=fake