Skip to content

Commit b4a47c8

Browse files
committed
2 parents e97ab46 + 040f6db commit b4a47c8

904 files changed

Lines changed: 95551 additions & 4680 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/CODEOWNERS‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99

1010
# Repository automation and release security
1111
/.github/ @lidge-jun @Ingwannu
12+
/.coderabbit.yaml @lidge-jun @Ingwannu
13+
/.npmignore @lidge-jun @Ingwannu
14+
/bunfig.toml @lidge-jun @Ingwannu
1215
/scripts/release.ts @lidge-jun @Ingwannu
16+
/scripts/release-notes.ts @lidge-jun @Ingwannu
17+
/scripts/prepare-package.ts @lidge-jun @Ingwannu
1318
/package.json @lidge-jun @Ingwannu
1419
/bun.lock @lidge-jun @Ingwannu
1520

@@ -18,6 +23,9 @@
1823
/src/codex/auth-context.ts @lidge-jun @Ingwannu
1924
/src/server/auth-cors.ts @lidge-jun @Ingwannu
2025
/src/server/management-api.ts @lidge-jun @Ingwannu
26+
/src/lib/admin-secrets.ts @lidge-jun @Ingwannu
27+
/src/lib/service-secrets.ts @lidge-jun @Ingwannu
28+
/src/server/management-auth.ts @lidge-jun @Ingwannu
2129

2230
# Governance and security policy
2331
/AGENTS.md @lidge-jun @Ingwannu

‎.github/scripts/enforce-pr-target.test.cjs‎

Lines changed: 83 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,87 @@ describe("enforce-pr-target workflow", () => {
143143
.split("- name: Checkout trusted PR-quality scripts")[1]
144144
.split(/\n {6}- name:/)[0];
145145
assert.match(checkoutStep, /actions\/checkout@[0-9a-f]{40}/);
146-
// `pull_request_target` pins the PR base SHA. Trusted `status`
147-
// revalidation has no pull_request payload, so it sources scripts from the
148-
// repository default branch that supplied the privileged workflow itself.
149-
assert.match(
150-
checkoutStep,
151-
/ref:\s*\$\{\{\s*github\.event_name\s*==\s*'status'\s*&&\s*github\.event\.repository\.default_branch\s*\|\|\s*github\.event\.pull_request\.base\.sha\s*\}\}/,
146+
// The trusted ref comes from a fixed set of integration branches, never
147+
// from the PR's own base commit: a stacked child's base is another open
148+
// PR's head, and `base.sha` would let that unpromoted commit choose the
149+
// code that runs with this job's write-capable token.
150+
//
151+
// `status` has no pull_request payload and sources from the default branch
152+
// that supplied the privileged workflow. A `main`-targeting PR sources
153+
// from `main` so the workflow definition and the scripts match. Everything
154+
// else resolves to `dev`.
155+
//
156+
// Exact equality, not fragment matching: separate checks for `status`,
157+
// `main`, and `dev` would all pass with the operator grouping wrong or a
158+
// surviving `base.sha` fallback.
159+
const ref = checkoutStep.match(/^\s*ref:\s*(.+)$/m)?.[1];
160+
assert.ok(ref, "trusted checkout must declare ref");
161+
assert.equal(
162+
ref.replace(/\s+/g, " ").trim(),
163+
"${{ github.event_name == 'status' && github.event.repository.default_branch || (github.event.pull_request.base.ref == 'main' && 'main' || 'dev') }}",
164+
);
165+
assert.doesNotMatch(ref, /base\.sha|head\.(?:sha|ref)/);
166+
// Pinning the checkout ref only gates one step. A later `run:` or
167+
// `github-script` step interpolating a head ref would execute
168+
// PR-controlled content with this workflow's write-capable token, so the
169+
// whole file is gated. (`pr.head.sha` read back from the API is an
170+
// identity for comparison, not an interpolated ref, and is unaffected.)
171+
assert.doesNotMatch(
172+
workflow,
173+
/github\.event\.pull_request\.head\.(?:sha|ref|repo)/,
174+
"no step in a pull_request_target workflow may interpolate a PR head ref",
175+
);
176+
// `refs/pull/<n>/head` reaches the same PR-controlled tree without ever
177+
// naming `head`, so ban the merge-ref form too.
178+
assert.doesNotMatch(
179+
workflow,
180+
/refs\/pull\//,
181+
"no step may check out a refs/pull/* ref",
182+
);
183+
// Banning literal text is not enough: `format('refs/{0}/{1}/{2}', ...)`
184+
// builds the same PR-controlled ref without ever spelling it. Every
185+
// checkout in a pull_request_target workflow must therefore declare a ref
186+
// drawn from the trusted allowlist, and no other step may name the PR
187+
// number in a ref-shaped expression.
188+
// An ALLOWLIST, not a denylist: every checkout in this workflow must use
189+
// exactly the trusted expression. Banning known-bad shapes lost twice —
190+
// first to `refs/pull/<n>/head`, then to `format('refs/{0}/...')` — and a
191+
// `repository:` override pointing at the fork head is a third shape no
192+
// denylist would have caught.
193+
const checkouts = workflow.match(/uses:\s*actions\/checkout@[\s\S]*?(?=\n {6}- name:|$)/g) ?? [];
194+
for (const step of checkouts) {
195+
const stepRef = (step.match(/^\s*ref:\s*(.+)$/m)?.[1] ?? "").replace(/\s+/g, " ").trim();
196+
assert.equal(stepRef, "${{ github.event_name == 'status' && github.event.repository.default_branch || (github.event.pull_request.base.ref == 'main' && 'main' || 'dev') }}", "every checkout must use the trusted ref");
197+
assert.doesNotMatch(step, /repository:/, "a checkout must not retarget its repository");
198+
}
199+
// Checkout is not the only way to obtain PR-controlled code. A `run:` step
200+
// can fetch it directly, and that is a realistic future edit rather than a
201+
// synthetic one, so executable steps are gated on the acquisition verbs
202+
// themselves.
203+
// Stop enumerating command shapes. A denylist lost four times here
204+
// (`refs/pull`, `format()`, `repository:`, `gh pr checkout`), and
205+
// `git clone https://github.com/<fork>` would have been the fifth. The
206+
// invariant is simpler than the attack surface: under
207+
// `pull_request_target`, nothing executable may name the PR head or the
208+
// fork repository at all.
209+
// Comments may discuss the head ref; only executable content may not use
210+
// it, so YAML comment lines are stripped before this check.
211+
const executable = workflow
212+
.split("\n")
213+
.filter(line => !/^\s*#/.test(line) && !/^\s*\/\//.test(line.replace(/^\s*/, "")))
214+
.join("\n");
215+
assert.doesNotMatch(
216+
executable.replace(/^\s*\/\/.*$/gm, ""),
217+
/github\.head_ref|pull_request(?:\[['"]head['"]\]|\.head)\s*(?:\[|\.)?\s*['"]?repo/,
218+
"no executable step may reference the PR head repository",
219+
);
220+
// Belt and braces for the acquisition verbs, which have no legitimate use
221+
// in either gate: both only read PR metadata through the API.
222+
assert.doesNotMatch(
223+
workflow,
224+
/gh\s+pr\s+checkout|git\s+(?:fetch|checkout|clone|switch)|refs\/pull/,
225+
"no step may acquire pull-request code",
152226
);
153-
assert.doesNotMatch(checkoutStep, /\|\|\s*'dev'/);
154227
// The readiness ping reads MAINTAINERS.md from the same trusted checkout.
155228
assert.match(checkoutStep, /sparse-checkout:\s*\|\s*\n\s*\.github\/scripts\n\s*MAINTAINERS\.md/);
156229
assert.match(checkoutStep, /persist-credentials:\s*false/);
@@ -197,6 +270,9 @@ describe("enforce-pr-target workflow", () => {
197270
);
198271
assert.ok(qualityCall, "must call collectPrQualityFailures");
199272
assert.match(qualityCall[1], /stackedBase/);
273+
assert.match(qualityCall[1], /changedFilePaths/);
274+
assert.match(qualityCall[1], /filesTruncated/);
275+
assert.match(workflow, /isChangedFileListTruncated/);
200276
});
201277

202278
it("strips stale WRONG BRANCH prefix on failure when base is corrected", () => {

‎.github/scripts/issue-quality-core.cjs‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,10 +1134,8 @@ const REPRO_PATH_RE = new RegExp([
11341134
"~?/[\\w.@-]+(?:/[\\w.@-]+)+",
11351135
"[A-Za-z]:\\\\(?:[\\w.@-]+\\\\)+[\\w.@-]+",
11361136
"~?/[\\w.@-]+/[\\w.@-]+\\.(?:json|yaml|yml|toml|conf|log|env|txt|ts|js|tsx|jsx|sh|ps1|py)",
1137-
"[\\w.@-]+\\.(?:json|yaml|yml|toml|conf|log|env)\\b",
1138-
].join("|"));
1139-
const ACTIONABLE_REPRO_RE = new RegExp(
1140-
[REPRO_COMMAND_RE.source, REPRO_FAILURE_RE.source, REPRO_PATH_RE.source].join("|"),
1137+
"(?:^|[^\\w.@-])[\\w.@-]+\\.(?:json|yaml|yml|toml|conf|log|env)\\b",
1138+
].join("|"),
11411139
"i",
11421140
);
11431141

@@ -1151,9 +1149,18 @@ const EMPTY_FENCE_RE = /^[ \t]{0,3}(?:```+|~~~+)\s*\n\s*\n[ \t]{0,3}(?:```+|~~~+
11511149
* count as actionable when their body contains non-whitespace content.
11521150
*/
11531151
function hasActionableReproductionDetail(text) {
1152+
if (typeof text !== "string") return false;
1153+
// Avoid Markdown cleanup and path matching when the raw input cannot contain
1154+
// actionable syntax. Fences remain eligible through their ` / ~ sigils.
1155+
if (!/[./\\`~]/.test(text) && !REPRO_COMMAND_RE.test(text) && !REPRO_FAILURE_RE.test(text)) {
1156+
return false;
1157+
}
11541158
const c = clean(text);
11551159
if (!c) return false;
1156-
if (ACTIONABLE_REPRO_RE.test(c)) return true;
1160+
if (REPRO_COMMAND_RE.test(c) || REPRO_FAILURE_RE.test(c)) return true;
1161+
// A boundary-anchored filename avoids retrying the same long token from each
1162+
// successive character while preserving case-insensitive extension matches.
1163+
if (/[./\\]/.test(c) && REPRO_PATH_RE.test(c)) return true;
11571164
// Fenced blocks: only count when the body has non-whitespace content.
11581165
if (/```|~~~/.test(c)) {
11591166
const parts = stripFencedActionableContent(c);

‎.github/scripts/issue-quality.test.cjs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,13 @@ describe("validateIssue - feature", () => {
713713
assert.equal(hasActionableReproductionDetail("```\nSIGSEGV at 0x0000\n```"), true);
714714
});
715715

716+
it("bounds long non-matching reproduction path tokens", () => {
717+
const startedAt = performance.now();
718+
assert.equal(hasActionableReproductionDetail(`${"a".repeat(60_000)}.unknown`), false);
719+
assert.ok(performance.now() - startedAt < 500, "actionable reproduction check took too long");
720+
assert.equal(hasActionableReproductionDetail("CONFIG.JSON"), true);
721+
});
722+
716723
it("rejects fenced placeholder-only examples", () => {
717724
const fencedPlaceholders = [
718725
"```\nN/A\n```",

‎.github/scripts/pr-hygiene.test.cjs‎

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,89 @@ describe("pr-hygiene workflow trust boundary", () => {
264264
"utf8",
265265
);
266266

267-
it("checks out the PR base SHA, not the repository default branch", () => {
268-
assert.match(workflow, /ref:\s*\$\{\{\s*github\.event\.pull_request\.base\.sha\s*\}\}/);
267+
it("checks out trusted scripts from an integration branch, never a PR-controlled ref", () => {
268+
// Scope to the checkout step so a stray `ref:` elsewhere cannot satisfy
269+
// this, and compare the whole expression rather than matching fragments:
270+
// independent substring checks would pass even with the operator grouping
271+
// wrong or a `base.sha` fallback still present.
272+
const checkoutStep = workflow
273+
.split("- name: Checkout trusted hygiene script")[1]
274+
.split(/\n {6}- name:/)[0];
275+
const ref = checkoutStep.match(/^\s*ref:\s*(.+)$/m)?.[1];
276+
assert.ok(ref, "trusted checkout must declare ref");
277+
assert.equal(
278+
ref.replace(/\s+/g, " ").trim(),
279+
"${{ github.event.pull_request.base.ref == 'main' && 'main' || 'dev' }}",
280+
);
281+
// A stacked child PR's base is another open PR's head; neither a base nor
282+
// a head ref may select the code that runs with the write-capable token.
283+
assert.doesNotMatch(ref, /base\.sha|head\.(?:sha|ref)/);
284+
assert.match(checkoutStep, /persist-credentials:\s*false/);
285+
});
286+
287+
it("never lets a PR-controlled ref reach an executable step", () => {
288+
// Pinning the checkout ref is not enough on its own: a later `run:` or
289+
// `github-script` step could fetch and execute PR head content and a
290+
// checkout-scoped assertion would still pass. This gates the whole file.
291+
//
292+
// `pull_request_target` grants a write-capable token, so no executable
293+
// surface here may interpolate a head ref, and nothing may reference the
294+
// head repository at all.
295+
assert.doesNotMatch(
296+
workflow,
297+
/pull_request\.head\.(?:sha|ref|repo)/,
298+
"no step in a pull_request_target workflow may consume a PR head ref",
299+
);
300+
// `refs/pull/<n>/head` reaches the same PR-controlled tree without ever
301+
// naming `head`, so ban the merge-ref form too.
302+
assert.doesNotMatch(
303+
workflow,
304+
/refs\/pull\//,
305+
"no step may check out a refs/pull/* ref",
306+
);
307+
// Banning literal text is not enough: `format('refs/{0}/{1}/{2}', ...)`
308+
// builds the same PR-controlled ref without ever spelling it. Every
309+
// checkout in a pull_request_target workflow must therefore declare a ref
310+
// drawn from the trusted allowlist, and no other step may name the PR
311+
// number in a ref-shaped expression.
312+
// An ALLOWLIST, not a denylist: every checkout in this workflow must use
313+
// exactly the trusted expression. Banning known-bad shapes lost twice —
314+
// first to `refs/pull/<n>/head`, then to `format('refs/{0}/...')` — and a
315+
// `repository:` override pointing at the fork head is a third shape no
316+
// denylist would have caught.
317+
const checkouts = workflow.match(/uses:\s*actions\/checkout@[\s\S]*?(?=\n {6}- name:|$)/g) ?? [];
318+
for (const step of checkouts) {
319+
const stepRef = (step.match(/^\s*ref:\s*(.+)$/m)?.[1] ?? "").replace(/\s+/g, " ").trim();
320+
assert.equal(stepRef, "${{ github.event.pull_request.base.ref == 'main' && 'main' || 'dev' }}", "every checkout must use the trusted ref");
321+
assert.doesNotMatch(step, /repository:/, "a checkout must not retarget its repository");
322+
}
323+
// Checkout is not the only way to obtain PR-controlled code. A `run:` step
324+
// can fetch it directly, and that is a realistic future edit rather than a
325+
// synthetic one, so executable steps are gated on the acquisition verbs
326+
// themselves.
327+
// Stop enumerating command shapes. A denylist lost four times here
328+
// (`refs/pull`, `format()`, `repository:`, `gh pr checkout`), and
329+
// `git clone https://github.com/<fork>` would have been the fifth. The
330+
// invariant is simpler than the attack surface: under
331+
// `pull_request_target`, nothing executable may name the PR head or the
332+
// fork repository at all.
333+
// Comments may discuss the head ref; only executable content may not use
334+
// it, so YAML comment lines are stripped before this check.
335+
const executable = workflow
336+
.split("\n")
337+
.filter(line => !/^\s*#/.test(line) && !/^\s*\/\//.test(line.replace(/^\s*/, "")))
338+
.join("\n");
339+
assert.doesNotMatch(
340+
executable.replace(/^\s*\/\/.*$/gm, ""),
341+
/github\.head_ref|pull_request(?:\[['"]head['"]\]|\.head)\s*(?:\[|\.)?\s*['"]?repo/,
342+
"no executable step may reference the PR head repository",
343+
);
344+
// Belt and braces for the acquisition verbs, which have no legitimate use
345+
// in either gate: both only read PR metadata through the API.
269346
assert.doesNotMatch(
270347
workflow,
271-
/Checkout trusted hygiene script[\s\S]*?ref:\s*\$\{\{\s*github\.event\.repository\.default_branch/,
348+
/gh\s+pr\s+checkout|git\s+(?:fetch|checkout|clone|switch)|refs\/pull/,
349+
"no step may acquire pull-request code",
272350
);
273351
});
274352

‎.github/scripts/pr-quality-messages.cjs‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ function buildFailureSections(failures, { pr, allowedBases, defaultBase }) {
229229
sections.push(
230230
"⚠️ **UI screenshot required**",
231231
"",
232-
`This pull request mentions ${inlineCode("gui")} in its title or description, so it is treated as a GUI change.`,
232+
`This pull request changes files under ${inlineCode("gui/")}, or GitHub returned an incomplete changed-file list for a large diff, so it is treated as a GUI change.`,
233233
"",
234234
`@${pr.user.login} Please add a screenshot of the UI change to the description — drag and drop the image into the description editor, or paste a markdown image such as ${inlineCode("![Screenshot](https://example.com/after.png)")}. The check re-runs automatically once the description is edited.`
235235
);
@@ -259,14 +259,10 @@ function failureSummary(failures, { pr }) {
259259
}
260260

261261
/** The notice shown when the gate's own claim check disproves a ticked box. */
262-
function buildClaimCheckNotice(violations, liveHeadSha) {
262+
function buildClaimCheckNotice(violations, _liveHeadSha) {
263263
const lines = [];
264264
for (const code of violations) {
265-
if (code === "ci_green") {
266-
lines.push(
267-
`GitHub CI is not green on the current head ${inlineCode(liveHeadSha.slice(0, 7))}; the **CI green** box has been unticked.`
268-
);
269-
} else if (code === "latest_dev") {
265+
if (code === "latest_dev") {
270266
lines.push(
271267
`The PR is more than ${READINESS_LATEST_DEV_BEHIND_MAX} commits behind ${inlineCode("dev")}; the **latest dev** box has been unticked.`
272268
);

‎.github/scripts/pr-quality-messages.test.cjs‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,23 +213,21 @@ describe("buildStaleNotice", () => {
213213
});
214214

215215
describe("buildClaimCheckNotice", () => {
216-
it("names each violated claim and the reset action", () => {
216+
it("names the latest-dev violation and the reset action", () => {
217217
const notice = buildClaimCheckNotice(
218-
["ci_green", "latest_dev"],
218+
["latest_dev"],
219219
"3f1c0de0a6a4d0a3f9a1b2c3d4e5f60718293a4b",
220220
);
221-
assert.match(notice[0], /CI is not green on the current head `3f1c0de`/);
222-
assert.match(notice[0], /\*\*CI green\*\* box has been unticked/);
223-
assert.match(notice[1], /more than 10 commits behind `dev`/);
224-
assert.match(notice[1], /\*\*latest dev\*\* box has been unticked/);
225-
assert.match(notice[2], /reset: re-test against the latest code/);
221+
assert.match(notice[0], /more than 10 commits behind `dev`/);
222+
assert.match(notice[0], /\*\*latest dev\*\* box has been unticked/);
223+
assert.match(notice[1], /reset: re-test against the latest code/);
226224
});
227225

228-
it("handles a single violation", () => {
226+
it("ignores a stale ci_green code without inventing GitHub-CI copy", () => {
229227
const notice = buildClaimCheckNotice(["ci_green"], "a".repeat(40));
230-
assert.equal(notice.length, 2);
231-
assert.match(notice[0], /CI is not green/);
232-
assert.match(notice[1], /has been reset/);
228+
assert.equal(notice.length, 1);
229+
assert.match(notice[0], /has been reset/);
230+
assert.doesNotMatch(notice[0], /CI is not green/);
233231
});
234232

235233
it("returns only the reset line for an empty violation list", () => {

‎.github/scripts/pr-quality-state.cjs‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,21 @@ function migrateLegacyGateState(enforcerState, readinessState) {
201201
*/
202202

203203
/**
204-
* Bot-side verification of the two checklist claims the gate can check itself.
205-
* The CI box only holds when the head's `ci` check is green, and the
206-
* latest-dev box only holds while the head is at most
207-
* READINESS_LATEST_DEV_BEHIND_MAX commits behind the base. Unknown state
208-
* (compare or checks lookup failed) fails closed: an unverifiable claim is a
209-
* violation, because an attestation must not ride on missing evidence.
204+
* Bot-side verification of the checklist claim the gate can check itself for
205+
* ancestry. The local-CI box is an author attestation only (fork contributors
206+
* cannot start repository CI; a maintainer has to), so it is never disproved
207+
* here — head-drift still resets every box after a new push. The latest-dev
208+
* box only holds while the head is at most READINESS_LATEST_DEV_BEHIND_MAX
209+
* commits behind the base. Unknown state (compare lookup failed) fails closed:
210+
* an unverifiable claim is a violation, because an attestation must not ride
211+
* on missing evidence.
210212
*/
211213
function readinessClaimViolations({
212-
ciGreen,
213214
behindBase,
214215
behindUnknown = false,
215216
behindMax = READINESS_LATEST_DEV_BEHIND_MAX
216217
}) {
217218
const violations = [];
218-
if (!ciGreen) {
219-
violations.push("ci_green");
220-
}
221219
if (behindUnknown || behindBase > behindMax) {
222220
violations.push("latest_dev");
223221
}

0 commit comments

Comments
 (0)