mirror of
https://github.com/garrytan/gstack.git
synced 2026-12-01 20:34:25 +01:00
Stop mistaking ordinary text for Capy ids and check every part of a public PR body (GST-4105) (#4872)
On public repositories, `/gstack-ship` no longer refuses or rewrites ordinary text such as `SHA-256:abc` or `test/jam_fix.ts` as if it were a Capy id, and it now checks every part of the PR body it posts. Why: these are the follow-ups #4868 left open. It made public PR bodies safe but caught too much and left a few corners unchecked. Nothing to do: private repositories keep working with PR bodies written before #4868. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=security Review-Finding: p2/outside-voice#1 reader=outside-voice Review-Finding: p2/outside-voice#2 reader=outside-voice Review-Finding: p2/outside-voice#3 reader=outside-voice Review-Finding: p2/outside-voice#4 reader=outside-voice Review-Finding: p2/adversarial-native#1 reader=adversarial-native
This commit is contained in:
1 parent
3af268b2b6
commit
dade7cacf1
7 files changed
+341
-38
No files matched your search
@@ -17,7 +17,7 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import { spawnSync } from './spawn-sync';
|
||||
import * as fs from 'node:fs';
|
||||
import { appendRows, locate, readRecord, type ApprovalRow, type Env, type RecordError, type StoreLocation } from './approval-record';
|
||||
import { appendRows, locate, readRecord, repoVisibility, type ApprovalRow, type Env, type RecordError, type RepoVisibility, type StoreLocation } from './approval-record';
|
||||
import type { ShipReceipt } from './headless-artifacts';
|
||||
import type { ResultCodeName } from './result-codes';
|
||||
import { isGstackActor, redactInternalIds, type RuledNote } from './ruled-notes';
|
||||
@@ -140,7 +140,8 @@ export type GateAcceptanceCode = Extract<ResultCodeName, 'QUEUE_GATE_DISPOSITION
|
||||
* The lander's check (docs/ship-policy.md#gate-dispositions), one function for `land --pin`, `verify --pin` and `ready`: the
|
||||
* dispositions `branch`'s store applies at `pin`, re-derived here, each printed as GATE_DISPOSITION. It refuses when the
|
||||
* receipt's gate_dispositions or the PR body's `Gate disposition:` lines differ from them, and, with `accepted` (land and
|
||||
* verify; ready passes none), when an applied disposition is not accepted or an accepted id is not applied.
|
||||
* verify; ready passes none), when an applied disposition is not accepted or an accepted id is not applied. On a repository gh
|
||||
* reports private, a body written before GST-1955 that carries the line with its Capy ids unredacted still counts (GST-4105).
|
||||
*/
|
||||
export function gateAcceptance(o: { cwd: string; branch: string; pin: string; body: string; receipt?: ShipReceipt; accepted?: readonly string[]; env?: Env; noted?: readonly ApprovalRow[] }):
|
||||
{ lines: string[]; applied: GateDisposition[]; noteRows?: ApprovalRow[]; failure?: { code: GateAcceptanceCode; message: string; fix: string } } {
|
||||
@@ -154,13 +155,16 @@ export function gateAcceptance(o: { cwd: string; branch: string; pin: string; bo
|
||||
const listed = recorded ?? [];
|
||||
const where = `the store at ${loc.mirror ?? loc.file}${o.noted?.length ? ' with the READY note\'s rows' : ''}`;
|
||||
const lines = applied.map(d => `GATE_DISPOSITION: ${gateDispositionText(d)}`);
|
||||
const bodyHas = (text: string) => o.body.split(/\r?\n/).some(b => b.trim() === `Gate disposition: ${text}`);
|
||||
let visibility: RepoVisibility | undefined;
|
||||
const isPrivate = () => (visibility ??= repoVisibility(o.cwd, o.env ?? process.env)) === 'private';
|
||||
if (!applied.length && !listed.length && !o.accepted?.length) return { lines, applied, noteRows };
|
||||
const problems: string[] = [];
|
||||
for (const d of applied) {
|
||||
const r = listed.find(l => l.approval === d.approval);
|
||||
const r = listed.find(l => l.approval === d.approval), legacy = dispositionLine(securityRedacted(d));
|
||||
if (!r) problems.push(recorded ? `the receipt omits applied disposition ${d.approval}` : `the receipt has no gate_dispositions field (written before receipts always recorded it, or edited), but ${where} applies disposition ${d.approval}`);
|
||||
else if (gateDispositionText(r as GateDisposition) !== gateDispositionText(d)) problems.push(`the receipt's disposition ${d.approval} differs from the store's row`);
|
||||
if (!o.body.split(/\r?\n/).some(b => b.trim() === `Gate disposition: ${gateDispositionText(d)}`)) problems.push(`the PR body lacks the line "Gate disposition: ${gateDispositionText(d)}"`);
|
||||
if (!bodyHas(gateDispositionText(d)) && !(legacy !== gateDispositionText(d) && bodyHas(legacy) && isPrivate())) problems.push(`the PR body lacks the line "Gate disposition: ${gateDispositionText(d)}"`);
|
||||
}
|
||||
for (const l of listed) if (!applied.some(d => d.approval === l.approval)) problems.push(`the receipt lists disposition ${l.approval}, which ${where} does not apply at ${o.pin.slice(0, 12)}: this lander may read another GSTACK_STATE_ROOT or approvals mirror than the one the owner recorded into (set GSTACK_APPROVALS_DIR to it), or the row was removed after the receipt was written`);
|
||||
if (o.accepted) {
|
||||
@@ -177,12 +181,14 @@ export function gateAcceptance(o: { cwd: string; branch: string; pin: string; bo
|
||||
* (GST-1955), so the dispositions command, finish, the receipt and the queue's store check render one line.
|
||||
*/
|
||||
export const publicGateDisposition = (d: GateDisposition): GateDisposition => {
|
||||
const p = isSecurityFinding(d.finding) ? { ...d, finding: REDACTED_FINDING, reason: REDACTED_REASON, words: REDACTED_WORDS } : d;
|
||||
const p = securityRedacted(d);
|
||||
return { ...p, by: redactInternalIds(p.by), reason: redactInternalIds(p.reason), words: redactInternalIds(p.words) };
|
||||
};
|
||||
const securityRedacted = (d: GateDisposition): GateDisposition => isSecurityFinding(d.finding) ? { ...d, finding: REDACTED_FINDING, reason: REDACTED_REASON, words: REDACTED_WORDS } : d;
|
||||
const dispositionLine = (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 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})`; };
|
||||
export const gateDispositionText = (disposition: GateDisposition) => dispositionLine(publicGateDisposition(disposition));
|
||||
|
||||
/**
|
||||
* The dispositions that close a review row's gate findings: the same fingerprint and gate_id on a gate finding the logger left
|
||||
|
||||
@@ -48,7 +48,7 @@ export function prReviewHistory(body: string): PrReviewHistory {
|
||||
const ordered: Array<ReceiptRun | string> = [];
|
||||
all.forEach((e, i) => {
|
||||
if (e.status === 'voided' || e.carry_kind || e.carried_from) { ordered.push(e); return; }
|
||||
const key = e.run ? `run:${runId(e.run)}@${e.head}` : `#${i}`;
|
||||
const key = typeof e.run === 'string' && e.run ? `run:${runId(e.run)}@${e.head}` : `#${i}`;
|
||||
if (!reviewed.has(key)) ordered.push(key);
|
||||
reviewed.set(key, e);
|
||||
});
|
||||
@@ -73,8 +73,9 @@ export function prReviewHistory(body: string): PrReviewHistory {
|
||||
*/
|
||||
export function placeRunEntry(body: string, entry: ReceiptRun): string {
|
||||
const runs = receiptRuns(body).filter(r => !(entry.status && r.status && sameRun(r.run, entry.run)));
|
||||
if (entry.mark && runs.some(r => JSON.stringify(r) === JSON.stringify(entry))) return body;
|
||||
const kept = keptRuns([...runs, JSON.parse(JSON.stringify(entry)) as ReceiptRun]);
|
||||
const [placed] = keptRuns([JSON.parse(JSON.stringify(entry)) as ReceiptRun]);
|
||||
if (entry.mark && keptRuns(runs).some(r => JSON.stringify(r) === JSON.stringify(placed))) return body;
|
||||
const kept = keptRuns([...runs, placed!]);
|
||||
const block = '```' + RUNS_FENCE + '\n' + kept.map(r => JSON.stringify(r)).join('\n') + '\n```\n';
|
||||
if (RUNS_RE.test(body)) return body.replace(RUNS_RE, () => block);
|
||||
if (extractReceipt(body).found) {
|
||||
|
||||
+11
-2
@@ -34,8 +34,17 @@ export const OWNER_REF = /^[A-Z][A-Z0-9]*-[1-9]\d*:[A-Za-z0-9][\w.:+-]*$/;
|
||||
/**
|
||||
* A Capy thread or message id as public text must never carry it (GST-1955, CAPY-1 qm#3938): a `jam_` thread id, an `icm_` or `iev_`
|
||||
* message id, or a relay ref in OWNER_REF's shape, `<thread code>:<message id or timestamp>`. A thread code alone (`GStack Minder (GSTA-36)`) names a ruler.
|
||||
* Two exemptions sit on top of those catches (GST-4105), each a lookaround that leaves the matched text as it was: an id right after a
|
||||
* `/` is a file name (`test/jam_fix.ts`) unless it is a full 26-character Capy id, and a ref's message part must be a Capy id, an
|
||||
* ISO date or time (`2026-11-19`, `2026-11-28T09:28Z`) or epoch seconds (`1732790000`), so `SHA-256:abc`, `UTF-8:x`, `PR-12:fix` and `A-1:b` are text. A relayed ruling's ref reads
|
||||
* PRIVATE_REF on a public repository whatever its shape (repoRuledNotes).
|
||||
*/
|
||||
export const INTERNAL_ID = /\b(?:jam|icm|iev)_[A-Za-z0-9]+|\b[A-Z][A-Z0-9]*-[1-9]\d*:[A-Za-z0-9][\w.:+-]*/;
|
||||
export const INTERNAL_ID = /\b(?:(?<!\/)|(?=(?:jam|icm|iev)_[A-Za-z0-9]{26}(?![A-Za-z0-9])))(?:jam|icm|iev)_[A-Za-z0-9]+|\b[A-Z][A-Z0-9]*-[1-9]\d*:(?=(?:jam|icm|iev)_[A-Za-z0-9]|\d{4}-\d\d-\d\d|\d{9,}(?!\w))[A-Za-z0-9][\w.:+-]*/;
|
||||
/**
|
||||
* A Ruled note line whose relay (ruledNoteText's ` (relayed from <ref>)` between the ruler and ` at <time>: `) names anything but
|
||||
* PRIVATE_REF: on a public repository its ref is internal whatever its shape. The reason after the time is never read here.
|
||||
*/
|
||||
export const RELAYED_REF = /^Ruled note: \S+ at [0-9a-f]{12} ruled by .*? \(relayed from (?!a private message\) at )[^()]*\) at \d{4}-\d\d-\d\dT/;
|
||||
/** What public text says in place of an INTERNAL_ID: the relay a Ruled note names, and any id in an abandon entry's who and why. */
|
||||
export const PRIVATE_REF = 'a private message';
|
||||
export const redactInternalIds = (text: string) => text.replace(new RegExp(INTERNAL_ID.source, 'g'), PRIVATE_REF);
|
||||
@@ -47,7 +56,7 @@ export const keepsInternalIds = (text: string, cwd: string, env: Env = process.e
|
||||
* relayed from PRIVATE_REF, an id in its ruler or reason reads PRIVATE_REF too, and the approval record's row keeps them (CAPY-1 qm#3938).
|
||||
*/
|
||||
export const repoRuledNotes = (notes: RuledNote[], cwd: string, env: Env = process.env, target?: string): RuledNote[] =>
|
||||
keepsInternalIds(notes.map(n => `${n.relayed ?? ''} ${n.by} ${n.reason}`).join(' '), cwd, env, target) ? notes
|
||||
!notes.some(n => n.relayed || INTERNAL_ID.test(`${n.by} ${n.reason}`)) || renderMode(repoVisibility(cwd, env, target), false) === 'full' ? notes
|
||||
: notes.map(n => ({ ...n, by: redactInternalIds(n.by), reason: redactInternalIds(n.reason), ...(n.relayed ? { relayed: PRIVATE_REF } : {}) }));
|
||||
/** OWNER_REF in words, for the refusals and help that name it; a refusal never echoes the rejected ref, which may hold anything (#4718). */
|
||||
export const OWNER_REF_SHAPE = '<thread code>:<message id or timestamp>, where the thread code is an uppercase letter, then uppercase letters or digits, a dash and a number from 1, and the message part starts with a letter or digit (GSTA-36:2026-11-19T12:29:59Z)';
|
||||
|
||||
Reference in new issue
Block a user