diff --git a/.github/workflows/fleet-write.yml b/.github/workflows/fleet-write.yml index d96f6a8df15..af0e0572dac 100644 --- a/.github/workflows/fleet-write.yml +++ b/.github/workflows/fleet-write.yml @@ -32,7 +32,8 @@ # workflow file requires, and the `metadata: read` the sender gate's permission read needs; # plus, for a `workflow_dispatch` stroke ALONE (and the one other row that # spends it), the `actions: write` the dispatch endpoint needs, and for an -# advisory stroke alone the `repository-advisories: write` its row spends — +# advisory stroke alone the `repository-advisories: write` its row spends, +# and for a `dependabot_list` stroke alone the `vulnerability-alerts: read` it reads with — # each minted from the validator's per-stroke output, so every other run's # token is exactly the five grants above) # — and revoked by that action's post step. The workflow's own `GITHUB_TOKEN` gets nothing @@ -183,6 +184,16 @@ jobs: # NOT MEASURED either: the one live stroke carried the grant (`scripts/pm/fleet-write/ops.mjs`, "The one # row that takes a pull OUT of the merge queue"). permission-merge-queues: ${{ steps.validate.outputs.permission_merge_queues }} + # ONE consumer: the `dependabot_list` row — one walk of the repository's open Dependabot alerts (its path is + # spelled in `ops.mjs` alone), READ only and written nowhere: its answer is projected to a few fields and sealed to the + # seat's one-time key, the same path as `advisory_list` (`scripts/pm/fleet-write/dependabot.mjs`). Minted + # ONLY for a stroke carrying that op, which travels alone, the same way as `permission-actions`: the + # validator writes `permission_vulnerability_alerts=read` for it and an EMPTY value for every other stroke, + # so every other run's token is exactly what it was. The input is declared by the action's `action.yml` at + # the v3 tag (no "Unexpected input" warning). The App must request "Dependabot alerts: Read" and the + # installation accept it (a maintainer's setting); without it this mint fails with zero writes. Whether the + # narrowed token reads the list is NOT MEASURED until the first live stroke. + permission-vulnerability-alerts: ${{ steps.validate.outputs.permission_vulnerability_alerts }} # The sender gate, then the actions in order, then the step summary — # request id · sender and role · session · target · one row per request. diff --git a/scripts/pm/fleet-write/dependabot.mjs b/scripts/pm/fleet-write/dependabot.mjs new file mode 100644 index 00000000000..32a11a97286 --- /dev/null +++ b/scripts/pm/fleet-write/dependabot.mjs @@ -0,0 +1,409 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * fleet-write/dependabot — the relay's one row that LISTS a repository's open Dependabot alerts, `dependabot_list`. + * + * The table row, its grant, its gate, its one page path and the family refusing every other `dependabot` path live in + * `ops.mjs` (header: "The one row that LISTS Dependabot alerts"); the executor calls `dependabotListAction` and the + * seat opens the answer on the sealed-read path the table derives for every row requiring a `public_key` + * (`dispatch.mjs`, `ADVISORY_READ_OPS`). Everything else of the row is spelled here, once: the walk, the cursor, the + * fences, the projection, the pad and every sentence the run prints. It is a module of its own because the four + * relay files are each far over a thousand lines and this is a new row; it imports `ops.mjs` and nothing imports it + * back from there. + * + * ## Why, and what crosses + * + * A seat's session token answers 403 on `GET /repos/{repo}/dependabot/alerts`, so the alert list was invisible to the + * fleet. The maintainer's word, verbatim as the body of issue 39686 records it: 「立卡派发处理 长期办法:让车队中继能读。」 + * An alert names an unfixed weakness in a public repository, so the listing gets `advisory_list`'s treatment end to + * end: the op travels alone, nothing is written, the answer is projected to a few fields and sealed to the seat's + * one-time key, and nothing of it reaches a log line, a row, the step summary or an annotation but the ciphertext. + * + * row request the payload carries + * `dependabot_list` `GET …/dependabot/alerts?state=open&per_page=100[&after=C]`, and at most one `GET /repos/{repo}` `public_key` alone + * + * ⛔ What crosses the public run: that the listing landed or failed, the HTTP status, `dependabotListCall` (the call + * with its one state, never a cursor), the padded ciphertext and, on a refused next link, that link's shape. NEVER an + * alert number, a package, a manifest, a severity, an advisory id, a count, a cursor, a page number, or a byte or part + * count of the listing. + * + * ## The endpoint — read, not assumed + * + * GitHub's REST description (`github/rest-api-description` at cc4c0f2e, read 2026-12-04, operation + * `dependabot/list-alerts-for-repo`) gives the endpoint `state` (a comma list of `auto_dismissed`, `dismissed`, + * `fixed`, `open`), `per_page` (at most 100), `before` and `after` (cursors "as given in the Link header"), the + * filters `severity`, `ecosystem`, `package`, `manifest`, `scope` and the like, and NO `page`: it pages by cursor + * alone. The row asks `state=open&per_page=100` and nothing else; the caller names no state and no query. The answer + * is a list of `dependabot-alert`: `number` (an integer), `state`, `dependency` (`package` with `ecosystem` and + * `name`, `manifest_path`, and `scope` — `development`, `runtime` or null, and not among the schema's required keys), + * `security_vulnerability` (`severity` one of four, `vulnerable_version_range`, `first_patched_version` null or + * `{ identifier }`) and `security_advisory` (its `ghsa_id`, beside the summary, description, CVSS and references the + * projection drops). + * + * GitHub's permission ledger for server-to-server tokens (`github/docs` at 721ef837, read 2026-12-04, + * `src/github-apps/data/fpt-2022-11-28/server-to-server-permissions.json`) lists + * `list-dependabot-alerts-for-a-repository` under `vulnerability_alerts` ("Dependabot alerts") at `read`, + * server-to-server, no additional permission. The mint action pinned by the workflow, + * `actions/create-github-app-token@v3` (the tag at f418cff3, read 2026-12-04), DECLARES the input + * `permission-vulnerability-alerts` in its `action.yml` ("The level of permission to grant the access token to manage + * Dependabot alerts") and its `lib/get-permissions-from-inputs.js` turns every non-empty `INPUT_PERMISSION-*` into + * `{ vulnerability_alerts: … }` and skips an empty one — so, unlike `permission-repository-advisories`, this input + * draws no "Unexpected input" warning, and an empty value leaves every other stroke's token as it was. + * + * NOT MEASURED until the first live run, which is the seat's after the maintainer's grant (the fleet App requests + * "Dependabot alerts: Read" and the installation accepts it; until then the mint fails loudly with zero writes): that + * the App's token reads the list, and the exact shape of this endpoint's `Link` header. The walk follows the shape + * the advisory listing measured (below) and fails closed, printing a refused link's SHAPE, on anything else. + * + * ## The walk — one state, the platform's cursor, a page cap + * + * One walk of the open alerts (`dependabotListPagePath`, in `DEPENDABOT_LIST_PAGE_PATH_SHAPE`), at + * `DEPENDABOT_LIST_PAGE_SIZE` a page. It ends on a short page, or on a full page whose `Link` names no `rel="next"`; + * a short page whose `Link` still names one is FAILED (`DEPENDABOT_LIST_SHORT_PAGE_NEXT`). On a full page that names + * one it takes that link's `after` cursor and nothing else, and only when the link's origin is the relay's API, its + * path is this collection — `/repos/{repo}/dependabot/alerts`, or `/repositories/{id}/dependabot/alerts` with `{id}` + * the repository's own id, read ONCE with `GET /repos/{repo}` (`advisoryListRepoIdOf`) and ⛔ never taken from the + * link — its one `state` is `open` and its one `after` is in `ADVISORY_LIST_CURSOR_SHAPE` (`dependabotListNextCursor`). + * The next path is the relay's own spelling with that cursor, never the link. A refused link prints its shape beside + * the fixed sentence (`dependabotListLinkShape`) — ⛔ never a host, id, state, cursor or any other value. A walk still + * pending after `DEPENDABOT_LIST_PAGE_CAP` pages is FAILED: a truncated listing is a SUBSET, never an answer. + * + * ## The fences, the projection, the pad + * + * Each page must answer 200 with a list whose every item is an object carrying a positive integer `number` and + * `state` `open` (`dependabotListPageFailure`); then each projected field must hold its declared shape + * (`DEPENDABOT_LIST_FIELD_SHAPES`), so nothing but those values is ever sealed: `severity` one of the platform's four; + * `ecosystem`, `package`, `manifest_path` and `vulnerable_version_range` non-empty strings under their byte caps + * (`DEPENDABOT_LIST_STRING_CAPS`, which also bound one alert's size); `scope` `development`, `runtime`, null or + * absent; `first_patched_version` null or an object whose `identifier` is such a string; `ghsa_id` in `GHSA_ID_SHAPE`. + * A refusal names the failing fields and never a value (`dependabotListFieldSentence`); an alert listed twice is + * FAILED (`DEPENDABOT_LIST_REPEATED`). In each, nothing is sealed or emitted. + * + * Projected BEFORE the seal: each alert crosses as `DEPENDABOT_LIST_FIELDS` — its number, state, severity, the + * package's ecosystem and name, the manifest path, the scope, the vulnerable range, the first patched version (its + * identifier, or null) and the advisory's GHSA id — and nothing else, not even as ciphertext: no summary, description, + * CVSS, reference, URL, dismissal or assignee (`dependabotListPlaintext`: `{ count, alerts }` in the order walked). The + * JSON is padded with trailing spaces to exactly `ADVISORY_LIST_PADDED_BYTES` (`advisoryListPadded`, the advisory + * listing's channel size), so every sealed listing is `ADVISORY_READ_MAX_SEALED_CHARS` characters in + * `ADVISORY_READ_MAX_PARTS` parts and its length says nothing of the count. A listing over it is FAILED with nothing + * emitted (`DEPENDABOT_LIST_OVER_CAP`), ⛔ never a cut list. + * + * Sealed with `sealAdvisoryRead` to the action's `public_key` under `advisorySealAad`'s spelling for this op, emitted + * as notice parts titled `fleet-write dependabot_list`, which the seat reassembles, opens and prints on `--reveal` + * alone, its pad trimmed for that display only. It writes nothing, so opening the parts IS its read-back. + * + * The grant and the gate: `vulnerability-alerts` at `read`, minted for this stroke alone; the stroke's `target-write` + * sender gate, and the row's `senderGate` judged again before the first GET, any value but `target-write` refused with + * nothing read (`DEPENDABOT_LIST_SENDER_REFUSED`). A refused page is a FAILED action carrying + * `DEPENDABOT_LIST_ACCESS_REMEDY`, ⛔ never a retry under a wider token. + */ + +import { + ADVISORY_LIST_CURSOR_MAX_CHARS, + ADVISORY_LIST_CURSOR_SHAPE, + ADVISORY_READ_MAX_PARTS, + ADVISORY_READ_MAX_SEALED_CHARS, + ADVISORY_READ_SEAL_FAILED, + ADVISORY_READ_SENDER_GATES, + ADVISORY_READ_UNREACHED_STATUS, + ADVISORY_LIST_PADDED_BYTES, + DEPENDABOT_LIST_PAGE_SIZE, + DEPENDABOT_LIST_STATE, + GHSA_ID_SHAPE, + OPS, + advisoryListNextLinks, + advisoryListPadded, + advisoryListRepoIdOf, + advisoryListRepoIdUnreadText, + advisoryPlatformText, + advisoryReadParts, + advisorySealAad, + sealAdvisoryRead, +} from './ops.mjs'; + +/** The op this module serves — the table's row name, spelled once here. */ +export const DEPENDABOT_LIST_OP = 'dependabot_list'; +/** The most pages the walk reads: a walk still pending after this is FAILED, never a truncated answer. */ +export const DEPENDABOT_LIST_PAGE_CAP = 3; +/** The fields of each listed alert that cross, projected BEFORE the seal, in this order — nothing else. */ +export const DEPENDABOT_LIST_FIELDS = Object.freeze(['number', 'state', 'severity', 'ecosystem', 'package', 'manifest_path', 'scope', 'vulnerable_version_range', 'first_patched_version', 'ghsa_id']); +/** The severities an alert's vulnerability may carry — the platform's own enum for the field. */ +export const DEPENDABOT_LIST_SEVERITIES = Object.freeze(['critical', 'high', 'medium', 'low']); +/** The scopes a dependency may carry beside null — the platform's own enum for the field. */ +export const DEPENDABOT_LIST_SCOPES = Object.freeze(['development', 'runtime']); +/** The byte cap of each free-text field that crosses — each also bounds one alert's share of the channel. */ +export const DEPENDABOT_LIST_STRING_CAPS = Object.freeze({ ecosystem: 64, package: 256, manifest_path: 512, vulnerable_version_range: 256, first_patched_version: 128 }); + +/** The path of one listing page: the open state, the page size and, after the first page, the cursor. Pure. */ +export function dependabotListPagePath(repo, after = null) { + return `/repos/${repo}/dependabot/alerts?state=${DEPENDABOT_LIST_STATE}&per_page=${DEPENDABOT_LIST_PAGE_SIZE}${after === null ? '' : `&after=${encodeURIComponent(after)}`}`; +} + +/** The call the row and the log print — its one state, ⛔ never a cursor. Pure. */ +export function dependabotListCall(repo) { + return `GET /repos/${repo}/dependabot/alerts?state=${DEPENDABOT_LIST_STATE}&per_page=${DEPENDABOT_LIST_PAGE_SIZE}`; +} + +/** The collection a next link may name by the repository's NUMERIC id, followed only when it is the repository's own. */ +export const DEPENDABOT_LIST_NUMERIC_COLLECTION_SHAPE = /^\/repositories\/([1-9][0-9]{0,19})\/dependabot\/alerts$/; + +/** Why a `Link` header gives the walk no cursor it may follow — one sentence, ⛔ never the link or the cursor. */ +export const DEPENDABOT_LIST_CURSOR_REFUSED = + "a full page's Link header names a next page the relay does not follow — not exactly one rel=\"next\" link, or one off this API's " + + 'alerts collection or its one state, or a cursor that is not exactly one value in its declared shape — so nothing was sealed or emitted'; + +/** + * The next cursor of a page (header: "The walk"): `{ after }` — `null` when the `Link` header names no `rel="next"` — + * or `{ fail }` with `DEPENDABOT_LIST_CURSOR_REFUSED`, or `{ needsRepoId: true }` when the one next link names the + * collection by a numeric id and `repoId` was not given. Other query parameters of the link are never read. Pure; + * never throws. + */ +export function dependabotListNextCursor(link, { api, repo, repoId = null }) { + const nexts = advisoryListNextLinks(link); + if (nexts === null || nexts.length > 1) return { fail: DEPENDABOT_LIST_CURSOR_REFUSED }; + if (nexts.length === 0) return { after: null }; + let url; + let base; + try { + url = new URL(nexts[0]); + base = new URL(api); + } catch { + return { fail: DEPENDABOT_LIST_CURSOR_REFUSED }; + } + if (url.origin !== base.origin) return { fail: DEPENDABOT_LIST_CURSOR_REFUSED }; + const states = url.searchParams.getAll('state'); + const afters = url.searchParams.getAll('after'); + if (states.length !== 1 || states[0] !== DEPENDABOT_LIST_STATE || afters.length !== 1 || !ADVISORY_LIST_CURSOR_SHAPE.test(afters[0])) return { fail: DEPENDABOT_LIST_CURSOR_REFUSED }; + if (url.pathname === `/repos/${repo}/dependabot/alerts`) return { after: afters[0] }; + const numeric = DEPENDABOT_LIST_NUMERIC_COLLECTION_SHAPE.exec(url.pathname); + if (!numeric) return { fail: DEPENDABOT_LIST_CURSOR_REFUSED }; + if (repoId === null || repoId === undefined) return { needsRepoId: true }; + return String(repoId) === numeric[1] ? { after: afters[0] } : { fail: DEPENDABOT_LIST_CURSOR_REFUSED }; +} + +/** The path segments a refused link's shape prints as they are; every other segment prints as a placeholder. */ +const SHAPE_WORDS = Object.freeze(['repos', 'repositories', 'dependabot', 'alerts']); + +/** + * The diagnostic a refused next link prints (header: "The walk"): its SHAPE alone — how many next links, the origin as + * the relay's or another, the path with the owner, the name and every id replaced by a placeholder (and whether they + * are this repository's), the query parameter NAMES, and of `state` and `after` only how each stands. ⛔ No host, + * owner, name, id, state, cursor or other value is ever printed. Pure; never throws. + */ +export function dependabotListLinkShape(link, { api, repo, repoId = null }) { + const nexts = advisoryListNextLinks(link); + if (nexts === null) return 'link shape: the Link header is no string'; + if (nexts.length === 0) return 'link shape: no rel="next" link'; + const parts = [`${nexts.length} rel="next" link(s)`]; + let url; + let base; + try { + url = new URL(nexts[0]); + base = new URL(api); + } catch { + return `link shape: ${parts[0]}; the first is no absolute URL`; + } + parts.push(url.origin === base.origin ? "on the relay's API origin" : 'on another origin'); + const segs = url.pathname.split('/').slice(1); + const [own0, own1] = String(repo).split('/'); + const shown = []; + let note = ''; + for (let k = 0; k < segs.length; k++) { + const seg = segs[k]; + if (k === 1 && segs[0] === 'repos' && segs.length > 2) { + shown.push('OWNER', 'NAME'); + const same = seg === own0 && segs[2] === own1; + const folded = !same && seg.toLowerCase() === String(own0).toLowerCase() && segs[2].toLowerCase() === String(own1).toLowerCase(); + note = same ? ' (OWNER/NAME this repository)' : folded ? ' (OWNER/NAME this repository in another letter case)' : ' (OWNER/NAME another repository)'; + k++; + } else if (k === 1 && segs[0] === 'repositories') { + shown.push('ID'); + note = !/^[1-9][0-9]{0,19}$/.test(seg) ? ' (ID not a repository id)' : repoId === null || repoId === undefined ? ' (ID not compared: the repository id was not read)' : String(repoId) === seg ? " (ID this repository's)" : " (ID another repository's)"; + } else if (SHAPE_WORDS.includes(seg) || seg === '') shown.push(seg); + else shown.push(/^[0-9]+$/.test(seg) ? 'N' : 'SEG'); + } + parts.push(`path /${shown.join('/')}${note}`); + parts.push(`query names [${[...url.searchParams.keys()].map((n) => (/^[a-z_]{1,32}$/.test(n) ? n : 'NAME')).join(',')}]`); + const states = url.searchParams.getAll('state'); + parts.push(`state ${states.length === 0 ? 'absent' : states.length > 1 ? `${states.length} values` : states[0] === DEPENDABOT_LIST_STATE ? "the walk's" : "not the walk's"}`); + const afters = url.searchParams.getAll('after'); + const cursor = (c) => (ADVISORY_LIST_CURSOR_SHAPE.test(c) ? 'in its shape' : c.length > ADVISORY_LIST_CURSOR_MAX_CHARS ? 'over its length cap' : c.length === 0 ? 'empty' : 'with a character outside its alphabet'); + parts.push(`after ${afters.length === 0 ? 'absent' : afters.length > 1 ? `${afters.length} values` : cursor(afters[0])}`); + return `link shape: ${parts.join('; ')}`; +} + +const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v); +/** The value at a path of nested objects, or `undefined` when any step is no object or lacks the key. Pure. */ +const at = (v, ...keys) => { + let cur = v; + for (const k of keys) { + if (!isObject(cur) || !Object.hasOwn(cur, k)) return undefined; + cur = cur[k]; + } + return cur; +}; +const capped = (field) => (v) => typeof v === 'string' && v.length > 0 && Buffer.byteLength(v, 'utf8') <= DEPENDABOT_LIST_STRING_CAPS[field]; + +/** + * The projected fields the page fence judges past the number and the state, in the order a refusal names them: each + * with where it is read on the platform's alert (`read`), what crosses (`cross`, absent for a value the alert lacks) + * and its declared shape (`holds`, over the value read). Frozen. + */ +export const DEPENDABOT_LIST_FIELD_SHAPES = Object.freeze([ + Object.freeze({ field: 'severity', read: (a) => at(a, 'security_vulnerability', 'severity'), holds: (v) => DEPENDABOT_LIST_SEVERITIES.includes(v) }), + Object.freeze({ field: 'ecosystem', read: (a) => at(a, 'dependency', 'package', 'ecosystem'), holds: capped('ecosystem') }), + Object.freeze({ field: 'package', read: (a) => at(a, 'dependency', 'package', 'name'), holds: capped('package') }), + Object.freeze({ field: 'manifest_path', read: (a) => at(a, 'dependency', 'manifest_path'), holds: capped('manifest_path') }), + // The one field the platform's schema does not require: absent is admitted, and the projection leaves it absent. + Object.freeze({ field: 'scope', read: (a) => at(a, 'dependency', 'scope'), holds: (v) => v === undefined || v === null || DEPENDABOT_LIST_SCOPES.includes(v) }), + Object.freeze({ field: 'vulnerable_version_range', read: (a) => at(a, 'security_vulnerability', 'vulnerable_version_range'), holds: capped('vulnerable_version_range') }), + Object.freeze({ + field: 'first_patched_version', + read: (a) => at(a, 'security_vulnerability', 'first_patched_version'), + holds: (v) => v === null || (isObject(v) && capped('first_patched_version')(v.identifier)), + cross: (v) => (v === null ? null : v.identifier), + }), + Object.freeze({ field: 'ghsa_id', read: (a) => at(a, 'security_advisory', 'ghsa_id'), holds: (v) => typeof v === 'string' && GHSA_ID_SHAPE.test(v) }), +]); + +/** The refusal of a page whose alerts carry a field off its declared shape: the fields by NAME, ⛔ never a value. Pure. */ +export function dependabotListFieldSentence(fields) { + const names = fields.length > 1 ? `${fields.slice(0, -1).join(', ')} and ${fields[fields.length - 1]}` : fields[0]; + return `a page of the listing lists an alert whose ${names} ${fields.length > 1 ? "are not of the fields' declared shapes" : "is not of the field's declared shape"}`; +} + +/** + * Why one listing page fails its fences, or null when it holds (header: "The fences"): 200, a list, every item an + * object with a positive integer `number` in the `open` state, then every field of `DEPENDABOT_LIST_FIELD_SHAPES` + * holding its shape. ⛔ The sentence carries the status, or the failing fields' names, alone. Pure. + */ +export function dependabotListPageFailure(answer) { + if (answer?.status !== 200) return `a page of the listing answered HTTP ${answer?.status ?? 'none'}`; + if (!Array.isArray(answer.json)) return 'a page of the listing answered HTTP 200 with no list'; + if (!answer.json.every((a) => isObject(a) && Number.isSafeInteger(a.number) && a.number > 0 && a.state === DEPENDABOT_LIST_STATE)) { + return 'a page of the listing lists an item that is not an alert in the state the page asked for'; + } + const failed = DEPENDABOT_LIST_FIELD_SHAPES.filter(({ read, holds }) => !answer.json.every((a) => holds(read(a)))).map(({ field }) => field); + return failed.length === 0 ? null : dependabotListFieldSentence(failed); +} + +/** One listed alert as it crosses: `DEPENDABOT_LIST_FIELDS`, in that order — a fenced alert's values alone. Pure. */ +export function dependabotListProjection(alert) { + const out = { number: alert.number, state: alert.state }; + for (const { field, read, cross } of DEPENDABOT_LIST_FIELD_SHAPES) { + const v = read(alert); + if (v !== undefined) out[field] = cross ? cross(v) : v; + } + return out; +} + +/** What is sealed, before its pad: `{ count, alerts }` — each alert projected, in the order walked. Pure. */ +export function dependabotListPlaintext(alerts) { + return JSON.stringify({ count: alerts.length, alerts: alerts.map(dependabotListProjection) }); +} + +/** The exact plaintext size of every sealed listing — the advisory listing's, the run's full notice size. */ +export const DEPENDABOT_LIST_PADDED_BYTES = ADVISORY_LIST_PADDED_BYTES; + +/** What a refused page prints after its status: the grant is the first live run's to measure, ⛔ never widened by hand. */ +export const DEPENDABOT_LIST_ACCESS_REMEDY = + 'the relay token carries vulnerability-alerts READ (the App permission "Dependabot alerts") for this stroke alone — GitHub\'s ' + + "permission ledger lists this listing under it, and the first live run measures it; a refusal may also mean the repository's " + + 'Dependabot alerts are off — put this reading to the maintainer, ⛔ never re-send it under a wider or un-narrowed token'; + +/** What a listing whose row names an unknown sender gate prints: refused before any request. */ +export const DEPENDABOT_LIST_SENDER_REFUSED = + 'REFUSED before any request: the row names no sender gate the table knows, so nothing was read, sealed or emitted'; + +/** What a listing whose GET never reached the platform prints — ⛔ never the exception's message, which carries the path. */ +export const DEPENDABOT_LIST_UNREACHED = + "REFUSED: a page of the listing did not reach the platform (the runner's call threw before any answer), so nothing was sealed or " + + 'emitted — re-send the listing with a fresh key'; + +/** What a walk that hit its page cap prints: no count. */ +export const DEPENDABOT_LIST_CAP_HIT = + `the walk reached its ${DEPENDABOT_LIST_PAGE_CAP}-page cap with more pending — a truncated listing is a SUBSET, so nothing was sealed or ` + + 'emitted; put the reading to the maintainer'; + +/** What a walk prints when a short page still names a next page. */ +export const DEPENDABOT_LIST_SHORT_PAGE_NEXT = + 'a short page of the listing still names a next page, so the walk cannot end there — nothing was sealed or emitted'; + +/** What a walk that met one alert twice prints: the cursor did not advance cleanly. */ +export const DEPENDABOT_LIST_REPEATED = 'one alert appears twice across the pages, so the walk is not one listing — nothing was sealed or emitted'; + +/** What a listing too large for the channel prints: the cap, and ⛔ nothing of the listing. */ +export const DEPENDABOT_LIST_OVER_CAP = + `the projected listing is over the ${DEPENDABOT_LIST_PADDED_BYTES} bytes the run's ${ADVISORY_READ_MAX_PARTS} notices carry — nothing was ` + + 'emitted; ⛔ the listing never leaves cut or another way, put the reading to the maintainer'; + +/** The row a landed listing prints — ⛔ no number, no count, no byte or part count. */ +export const DEPENDABOT_LIST_LANDED = + "sealed the Dependabot alerts listing to the seat's one-time key, padded to the run's full notice size so its length says nothing — only that seat's process opens it"; + +/** + * The listing (header): the gate, the walk, the fences, the projection, the pad, the seal and the parts. Returns + * `{ ok, status, result, why, notes }` in the executor's read shape — `notes` the notice parts, `{ action, op, part, + * of, sealed }` each, on a landing alone. `rest` is the executor's transport, handed in; `seal` and `senderGate` are + * the self-test's doors, the CLI passes neither. ⛔ No string it returns carries a number, a count, a field's value, a + * cursor or a page number. Never throws. + */ +export async function dependabotListAction(req, { payload, index, api, t, rest, seal = sealAdvisoryRead, senderGate = OPS[DEPENDABOT_LIST_OP].senderGate }) { + const { publicKey } = req.dependabotList; + // The gate is judged BEFORE the first GET: `target-write` was the stroke's, every other value is closed. + if (!Object.hasOwn(ADVISORY_READ_SENDER_GATES, senderGate) || senderGate !== 'target-write') return { ok: false, status: 'not sent', why: DEPENDABOT_LIST_SENDER_REFUSED, notes: [] }; + const alerts = []; + const seen = new Set(); + let status = null; + let repoId = null; + let after = null; + let ended = false; + for (let page = 1; page <= DEPENDABOT_LIST_PAGE_CAP && !ended; page++) { + const r = await rest(api, dependabotListPagePath(payload.repo, after), { method: 'GET' }, t); + // Status 0 is `rest`'s word for a call that threw: ⛔ never its message, which carries the path and so a cursor. + if (r.status === 0) return { ok: false, status: ADVISORY_READ_UNREACHED_STATUS, why: DEPENDABOT_LIST_UNREACHED, notes: [] }; + status = r.status; + const failed = dependabotListPageFailure(r); + if (failed) { + const refused = !(r.status >= 200 && r.status < 300); + return { ok: false, status: r.status, why: `REFUSED at the relay's fence on the listing, nothing sealed or emitted — ${failed}${refused ? `${advisoryPlatformText(r.detail)}; ${DEPENDABOT_LIST_ACCESS_REMEDY}` : ''}`, notes: [] }; + } + for (const alert of r.json) { + if (seen.has(alert.number)) return { ok: false, status: r.status, why: DEPENDABOT_LIST_REPEATED, notes: [] }; + seen.add(alert.number); + alerts.push(alert); + } + let next = dependabotListNextCursor(r.link ?? null, { api, repo: payload.repo, repoId }); + if (next.needsRepoId) { + // The link names the collection by a numeric id: read the repository's own id ONCE, never trust the link's. + const own = await rest(api, `/repos/${payload.repo}`, { method: 'GET' }, t); + if (own.status === 0) return { ok: false, status: ADVISORY_READ_UNREACHED_STATUS, why: DEPENDABOT_LIST_UNREACHED, notes: [] }; + repoId = advisoryListRepoIdOf(own, payload.repo); + if (repoId === null) return { ok: false, status: own.status, why: advisoryListRepoIdUnreadText(own.status), notes: [] }; + next = dependabotListNextCursor(r.link ?? null, { api, repo: payload.repo, repoId }); + } + if (next.fail) return { ok: false, status: r.status, why: `${next.fail}; ${dependabotListLinkShape(r.link ?? null, { api, repo: payload.repo, repoId })}`, notes: [] }; + if (r.json.length < DEPENDABOT_LIST_PAGE_SIZE) { + if (next.after !== null) return { ok: false, status: r.status, why: DEPENDABOT_LIST_SHORT_PAGE_NEXT, notes: [] }; + ended = true; + break; + } + if (next.after === null) ended = true; + else after = next.after; + } + if (!ended) return { ok: false, status, why: DEPENDABOT_LIST_CAP_HIT, notes: [] }; + const padded = advisoryListPadded(dependabotListPlaintext(alerts)); + if (padded === null) return { ok: false, status, why: DEPENDABOT_LIST_OVER_CAP, notes: [] }; + let sealed; + try { + sealed = seal({ plaintext: padded, publicKey, aad: advisorySealAad({ requestId: payload.request_id, action: index, op: DEPENDABOT_LIST_OP }) }); + } catch { + return { ok: false, status, why: ADVISORY_READ_SEAL_FAILED, notes: [] }; + } + // A sealed listing is exactly the channel's size, so its length says nothing; anything else is a seal that failed. + if (typeof sealed !== 'string' || !/^[A-Za-z0-9_-]+$/.test(sealed) || sealed.length !== ADVISORY_READ_MAX_SEALED_CHARS) return { ok: false, status, why: ADVISORY_READ_SEAL_FAILED, notes: [] }; + const parts = advisoryReadParts(sealed); + if (!parts || parts.length !== ADVISORY_READ_MAX_PARTS) return { ok: false, status, why: ADVISORY_READ_SEAL_FAILED, notes: [] }; + const notes = parts.map((chunk, k) => ({ action: index, op: DEPENDABOT_LIST_OP, part: k + 1, of: parts.length, sealed: chunk })); + return { ok: true, status, result: DEPENDABOT_LIST_LANDED, notes }; +} diff --git a/scripts/pm/fleet-write/dispatch.mjs b/scripts/pm/fleet-write/dispatch.mjs index d2ae07d96e2..2744eb6c0c1 100644 --- a/scripts/pm/fleet-write/dispatch.mjs +++ b/scripts/pm/fleet-write/dispatch.mjs @@ -337,6 +337,10 @@ * padded listing (`ops.mjs`, "The one row that LISTS advisories"); the * open stays byte for byte on it, and `--reveal` alone prints it with its * padding trimmed (`advisoryListDisplay`), that op's display alone; + * - `dependabot_list` is the same path again, derived the same way: its + * plaintext is the padded listing of the repository's open Dependabot + * alerts (`dependabot.mjs`), sealed under its own op's associated data, + * and `--reveal` prints it with the listing's display, the pad trimmed; * - `advisory_note` travels the other way and has NO byte read-back here * either: the seat cannot read the advisory it appends to. This file reads * the note from the file `note_file` names, composes its section — the @@ -1384,6 +1388,7 @@ export const RUN_READ_BACK_WINDOW_MS = 60_000; // read-back is the seat opening the sealed answer the run's notices carry with the key only this process holds // (`openRunAdvisoryReads`); an answer that does not open is `unverified` (header, "How the callers"). // ⛔ Nor for `advisory_list`, the same shape: it writes nothing; opening its sealed listing is its read-back. +// ⛔ Nor for `dependabot_list`, the same shape again: it writes nothing; opening its sealed listing is its read-back. // ⛔ No locator for `advisory_report`, on purpose — nor for `advisory_create`, the same shape: its prose rides `summary` // and `description`, never `body`, so it is not in `BODY_OPS`, and a byte-for-byte read-back cannot apply to it — the seat cannot read a private report before it // is a collaborator, and the executor must not print the answer that holds the stored bytes. Its confirmation is the @@ -2792,6 +2797,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ "retired lane aliases at the seat's door: a domain:engine / services / cli / rest label on labels_add, issue_create or pr_create is written as domain:server and said on stderr, a dry run included; a live domain:* label, a non-lane label and labels_remove pass untouched; the rewrite never refuses": 13, "advisory_read at the seat: the key pair made in this process per read — its public half in the action, its private half a KeyObject never exported, written or printed, and a key from the file refused; no byte read-back, said where the read-back is decided; the run's notice parts read back exactly, reassembled 1..n once each and opened with that key byte for byte, end to end through the real executor; what does not open is UNVERIFIED (6) with nothing printed; the text reaches this process's stdout on --reveal alone, never stderr or --json": 17, "advisory_list at the seat: derived from the table into the sealed-read path, so its key pair is made here and a key from the file refused, with no byte read-back, said where the read-back is decided; the real executor's ten notice parts read back, reassembled and opened under the listing's own associated data — never a read's — byte for byte on the padded plaintext; what does not open is UNVERIFIED (6) with nothing printed; --reveal alone prints it, its pad trimmed for that op's display alone, never on stderr or --json": 9, + "dependabot_list at the seat: derived from the table into the sealed-read path, so its key pair is made here and a key from the file refused, with no byte read-back, said where the read-back is decided; the real executor's ten notice parts read back, reassembled and opened under the listing's own associated data — never the advisory listing's — byte for byte on the padded plaintext; what does not open is UNVERIFIED (6) with nothing printed; --reveal alone prints it, its pad trimmed, never on stderr or --json": 8, "advisory_note at the seat: the note read from the file note_file names, composed under the seat's signature line and this door's own stamp, judged, then sealed HERE with a one-time digest key to the relay's committed half under the stroke's request id — the payload carrying the seal alone; a seal from the file, a file inside any git repository, and a missing, unreadable or unjudged one refused and a null committed half a prerequisite, all before anything is sent; the run's ONE notice confirmed against the byte count and keyed digest only this process holds, anything else UNVERIFIED, exit 6 — and no byte of the note on any line the seat prints": 23, "advisory_rewrite at the seat: the summary and/or description read from the files summary_file and description_file name, each placed outside every git repository by the note's own check, spelled as one JSON object with no signature or stamp and judged — an empty description refused — then sealed HERE through the note's path with a one-time digest key under the rewrite's own associated data, the payload carrying the seal alone; the real executor's ONE notice confirmed against that digest, a mismatch UNVERIFIED, exit 6 — and no byte of either text on any line the seat prints": 12, }); @@ -2799,8 +2805,8 @@ const SELF_TEST_BATTERIES = Object.freeze({ // hierarchy link seat battery, 24 → 25 with the pull request body battery, 25 → 26 with the advisory rows' seat // battery, 26 → 27 with advisory_read's seat battery, 27 → 28 with the retired lane aliases battery, 29 → 30 with // advisory_list's seat battery, 30 → 31 with advisory_note's seat battery, 32 → 33 with the record tier's seat -// battery: one battery, one row; 33 → 34 with advisory_rewrite's seat battery. -const SELF_TEST_BATTERY_FLOOR = 34; +// battery: one battery, one row; 33 → 34 with advisory_rewrite's seat battery; 34 → 35 with dependabot_list's. +const SELF_TEST_BATTERY_FLOOR = 35; const UNATTRIBUTED_BATTERY = '(unattributed)'; const REWRITE_SEAT_BATTERY = "advisory_rewrite at the seat: the summary and/or description read from the files summary_file and description_file name, each placed outside every git repository by the note's own check, spelled as one JSON object with no signature or stamp and judged — an empty description refused — then sealed HERE through the note's path with a one-time digest key under the rewrite's own associated data, the payload carrying the seal alone; the real executor's ONE notice confirmed against that digest, a mismatch UNVERIFIED, exit 6 — and no byte of either text on any line the seat prints"; @@ -3755,7 +3761,7 @@ export async function selfTest() { t("⛔ a public_key already in the actions file is REFUSED, never used — a key made elsewhere means a private key kept elsewhere — and the refusal never echoes it", [supplied.refused.length, supplied.keys.size, supplied.refused[0]?.includes('actions[0].public_key is set in the actions file'), supplied.refused.some((l) => l.includes('ADVISORY MARKER'))], [1, 0, true, false]); // Derived from the table. const stroke = packRequest({ repo: REPO, session: SESSION, actions: [armed.actions[0]], requestId: 'fw-test-1' }).payload; - t('derived from the table: advisory_read and advisory_list are the ops whose answer comes back sealed — the read no body op, no run op, no content, no card or advisory annotation, no read-back locator or target, and ZERO writes in its stroke', [ADVISORY_READ_OPS, [BODY_OPS, RUN_OPS, CONTENT_CREATING_OPS, ADVISORY_ANNOTATED_OPS].map((list) => list.includes('advisory_read')), Object.hasOwn(ANNOTATED_OPS, 'advisory_read'), 'advisory_read' in READ_BACK_LOCATORS, readBackTargets(stroke), strokePacing(stroke).writes], [['advisory_read', 'advisory_list'], [false, false, false, false], false, false, [], 0]); + t('derived from the table: advisory_read, advisory_list and dependabot_list are the ops whose answer comes back sealed — the read no body op, no run op, no content, no card or advisory annotation, no read-back locator or target, and ZERO writes in its stroke', [ADVISORY_READ_OPS, [BODY_OPS, RUN_OPS, CONTENT_CREATING_OPS, ADVISORY_ANNOTATED_OPS].map((list) => list.includes('advisory_read')), Object.hasOwn(ANNOTATED_OPS, 'advisory_read'), 'advisory_read' in READ_BACK_LOCATORS, readBackTargets(stroke), strokePacing(stroke).writes], [['advisory_read', 'advisory_list', 'dependabot_list'], [false, false, false, false], false, false, [], 0]); const at = own.indexOf('export const READ_BACK_LOCATORS'); t("⛔ that advisory_read has NO byte read-back is said WHERE the read-back is decided, and in the header's account of the callers", [own.slice(Math.max(0, at - 1200), at).includes('No locator for `advisory_read`: it has NO byte read-back, because it writes nothing'), own.includes('`advisory_read` has NO byte read-back either, and needs none: it writes')], [true, true]); // The parts: one spelling, read back exactly. @@ -3959,6 +3965,102 @@ export async function selfTest() { t("⭐ the CLI with --reveal: THIS process's stdout is the listing's JSON with its pad trimmed — exactly the projected listing, not one trailing space — and never a stderr line", [loud.code, loud.out, advisoryListDisplay(padded) === listed, loud.errs.some((l) => l.includes(idOf(2)))], [EXIT_OK, [listed], true, false]); } + // ── dependabot_list at the seat ───────────────────────────────────────── + battery("dependabot_list at the seat: derived from the table into the sealed-read path, so its key pair is made here and a key from the file refused, with no byte read-back, said where the read-back is decided; the real executor's ten notice parts read back, reassembled and opened under the listing's own associated data — never the advisory listing's — byte for byte on the padded plaintext; what does not open is UNVERIFIED (6) with nothing printed; --reveal alone prints it, its pad trimmed, never on stderr or --json"); + { + const REPO = 'objectstack-ai/objectstack'; + const MARKER = 'DEPENDABOT MARKER: never in a seat line'; + const { executeFleetWrite } = await import('./execute.mjs'); + const { ADVISORY_READ_OPEN_FAILED, advisoryListPadded, advisoryReadParts, sealAdvisoryRead } = await import('./ops.mjs'); + const { DEPENDABOT_LIST_PADDED_BYTES, dependabotListPagePath, dependabotListPlaintext } = await import('./dependabot.mjs'); + const DL = { op: 'dependabot_list' }; + // Made-up alerts: an eight-digit number, a package and a GHSA id of their own, naming nothing real. + const pkgOf = (k) => `seat-marker-pkg-${k}`; + const alert = (k) => ({ + number: 81370000 + k, state: 'open', html_url: MARKER, + dependency: { package: { ecosystem: 'npm', name: pkgOf(k) }, manifest_path: 'pnpm-lock.yaml', scope: 'runtime' }, + security_advisory: { ghsa_id: `GHSA-${k.toString(36).padStart(4, '0')}-2345-wxyz`, summary: MARKER, description: MARKER }, + security_vulnerability: { severity: 'medium', vulnerable_version_range: '< 2.0.0', first_patched_version: { identifier: '2.0.0' } }, + }); + const listedAlerts = [alert(1), alert(2), alert(3)]; + const listed = dependabotListPlaintext(listedAlerts); + const padded = advisoryListPadded(listed); + const armed = armAdvisoryReads([DL]); + t('the key pair is made HERE for a Dependabot listing too — derived from the table, because the row requires a public_key: the listing gains a key the validator accepts, the private half a KeyObject in the map; a key from the file is refused', [ADVISORY_READ_OPS.includes('dependabot_list'), Object.keys(armed.actions[0]), validatePayload({ request_id: 'fw-test-1', repo: REPO, session: SESSION, actions: armed.actions }).ok, [...armed.keys.keys()], armed.keys.get(1)?.asymmetricKeyType, armAdvisoryReads([{ ...DL, public_key: MARKER }]).refused.length], [true, ['op', 'public_key'], true, [1], 'x25519', 1]); + const stroke = packRequest({ repo: REPO, session: SESSION, actions: armed.actions, requestId: 'fw-test-1' }).payload; + const own = readReal(SELF_PATH, 'utf8'); + const at = own.indexOf('export const READ_BACK_LOCATORS'); + t("no body op, no run op, no content, no annotation, no locator or read-back target, ZERO writes — and that it has no byte read-back is said WHERE the read-back is decided and in the header's account of the callers", [[BODY_OPS, RUN_OPS, CONTENT_CREATING_OPS, ADVISORY_ANNOTATED_OPS].map((l) => l.includes('dependabot_list')), Object.hasOwn(ANNOTATED_OPS, 'dependabot_list'), 'dependabot_list' in READ_BACK_LOCATORS, readBackTargets(stroke), strokePacing(stroke).writes, own.slice(Math.max(0, at - 1400), at).includes('Nor for `dependabot_list`, the same shape again: it writes nothing'), own.includes('`dependabot_list` is the same path again')], [[false, false, false, false], false, false, [], 0, true, true]); + t("its part is the read's one spelling under its own op, read back exactly", parseRelayAdvisoryReadAnnotation(relayAdvisoryReadAnnotationMessage({ action: 1, op: 'dependabot_list', part: 7, of: 10, sealed: 'AA' })), { action: 1, op: 'dependabot_list', part: 7, of: 10, sealed: 'AA' }); + // ⭐ End to end: the REAL executor walks, projects, pads and seals; its notices become the run's annotations. + const PERM_A = `GET /repos/${REPO}/collaborators/os-dev-a/permission`; + const executed = async (payload) => { + const lines = []; + const answers = { [PERM_A]: { status: 200, json: { permission: 'write', role_name: 'write' } }, [`GET ${dependabotListPagePath(REPO)}`]: { status: 200, json: listedAlerts } }; + const r = await executeFleetWrite({ payload, sender: 'os-dev-a', token: TOKEN }, { + fetch: async (url, init) => { + const u = new URL(url); + const a = answers[`${init?.method ?? 'GET'} ${u.pathname}${u.search}`] ?? { status: 404, json: { message: 'Not Found' } }; + return { status: a.status, headers: new Headers({ 'x-ratelimit-remaining': '4999' }), json: async () => a.json }; + }, + log: (l) => lines.push(l), + }); + const notes = lines.filter((l) => l.startsWith('::notice ')).map((l) => ({ path: '.github', annotation_level: 'notice', title: 'fleet-write dependabot_list', message: l.slice(l.indexOf('::', 2) + 2) })); + return { ...r, notes, lines }; + }; + const relayed = await executed(stroke); + const runOf = (notes, keys = armed.keys) => drive({ runs: () => [RUN('completed', 'success')], notes: () => notes }, { stroke, keys }); + const ok = await runOf({ status: 200, json: [RUNNER_NOTICE, ...relayed.notes] }); + const leaky = (l) => l.includes('DEPENDABOT MARKER') || l.includes('seat-marker-pkg-') || l.includes('8137000'); + t("⭐ END TO END — the real executor's ten parts opened by the key this process made: success, exit 0, the plaintext BYTE FOR BYTE the padded listing, its fields count and alerts, and no marker in it", [relayed.exit, relayed.notes.length, ok.state, exitForResult(ok), ok.reads?.map((r) => [r.action, r.op, r.state, r.parts, r.bytes, r.fields]), ok.reads?.[0]?.plaintext === padded, ok.reads?.[0]?.plaintext.includes('DEPENDABOT MARKER')], [EXIT_OK, 10, 'success', EXIT_OK, [[1, 'dependabot_list', 'opened', 10, DEPENDABOT_LIST_PADDED_BYTES, ['count', 'alerts']]], true, false]); + t("⛔ …and no line either side prints an alert field: the relay's job log and the seat's lines say the counts and the field names — never the marker, a package or an alert number", [ok.logs.some((l) => l.includes("action 1 dependabot_list's sealed answer in 10 part(s)") && l.includes('fields count, alerts')), [...ok.logs, ...relayed.lines.filter((l) => !l.startsWith('::notice '))].some(leaky)], [true, false]); + // ⛔ Its own associated data — never the advisory listing's. + const asAdvisoryList = (() => { + const sealed = sealAdvisoryRead({ plaintext: padded, publicKey: armed.actions[0].public_key, aad: advisorySealAad({ requestId: 'fw-test-1', action: 1, op: 'advisory_list' }) }); + return advisoryReadParts(sealed).map((chunk, k) => ({ path: '.github', annotation_level: 'notice', title: 'fleet-write dependabot_list', message: relayAdvisoryReadAnnotationMessage({ action: 1, op: 'dependabot_list', part: k + 1, of: 10, sealed: chunk }) })); + })(); + const stranger = armAdvisoryReads([DL]); + const otherSeal = await executed(packRequest({ repo: REPO, session: SESSION, actions: stranger.actions, requestId: 'fw-test-1' }).payload); + const tampered = relayed.notes.map((n, k) => (k === 6 ? { ...n, message: n.message.replace(/sealed=(.)/, (m, c) => `sealed=${c === 'A' ? 'B' : 'A'}`) } : n)); + const unread = [await runOf({ status: 200, json: asAdvisoryList }), await runOf({ status: 200, json: tampered }), await runOf({ status: 200, json: otherSeal.notes }), await runOf({ status: 200, json: relayed.notes }, new Map()), await runOf({ status: 200, json: relayed.notes.slice(1) })]; + t("⛔ UNVERIFIED, exit 6, nothing printed: the listing sealed under the ADVISORY listing's associated data, a part tampered with, parts sealed to another seat's key, no key in this process, and a part missing — the first three with the one sentence an answer that does not open earns", [unread.map((r) => [r.state, exitForResult(r), r.reads?.[0]?.state, r.reads?.[0]?.plaintext ?? null, r.logs.some(leaky)]), unread.slice(0, 3).map((r) => r.reads[0].why)], [unread.map(() => ['unverified', EXIT_UNCONFIRMED, 'unverified', null, false]), [ADVISORY_READ_OPEN_FAILED, ADVISORY_READ_OPEN_FAILED, ADVISORY_READ_OPEN_FAILED]]); + // The CLI: --reveal alone prints it, the pad trimmed. + writeFileSync(join(dir, 'dependabot-list.json'), JSON.stringify([DL]), 'utf8'); + const cli = async (args) => { + let nowMs = T0; + const clock = { now: () => nowMs, elapsed: () => nowMs - T0 }; + const seen = []; + const notes = () => { + const sent = seen.find((x) => x.call === DISPATCH)?.body?.client_payload; + const action = sent?.actions?.[0]; + if (!action?.public_key) return { status: 200, json: [] }; + const sealed = sealAdvisoryRead({ plaintext: padded, publicKey: action.public_key, aad: advisorySealAad({ requestId: sent.request_id, action: 1, op: 'dependabot_list' }) }); + return { status: 200, json: advisoryReadParts(sealed).map((chunk, k) => ({ path: '.github', annotation_level: 'notice', title: 'fleet-write dependabot_list', message: relayAdvisoryReadAnnotationMessage({ action: 1, op: 'dependabot_list', part: k + 1, of: 10, sealed: chunk }) })) }; + }; + const out = []; + const errs = []; + const [log, err] = [console.log, console.error]; + console.log = (l) => out.push(String(l)); + console.error = (l) => errs.push(String(l)); + let code; + try { + code = await main(args, { + env: { GITHUB_TOKEN: TOKEN, [SESSION_ENV]: SESSION }, + send: { fetch: platform({ runs: () => [RUN('completed', 'success')], notes }, seen, clock), pace: paceFor(join(dir, `pace-cli-${paceCase++}.jsonl`)), now: clock.now, sleep: async (ms) => { nowMs += ms; }, log: (l) => errs.push(String(l)), ceilings: { startMs: 90_000, ceilingMs: 300_000, pollMs: 5_000, notes: [] } }, + }); + } finally { + [console.log, console.error] = [log, err]; + } + return { code, out, errs, seen }; + }; + const base = ['--repo', REPO, '--actions-file', join(dir, 'dependabot-list.json'), '--request-id', 'fw-test-1']; + const quiet = await cli([...base, '--json']); + const quietJson = quiet.out.length ? JSON.parse(quiet.out[quiet.out.length - 1]) : null; + t('⛔ the CLI without --reveal: exit 0, ONE --json line whose advisory_reads carry the op, the state, the padded byte count, ten parts and the field names alone — no alert field anywhere, stdout or stderr', [quiet.code, quiet.out.length, quietJson?.advisory_reads?.map((r) => [r.op, r.state, r.bytes, r.parts, r.fields]), [...quiet.out, ...quiet.errs].some(leaky)], [EXIT_OK, 1, [['dependabot_list', 'opened', DEPENDABOT_LIST_PADDED_BYTES, 10, ['count', 'alerts']]], false]); + const loud = await cli([...base, '--reveal']); + t("⭐ the CLI with --reveal: THIS process's stdout is the listing's JSON with its pad trimmed — exactly the projected listing, not one trailing space — and never a stderr line", [loud.code, loud.out, loud.errs.some(leaky)], [EXIT_OK, [listed], false]); + } + // ── advisory_note at the seat ─────────────────────────────────────────── battery("advisory_note at the seat: the note read from the file note_file names, composed under the seat's signature line and this door's own stamp, judged, then sealed HERE with a one-time digest key to the relay's committed half under the stroke's request id — the payload carrying the seal alone; a seal from the file, a file inside any git repository, and a missing, unreadable or unjudged one refused and a null committed half a prerequisite, all before anything is sent; the run's ONE notice confirmed against the byte count and keyed digest only this process holds, anything else UNVERIFIED, exit 6 — and no byte of the note on any line the seat prints"); { @@ -5025,6 +5127,7 @@ const USAGE = [ ' node scripts/pm/fleet-write/dispatch.mjs --repo owner/name --actions-file actions.json --dry-run', ' node scripts/pm/fleet-write/dispatch.mjs --repo owner/name --actions-file read.json [--reveal] # one advisory_read: { op, ghsa_id }', ' node scripts/pm/fleet-write/dispatch.mjs --repo owner/name --actions-file list.json [--reveal] # one advisory_list: { op }', + ' node scripts/pm/fleet-write/dispatch.mjs --repo owner/name --actions-file alerts.json [--reveal] # one dependabot_list: { op }', ' node scripts/pm/fleet-write/dispatch.mjs --route # ONE JSON line: the transport this environment resolves to, and why', ' node scripts/pm/fleet-write/dispatch.mjs --self-test', '', @@ -5043,7 +5146,8 @@ const USAGE = [ ' the sealed answer with the private half, which never leaves memory. An answer over one page is read page by page,', ' each its own stroke and key, and joined before anything prints. --reveal prints the opened text to stdout, and', ' nothing else ever prints it; a public_key or a page in the actions file is refused (2). An advisory_list names nothing at all', - ' and is sealed and opened the same way: the triage, draft and closed advisories, five fields each.', + ' and is sealed and opened the same way: the triage, draft and closed advisories, five fields each. A dependabot_list', + ' names nothing either: the open Dependabot alerts, ten fields each, sealed, opened and printed the same way.', ' An advisory_note names ghsa_id and note_file: the file lies outside every git repository and opens with your', " signature line; this process adds the UTC stamp and seals the section to the relay's committed key, so the note's", ' text never enters the payload. A sealed_note in the actions file, or a note file inside a repository, is refused', @@ -5284,7 +5388,7 @@ export async function main(argv, deps = {}) { const result = await pageAdvisoryRead(await sendOne(packed.payload, armed.keys), { payload: packed.payload, session, send: sendOne, log: (l) => console.error(l) }); // ⛔ The opened text reaches THIS process's stdout, and only on --reveal — never stderr, a log, a file or --json. // A listing's opened text is padded to the channel's size: its display alone trims the pad (`advisoryListDisplay`). - if (opts.reveal) for (const r of result.reads ?? []) if (r.state === 'opened' && typeof r.plaintext === 'string') console.log(r.op === 'advisory_list' ? advisoryListDisplay(r.plaintext) : r.plaintext); + if (opts.reveal) for (const r of result.reads ?? []) if (r.state === 'opened' && typeof r.plaintext === 'string') console.log(r.op === 'advisory_list' || r.op === 'dependabot_list' ? advisoryListDisplay(r.plaintext) : r.plaintext); if (!result.ok && (result.state === 'no-run' || result.state === 'timeout')) console.error(unconfirmedText(result, tool)); if (result.notStored) console.error(notStoredText(result, tool)); if (result.state === 'unverified') console.error(unverifiedText(result, tool)); diff --git a/scripts/pm/fleet-write/execute.mjs b/scripts/pm/fleet-write/execute.mjs index bddf22656f3..434d0bab4ff 100644 --- a/scripts/pm/fleet-write/execute.mjs +++ b/scripts/pm/fleet-write/execute.mjs @@ -416,6 +416,20 @@ * marker in each, and finds the marker in no line, row, summary or * annotation, nor in the opened plaintext. * + * ## The Dependabot alerts listing — `dependabot_list`, the same path, its own module (`dependabotListAction`) + * + * `dependabot.mjs` spells the row's gate, its ONE walk of the open alerts on + * the platform's cursor, the fences, the projection, the pad, the seal and + * every sentence, and its header is the authority on them; this file hands it + * `rest` and prints what it returns exactly as the listing's: the row's call + * is `dependabotListCall` (its one state, never a cursor), its status the last + * page's, its result `DEPENDABOT_LIST_LANDED` or one fixed failure, and its + * notes the ten notice parts titled `fleet-write dependabot_list`. Its token + * carries `vulnerability-alerts: read` for this stroke alone. ⛔ Never an + * alert number, a package, a manifest, a severity, an advisory id, a count, a + * cursor or a page number on any line; the self-test serves alerts carrying a + * marker in every field that does not cross and finds it nowhere. + * * ## The note — `advisory_note`, opened here, appended once and read back (`advisoryNoteAction`) * * The relay's key first: the private half (the repository secret the workflow @@ -851,6 +865,23 @@ import { subIssueReadBack, transferRemedy, } from './ops.mjs'; +import { + DEPENDABOT_LIST_ACCESS_REMEDY, + DEPENDABOT_LIST_CAP_HIT, + DEPENDABOT_LIST_CURSOR_REFUSED, + DEPENDABOT_LIST_FIELDS, + DEPENDABOT_LIST_LANDED, + DEPENDABOT_LIST_OVER_CAP, + DEPENDABOT_LIST_PADDED_BYTES, + DEPENDABOT_LIST_PAGE_CAP, + DEPENDABOT_LIST_REPEATED, + DEPENDABOT_LIST_SENDER_REFUSED, + DEPENDABOT_LIST_SHORT_PAGE_NEXT, + DEPENDABOT_LIST_UNREACHED, + dependabotListAction, + dependabotListCall, + dependabotListPagePath, +} from './dependabot.mjs'; import { EVENT_PATH_ENV, readEventPayload, refusalText, tokenRepositoriesOf, validatePayload } from './validate.mjs'; const SELF_PATH = fileURLToPath(import.meta.url); @@ -2761,6 +2792,24 @@ export async function executeFleetWrite({ payload: raw, sender, token, api = DEF } continue; } + // The Dependabot alerts listing (header): `dependabot.mjs`'s gate, walk, projection, pad and seal on this file's + // transport — and nothing of it printed, not even a count. + if (req.dependabotList) { + const call = dependabotListCall(payload.repo); + const listed = await dependabotListAction(req, { payload, index: i + 1, api, t, rest, ...(deps.dependabotList ?? {}) }); + rows.push({ action: i + 1, op: action.op, call, status: listed.status, result: listed.ok ? scrub(listed.result, [token]) : `FAILED: ${scrub(listed.why, [token])}` }); + if (!listed.ok) { + stoppedAt = { action: i + 1, op: action.op, why: scrub(listed.why, [token]) }; + log(` ✗ action ${i + 1} ${action.op}: ${call} -> ${stoppedAt.why}`); + break; + } + log(` ✓ action ${i + 1} ${action.op}: ${call} -> HTTP ${listed.status} · ${rows[rows.length - 1].result}`); + for (const note of listed.notes) { + annotations.push(note); + log(annotationCommand(note)); + } + continue; + } // The note (header): the key, two fenced reads, the open and the mask, ONE PATCH and its byte read-back — nothing of // the note or the description printed; its notice names the action, the section's byte count and a keyed digest. if (req.advisoryNote) { @@ -2941,6 +2990,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ "an issue_create's title and body on a private repository: they reach no log line, row, step summary or annotation when the stroke lands, when the platform refuses it with a message quoting either — the row keeps the status, withholds that message and prints one that quotes nothing —, when the transport fails, or when the payload is refused for an over-cap or ill-typed body — the refusal names the key and the byte count alone": 8, "advisory_read: ONE GET after the sender gate and nothing written; the read, advisory and sender fences judged on that answer — target-write by the maintainer's ruling, a sender off the advisory's collaborators sealed for, one without write refused before the GET, any other gate closed — then the answer sealed to the seat's key and emitted as notice parts the reader parses back, opening byte for byte for that key and read alone; a failed or unsealed seal and an over-cap answer FAILED with nothing emitted; ⛔ the marker in the summary, description and vulnerabilities, and the advisory's id, reach no log line, row, step summary or annotation, and the sealed answer alone carries no marker": 18, "advisory_list: the row's gate before any request, then one walk per listed state on the platform's own cursor, nothing written; a short page or a full one with no next link ends a walk; a refused, unreached or off-shape page, a next link off this API's collection, a repeated advisory, the page cap and the channel's cap each FAILED with nothing emitted; each advisory projected to five fields, the JSON padded and sealed to the seat's key as exactly ten notice parts the reader parses back and opens; ⛔ the marker, every listed id, the cursor and the count reach no log line, row, step summary or annotation, and the row reads the same whatever the count": 27, + "dependabot_list: the row's gate before any request, then ONE walk of the open alerts on the platform's own cursor, nothing written; a short page or a full one with no next link ends the walk; a refused, unreached or off-shape page, a next link off this API's alerts collection, a repeated alert, the page cap and the channel's cap each FAILED with nothing emitted; each alert projected to ten fields, the JSON padded and sealed to the seat's key as exactly ten notice parts the reader parses back and opens; ⛔ the marker, every alert number, package, manifest path and GHSA id, the cursor and the count reach no log line, row, step summary, annotation or pace line, and the row reads the same whatever the count": 21, "advisory_note: the relay's key judged against the committed half before any request; the advisory's GET and its fences, the open, the section judged again and the mask (sparing the note's own notice), a second GET immediately before ONE PATCH of { description } — the text read, byte for byte, the separator and the section — then that PATCH's answer and a GET after it read back byte for byte; a key, fence, open, section, race, cap, refusal or read-back failure each FAILED with no write or no second one, and no byte of the note, the description or the key on any line, row, summary, annotation, pace line or real process's output": 25, "advisory_rewrite: the note's key judged first; the advisory's GET and the rewrite's fences — a published or withdrawn advisory refused, triage, draft and closed landing; the open under the rewrite's own associated data, so a note's seal never opens as one; the text judged again and masked; a second GET immediately before ONE PATCH of exactly the fields sealed, byte for byte; the read-back of each field sent and of the one not sent; ONE notice whose keyed digest is of the text the advisory stores, read back by the seat's parser; and no byte of the new text or the old on any line, row, summary, annotation or pace line": 16, "advisory_severity: the advisory read first and its fences judged — a published or withdrawn advisory, another advisory, an unread one and one carrying a CVSS vector refused with nothing sent; triage, draft and closed landing on ONE PATCH of exactly { severity }; the read-back landing only on an answer storing the severity sent, still unpublished, and FAILED otherwise, never re-sent; a refusal naming its cause; the validator's gate before any request; and the marker on no channel and the severity word on no row, summary or annotation": 7, @@ -2949,8 +2999,9 @@ const SELF_TEST_BATTERIES = Object.freeze({ // hierarchy link battery, 20 → 21 with the advisory rows' battery, 21 → 22 with advisory_read's, 22 → 23 with the mailbox // branch delete's, 23 → 24 with the private-repository issue body's, 24 → 25 with advisory_list's, 25 → 26 with // pr_enqueue_front's, 26 → 27 with the cloud staging deploy's, 27 → 28 with advisory_note's: one battery, one row; -// 28 → 30 with the jump's SIZE lift and pr_dequeue's; 30 → 31 with advisory_rewrite's; 31 → 32 with advisory_severity's. -const SELF_TEST_BATTERY_FLOOR = 32; +// 28 → 30 with the jump's SIZE lift and pr_dequeue's; 30 → 31 with advisory_rewrite's; 31 → 32 with advisory_severity's; +// 32 → 33 with dependabot_list's. +const SELF_TEST_BATTERY_FLOOR = 33; const SEVERITY_BATTERY = "advisory_severity: the advisory read first and its fences judged — a published or withdrawn advisory, another advisory, an unread one and one carrying a CVSS vector refused with nothing sent; triage, draft and closed landing on ONE PATCH of exactly { severity }; the read-back landing only on an answer storing the severity sent, still unpublished, and FAILED otherwise, never re-sent; a refusal naming its cause; the validator's gate before any request; and the marker on no channel and the severity word on no row, summary or annotation"; const REWRITE_BATTERY = "advisory_rewrite: the note's key judged first; the advisory's GET and the rewrite's fences — a published or withdrawn advisory refused, triage, draft and closed landing; the open under the rewrite's own associated data, so a note's seal never opens as one; the text judged again and masked; a second GET immediately before ONE PATCH of exactly the fields sealed, byte for byte; the read-back of each field sent and of the one not sent; ONE notice whose keyed digest is of the text the advisory stores, read back by the seat's parser; and no byte of the new text or the old on any line, row, summary, annotation or pace line"; const UNATTRIBUTED_BATTERY = '(unattributed)'; @@ -4832,7 +4883,7 @@ export async function selfTest() { })(); t('⭐ the seat\'s key opens the parts to the GET answer BYTE FOR BYTE — the summary, the description and the vulnerabilities as the platform answered them, CJK, an emoji, a newline, a quote and a backslash among them', [opened === picked(served.json), Buffer.compare(Buffer.from(opened, 'utf8'), Buffer.from(picked(served.json), 'utf8')), ['summary', 'description', 'vulnerabilities'].map((f) => JSON.stringify(openedJson?.[f]) === JSON.stringify(served.json[f])), Object.keys(openedJson ?? {})], [true, 0, [true, true, true], [...ADVISORY_READ_FIELDS]]); const parsedBack = notices(landed).map((l) => parseRelayAdvisoryReadAnnotation(l.slice(l.indexOf('::', 2) + 2))); - t("the parts are notice commands titled `fleet-write advisory_read`, the reader's own parser reads back exactly what was emitted, and each message is inside the runner's 4,096-character cut", [notices(landed).map((l) => l.slice(0, l.indexOf('::', 2) + 2)), parsedBack, notices(landed).every((l) => l.length - l.indexOf('::', 2) - 2 <= 4096), ADVISORY_READ_OPS], [Array(10).fill('::notice title=fleet-write advisory_read::'), landed.annotations, true, ['advisory_read', 'advisory_list']]); + t("the parts are notice commands titled `fleet-write advisory_read`, the reader's own parser reads back exactly what was emitted, and each message is inside the runner's 4,096-character cut", [notices(landed).map((l) => l.slice(0, l.indexOf('::', 2) + 2)), parsedBack, notices(landed).every((l) => l.length - l.indexOf('::', 2) - 2 <= 4096), ADVISORY_READ_OPS], [Array(10).fill('::notice title=fleet-write advisory_read::'), landed.annotations, true, ['advisory_read', 'advisory_list', 'dependabot_list']]); const sealedText = sealedOf(landed); t('⛔ the sealed answer ALONE carries none of the marker — not in its characters, not in its decoded bytes — though the text it opens to does (the positive control)', [sealedText.includes('ADVISORY'), Buffer.from(sealedText, 'base64url').includes(Buffer.from('ADVISORY MARKER')), opened.includes('ADVISORY MARKER')], [false, false, true]); t("⛔ it opens for the seat's key and THIS read alone: another key pair, another action index and another advisory id are each refused", [opens(landed, { key: pair().privateKey }), opens(landed, { action: 2 }), opens(landed, { ghsaId: OTHER })].map((x) => x.startsWith('refused: ')), [true, true, true]); @@ -5116,6 +5167,168 @@ export async function selfTest() { t('…positive control: the answers served carried the marker, the ids and the cursor, the cursor reached the platform on the second page — where it belongs — and the generic row printer, given a served item, WOULD print the marker and its id', [JSON.stringify(served).includes('ADVISORY MARKER') && JSON.stringify(served).includes(idOf(1)), paged.seen.some((s) => s.call.includes(encodeURIComponent(CURSOR))), resultOf({}, item(1, 'draft')).includes('ADVISORY MARKER') && resultOf({}, item(1, 'draft')).includes(idOf(1))], [true, true, true]); } + // ── dependabot_list ──────────────────────────────────────────────────── + battery("dependabot_list: the row's gate before any request, then ONE walk of the open alerts on the platform's own cursor, nothing written; a short page or a full one with no next link ends the walk; a refused, unreached or off-shape page, a next link off this API's alerts collection, a repeated alert, the page cap and the channel's cap each FAILED with nothing emitted; each alert projected to ten fields, the JSON padded and sealed to the seat's key as exactly ten notice parts the reader parses back and opens; ⛔ the marker, every alert number, package, manifest path and GHSA id, the cursor and the count reach no log line, row, step summary, annotation or pace line, and the row reads the same whatever the count"); + { + const { generateKeyPairSync } = await import('node:crypto'); + // Spaces and punctuation: prose, never a number's, a package's or a cursor's shape. + const MARKER = 'DEPENDABOT MARKER: how the alert was dismissed, never to be logged'; + const CURSOR = 'Y3Vyc29yOnYyOpK0+Zm9v/YmFy=='; + const API = 'https://api.test'; + const CALL = dependabotListCall(REPO); + const pair = () => { + const k = generateKeyPairSync('x25519'); + return { privateKey: k.privateKey, spki: k.publicKey.export({ format: 'der', type: 'spki' }).toString('base64') }; + }; + const SEAT = pair(); + const dl = (extra = {}) => ({ op: 'dependabot_list', public_key: SEAT.spki, ...extra }); + const pageKey = (after = null) => `GET ${dependabotListPagePath(REPO, after)}`; + const REPO_ID_NUMBER = 4242; + const REPO_READ = `GET /repos/${REPO}`; + const ownRepo = { [REPO_READ]: { status: 200, json: { id: REPO_ID_NUMBER, full_name: REPO, description: MARKER } } }; + // Made-up alerts: an eight-digit number no other line carries, a package and manifest path of their own, a made-up GHSA id. + const numberOf = (k) => 91370000 + k; + const packageOf = (k) => `dep-marker-pkg-${k}`; + const manifestOf = (k) => `apps/dep-marker-app-${k}/package.json`; + const idOf = (k) => `GHSA-${k.toString(36).padStart(4, '0')}-2345-wxyz`; + const alert = (k, extra = {}) => ({ + number: numberOf(k), state: 'open', url: `${API}/repos/${REPO}/dependabot/alerts/${numberOf(k)}`, html_url: `https://github.test/${REPO}/security/dependabot/${numberOf(k)}#${MARKER}`, + dependency: { package: { ecosystem: 'npm', name: packageOf(k) }, manifest_path: manifestOf(k), scope: 'runtime' }, + security_advisory: { ghsa_id: idOf(k), cve_id: MARKER, summary: `${MARKER} — the summary`, description: `${MARKER} — the description`, severity: 'high', references: [{ url: MARKER }] }, + security_vulnerability: { package: { ecosystem: 'npm', name: packageOf(k) }, severity: 'high', vulnerable_version_range: '< 9.9.9', first_patched_version: { identifier: '9.9.9' } }, + created_at: '2026-11-01T00:00:00Z', updated_at: '2026-11-02T00:00:00Z', dismissed_by: null, dismissed_reason: null, dismissed_comment: MARKER, auto_dismissed_at: null, + ...extra, + }); + const alerts = (from, n) => Array.from({ length: n }, (_, j) => alert(from + j)); + const pageOf = (json, link = null) => ({ status: 200, json, ...(link ? { headers: { link } } : {}) }); + const nextLink = (after) => `<${API}/repos/${REPO}/dependabot/alerts?state=open&per_page=100&after=${encodeURIComponent(after)}>; rel="next"`; + const realLink = (after, id = String(REPO_ID_NUMBER)) => `<${API}/repositories/${id}/dependabot/alerts?per_page=100&state=open&after=${encodeURIComponent(after)}&page=2>; rel="next"`; + const sealedOf = (r) => (r.annotations ?? []).filter((n) => n.op === 'dependabot_list').sort((a, b) => a.part - b.part).map((n) => n.sealed).join(''); + const opens = (r, { key = SEAT.privateKey, aad = advisorySealAad({ requestId: 'fw-test-1', action: 1, op: 'dependabot_list' }) } = {}) => { + try { + return openAdvisoryRead({ sealed: sealedOf(r), privateKey: key, aad }); + } catch (e) { + return `refused: ${e.message}`; + } + }; + const countOf = (r) => { + try { + return JSON.parse(opens(r)).count; + } catch { + return null; + } + }; + const notices = (r) => r.logs.filter((l) => l.startsWith('::notice ')); + const queried = (answers, seen) => { + const served = new Map(); + return async (url, init) => { + const u = new URL(url); + const call = `${init?.method ?? 'GET'} ${u.pathname}${u.search}`; + seen.push({ call, body: init?.body ? JSON.parse(init.body) : null, auth: init?.headers?.authorization ?? '' }); + const declared = answers[call]; + const nth = served.get(call) ?? 0; + served.set(call, nth + 1); + const a = (Array.isArray(declared) ? declared[Math.min(nth, declared.length - 1)] : declared) ?? { status: 404, json: { message: 'Not Found' } }; + if (a.throws) throw new Error(a.throws); + return { status: a.status, headers: new Headers({ 'x-ratelimit-remaining': '4999', ...(a.headers ?? {}) }), json: async () => a.json }; + }; + }; + const swept = []; + const dlRun = async (actions, answers, { sender = 'os-support-ai', ...extra } = {}) => { + const seen = []; + const logs = []; + const paceLines = []; + const file = join(dir, `pace-dependabot-${paceCase++}.jsonl`); + const r = await executeFleetWrite({ payload: base(actions), sender, token: TOKEN, api: API }, { fetch: queried(answers, seen), pace: { ...paceFor(file), log: (l) => paceLines.push(l) }, log: (l) => logs.push(l), ...extra }); + const out = { ...r, seen, logs }; + swept.push({ r: out, paceLines }); + return out; + }; + // ⭐ Landed: one walk, one short page. + const served = { ...allowed, [pageKey()]: pageOf(alerts(1, 4)) }; + const landed = await dlRun([dl()], served); + t("⭐ a listing is the sender gate, then ONE GET of the open alerts under the App token — ZERO writes, exit 0; its row prints the call with the state, status 200 and the one fixed landed sentence", [landed.exit, landed.seen.map((x) => x.call), landed.seen.every((x) => x.auth === `Bearer ${TOKEN}`), writes(landed.seen).length, landed.rows.map((x) => [x.op, x.call, x.status, x.result])], [EXIT_OK, [PERM, pageKey()], true, 0, [['dependabot_list', CALL, 200, DEPENDABOT_LIST_LANDED]]]); + const opened = opens(landed); + const openedJson = (() => { + try { + return JSON.parse(opened); + } catch { + return null; + } + })(); + t("⭐ the seat's key opens the parts to the padded listing, exactly the channel's size: the count beside every alert in walk order, each exactly the ten fields as the platform answered them, the patched version as its identifier — and the marker NOWHERE in it; the display alone trims the pad", [Buffer.byteLength(opened, 'utf8'), openedJson?.count, openedJson?.alerts?.map((a) => Object.keys(a).join(',')), openedJson?.alerts?.[0], opened.includes('DEPENDABOT MARKER'), JSON.stringify(openedJson) === advisoryListDisplay(opened)], [DEPENDABOT_LIST_PADDED_BYTES, 4, Array.from({ length: 4 }, () => DEPENDABOT_LIST_FIELDS.join(',')), { number: numberOf(1), state: 'open', severity: 'high', ecosystem: 'npm', package: packageOf(1), manifest_path: manifestOf(1), scope: 'runtime', vulnerable_version_range: '< 9.9.9', first_patched_version: '9.9.9', ghsa_id: idOf(1) }, false, true]); + const parsedBack = notices(landed).map((l) => parseRelayAdvisoryReadAnnotation(l.slice(l.indexOf('::', 2) + 2))); + t("the parts are exactly ten notice commands titled `fleet-write dependabot_list`, each 4,000 characters, numbered 1..10 of 10, read back exactly by the reader's own parser", [notices(landed).length, [...new Set(notices(landed).map((l) => l.slice(0, l.indexOf('::', 2) + 2)))], landed.annotations.map((n) => n.sealed.length), landed.annotations.map((n) => `${n.part}/${n.of}`), parsedBack], [ADVISORY_READ_MAX_PARTS, ['::notice title=fleet-write dependabot_list::'], Array.from({ length: 10 }, () => 4000), Array.from({ length: 10 }, (_, k) => `${k + 1}/10`), landed.annotations]); + t("⛔ it opens for the seat's key and THIS listing alone: another key pair, another action index, and the advisory listing's associated data are each refused", [opens(landed, { key: pair().privateKey }), opens(landed, { aad: advisorySealAad({ requestId: 'fw-test-1', action: 2, op: 'dependabot_list' }) }), opens(landed, { aad: advisorySealAad({ requestId: 'fw-test-1', action: 1, op: 'advisory_list' }) })].map((x) => x.startsWith('refused: ')), [true, true, true]); + // The walk on the platform's cursor. + const paged = await dlRun([dl()], { ...allowed, [pageKey()]: pageOf(alerts(10, 100), nextLink(CURSOR)), [pageKey(CURSOR)]: pageOf(alerts(110, 5)) }); + t("⭐ a full page whose Link names this collection's next page is followed on its cursor alone, re-spelled on the relay's own path — and the walk ends on the short page: 105 listed, the repository never read", [paged.exit, paged.seen.map((x) => x.call), countOf(paged)], [EXIT_OK, [PERM, pageKey(), pageKey(CURSOR)], 105]); + const exact = await dlRun([dl()], { ...allowed, [pageKey()]: pageOf(alerts(10, 100)) }); + t('a full page whose Link names no next page ends the walk too: 100 listed, no second GET', [exact.exit, exact.seen.map((x) => x.call), countOf(exact)], [EXIT_OK, [PERM, pageKey()], 100]); + const real = await dlRun([dl()], { ...allowed, ...ownRepo, [pageKey()]: pageOf(alerts(10, 100), realLink(CURSOR)), [pageKey(CURSOR)]: pageOf(alerts(110, 7)) }); + t("⭐ the numeric next-link shape is followed once the repository's own id, read ONCE, equals the link's: a second page on the relay's own path, 107 listed, zero writes", [real.exit, real.seen.map((x) => x.call), countOf(real), writes(real.seen).length], [EXIT_OK, [PERM, pageKey(), REPO_READ, pageKey(CURSOR)], 107, 0]); + const shortNext = await dlRun([dl()], { ...allowed, [pageKey()]: pageOf(alerts(10, 5), nextLink(CURSOR)), [pageKey(CURSOR)]: pageOf(alerts(15, 5)) }); + t('⛔ a SHORT page whose Link still names a next page is FAILED — no second page asked, nothing sealed, no part', [shortNext.exit, shortNext.seen.map((x) => x.call), shortNext.annotations.length, notices(shortNext).length, shortNext.rows[0]?.result], [EXIT_ACTION_FAILED, [PERM, pageKey()], 0, 0, `FAILED: ${DEPENDABOT_LIST_SHORT_PAGE_NEXT}`]); + // ⭐ One sealed size whatever the count — the row and the log read the same. + const none = await dlRun([dl()], { ...allowed, [pageKey()]: pageOf([]) }); + const unnoticed = (r) => [...r.logs.filter((l) => !l.startsWith('::notice ')), JSON.stringify(r.rows), r.summary].join('\n'); + t("⭐ zero, four and 105 alerts seal to ONE length in ten parts each — and every line, row and summary but the ciphertext is byte-identical across the three: nothing on the run says how many", [[none, landed, paged].map((r) => [r.exit, sealedOf(r).length, r.annotations.length, countOf(r)]), unnoticed(none) === unnoticed(landed) && unnoticed(none) === unnoticed(paged)], [[[EXIT_OK, 40000, 10, 0], [EXIT_OK, 40000, 10, 4], [EXIT_OK, 40000, 10, 105]], true]); + // ⛔ The page cap, the cursor's fences, a repeated alert, the channel's cap. + const capped = await dlRun([dl()], { ...allowed, [pageKey()]: pageOf(alerts(10, 100), nextLink('AAAA')), [pageKey('AAAA')]: pageOf(alerts(110, 100), nextLink('BBBB')), [pageKey('BBBB')]: pageOf(alerts(210, 100), nextLink('CCCC')), [pageKey('CCCC')]: pageOf(alerts(310, 1)) }); + t('⛔ a walk still pending after its 3-page cap is FAILED — exactly 3 pages read, nothing sealed, no part — never a truncated listing', [capped.exit, capped.seen.filter((x) => x.call.includes('/dependabot/alerts')).length, capped.annotations.length, notices(capped).length, capped.rows[0]?.result], [EXIT_ACTION_FAILED, DEPENDABOT_LIST_PAGE_CAP, 0, 0, `FAILED: ${DEPENDABOT_LIST_CAP_HIT}`]); + const offLinks = [`; rel="next"`, realLink(CURSOR, '4243'), nextLink(CURSOR).replace('state=open', 'state=dismissed'), nextLink(`${CURSOR} ${MARKER}`), nextLink(CURSOR).replace('/dependabot/alerts?', `/dependabot/alerts/${numberOf(1)}?`)]; + const off = []; + for (const link of offLinks) { + const r = await dlRun([dl()], { ...allowed, ...ownRepo, [pageKey()]: pageOf(alerts(10, 100), link) }); + off.push([r.exit, r.seen.filter((x) => x.call.includes('/dependabot/alerts')).length, r.annotations.length, r.rows[0]?.result?.startsWith(`FAILED: ${DEPENDABOT_LIST_CURSOR_REFUSED}; link shape: 1 rel="next" link(s); `)]); + } + t("⛔ a next link off this API's alerts collection — another host, another repository's numeric id, another state, a cursor outside its shape, one alert's path — is FAILED with the one sentence and the link's shape: no second page asked, nothing sealed, no part", off, offLinks.map(() => [EXIT_ACTION_FAILED, 1, 0, true])); + const twice = await dlRun([dl()], { ...allowed, [pageKey()]: pageOf(alerts(10, 100), nextLink(CURSOR)), [pageKey(CURSOR)]: pageOf(alerts(109, 5)) }); + t('⛔ an alert listed twice across the pages is FAILED — the walk is not one listing — nothing sealed, no part', [twice.exit, twice.annotations.length, twice.rows[0]?.result], [EXIT_ACTION_FAILED, 0, `FAILED: ${DEPENDABOT_LIST_REPEATED}`]); + const longAlert = (k) => alert(k, { dependency: { package: { ecosystem: 'npm', name: `${packageOf(k)}-${'p'.repeat(200)}` }, manifest_path: `${manifestOf(k)}/${'m'.repeat(300)}`, scope: 'development' } }); + const huge = await dlRun([dl()], { ...allowed, [pageKey()]: pageOf(Array.from({ length: 100 }, (_, j) => longAlert(10 + j)), nextLink('AAAA')), [pageKey('AAAA')]: pageOf(Array.from({ length: 5 }, (_, j) => longAlert(110 + j))) }); + t("⛔ a listing over the channel's cap (105 alerts carrying long package names and manifest paths) is FAILED with the cap sentence alone — every page read, nothing sealed, no part, ⛔ never a cut list", [huge.exit, huge.seen.length, huge.annotations.length, notices(huge).length, huge.rows[0]?.result], [EXIT_ACTION_FAILED, 3, 0, 0, `FAILED: ${DEPENDABOT_LIST_OVER_CAP}`]); + // ⛔ A page's fences, and a GET that never reached the platform. + const forbidden = await dlRun([dl()], { ...allowed, [pageKey()]: { status: 403, json: { message: 'Resource not accessible by integration', documentation_url: MARKER } } }); + const dismissed = await dlRun([dl()], { ...allowed, [pageKey()]: pageOf([alert(1), alert(2, { state: 'dismissed' })]) }); + const offField = await dlRun([dl()], { ...allowed, [pageKey()]: pageOf([alert(1), alert(2, { security_vulnerability: { ...alert(2).security_vulnerability, severity: MARKER, vulnerable_version_range: null } })]) }); + t("⛔ fence page: a 403 (the platform's known message and the grant remedy, no further page), a dismissed alert, and a field off its shape — each FAILED, naming the status or the field alone, nothing sealed, no part", [[forbidden, dismissed, offField].map((r) => [r.exit, r.annotations.length, r.rows[0]?.status]), forbidden.seen.length, forbidden.rows[0]?.result, dismissed.rows[0]?.result, offField.rows[0]?.result], [[[EXIT_ACTION_FAILED, 0, 403], [EXIT_ACTION_FAILED, 0, 200], [EXIT_ACTION_FAILED, 0, 200]], 2, `FAILED: REFUSED at the relay's fence on the listing, nothing sealed or emitted — a page of the listing answered HTTP 403 (the platform: Resource not accessible by integration); ${DEPENDABOT_LIST_ACCESS_REMEDY}`, "FAILED: REFUSED at the relay's fence on the listing, nothing sealed or emitted — a page of the listing lists an item that is not an alert in the state the page asked for", "FAILED: REFUSED at the relay's fence on the listing, nothing sealed or emitted — a page of the listing lists an alert whose severity and vulnerable_version_range are not of the fields' declared shapes"]); + const unreached = await dlRun([dl()], { ...allowed, [pageKey()]: { throws: `fetch failed for ${dependabotListPagePath(REPO, CURSOR)} holding ${MARKER}` } }); + const unreachedText = [...unreached.logs, unreached.summary ?? '', JSON.stringify(unreached.rows)].join('\n'); + t("⛔ a page that never reached the platform is FAILED saying so — status `not reached`, no grant remedy, nothing sealed, and the exception's message printed nowhere", [unreached.exit, unreached.rows.map((x) => [x.status, x.result]), unreached.annotations.length, unreachedText.includes('fetch failed'), unreachedText.includes(DEPENDABOT_LIST_ACCESS_REMEDY)], [EXIT_ACTION_FAILED, [[ADVISORY_READ_UNREACHED_STATUS, `FAILED: ${DEPENDABOT_LIST_UNREACHED}`]], 0, false, false]); + // ⛔ The row's gate: judged before the first GET; and the stroke's own gate first. + const gates = []; + for (const senderGate of ['anyone', 'collaborator', 'toString', '']) { + const r = await dlRun([dl()], { ...allowed, [pageKey()]: pageOf(alerts(1, 2)) }, { dependabotList: { senderGate } }); + gates.push([r.exit, r.seen.map((x) => x.call), r.annotations.length, r.rows[0]?.result]); + } + t('⛔ any gate but target-write is refused BEFORE the first GET — a made-up one, the retired collaborator, a prototype key, empty: the permission read alone, nothing sealed, no part', gates, gates.map(() => [EXIT_ACTION_FAILED, [PERM], 0, `FAILED: ${DEPENDABOT_LIST_SENDER_REFUSED}`])); + const PERM_B = `GET /repos/${REPO}/collaborators/os-dev-b/permission`; + const triageB = await dlRun([dl()], { [PERM_B]: { status: 200, json: { permission: 'read', role_name: 'triage', user: { login: 'os-dev-b' } } }, [pageKey()]: pageOf(alerts(1, 2)) }, { sender: 'os-dev-b' }); + t("⛔ …and the stroke's own gate first: a sender with triage on the target is refused before any listing GET — exit 4, no row, no part", [triageB.exit, triageB.seen.map((x) => x.call), triageB.rows.length, (triageB.annotations ?? []).length], [EXIT_SENDER_REFUSED, [PERM_B], 0, 0]); + // ⛔ A failed seal. + const seals = []; + for (const seal of [() => { throw new Error(`seal blew up holding ${MARKER}`); }, ({ plaintext }) => plaintext, () => 'A'.repeat(4000), () => 'A'.repeat(40_001)]) { + const r = await dlRun([dl()], served, { dependabotList: { seal } }); + seals.push([r.exit, r.annotations.length, notices(r).length, r.rows[0]?.result]); + } + t("⛔ a seal that throws, hands back the plaintext, or returns ciphertext of any length but the channel's is FAILED with the one fixed sentence — no part, no notice", seals, seals.map(() => [EXIT_ACTION_FAILED, 0, 0, `FAILED: ${ADVISORY_READ_SEAL_FAILED}`])); + // ⛔ Refused before any request. + const gated = []; + for (const actions of [[dl({ state: 'dismissed' })], [dl({ after: CURSOR })], [dl({ public_key: MARKER })], [dl(), { op: 'comment', issue: 1, body: 'x' }], [dl(), dl({ public_key: pair().spki })], [dl(), { op: 'advisory_list', public_key: SEAT.spki }], [{ op: 'dependabot_list' }]]) { + const r = await dlRun(actions, served); + gated.push([r.exit, r.seen.length]); + } + t('⛔ refused before ANY request, the sender gate included: a state, a cursor, a key that is prose, a listing beside a comment, two listings, one beside the advisory listing, and a listing with no key — exit 2', gated, gated.map(() => [EXIT_REFUSED, 0])); + // ⛔ The sweep: every run above, every channel this file emits on. + const emitted = swept.map(({ r, paceLines }) => [...(r.logs ?? []), ...(r.lines ?? []), r.summary ?? '', JSON.stringify(r.rows ?? []), ...(r.annotations ?? []).map((n) => relayAdvisoryReadAnnotationMessage(n)), ...paceLines].join('\n')); + const values = Array.from({ length: 420 }, (_, k) => [String(numberOf(k)), packageOf(k), manifestOf(k), idOf(k)]).flat(); + const leakOf = (text) => text.includes('DEPENDABOT MARKER') || text.includes('dep-marker-') || text.includes(CURSOR) || text.includes(encodeURIComponent(CURSOR)) || text.includes('9.9.9') || values.some((v) => text.includes(v)); + const leaks = emitted.map((text, i) => (leakOf(text) ? i : null)).filter((i) => i !== null); + t("⛔ THE MARKER TEST — no alert field reaches any log line: across every run of this battery — landed, paged, exact, numeric, short-with-next, empty, capped, off-link, repeated, over-cap, fenced, unreached, gated, unsealed, refused — the marker, every alert's number, package, manifest path, GHSA id and patched version, and the cursor reach NO log line, row, step summary, annotation or pace-log line", [swept.length, leaks], [34, []], leaks.map((i) => emitted[i].split('\n').find((l) => leakOf(l))).join(' | ')); + t('…positive control: the answers served carried the marker and every field, the cursor reached the platform on the second page — where it belongs — and the generic row printer, given a served alert, WOULD print the marker and its package', [JSON.stringify(served).includes('DEPENDABOT MARKER') && JSON.stringify(served).includes(packageOf(1)) && JSON.stringify(served).includes(String(numberOf(1))), paged.seen.some((x) => x.call.includes(encodeURIComponent(CURSOR))), resultOf({}, alert(1)).includes('DEPENDABOT MARKER') || resultOf({}, alert(1)).includes(String(numberOf(1)))], [true, true, true]); + } + // ── advisory_note ─────────────────────────────────────────────────────── battery("advisory_note: the relay's key judged against the committed half before any request; the advisory's GET and its fences, the open, the section judged again and the mask (sparing the note's own notice), a second GET immediately before ONE PATCH of { description } — the text read, byte for byte, the separator and the section — then that PATCH's answer and a GET after it read back byte for byte; a key, fence, open, section, race, cap, refusal or read-back failure each FAILED with no write or no second one, and no byte of the note, the description or the key on any line, row, summary, annotation, pace line or real process's output"); { diff --git a/scripts/pm/fleet-write/ops.mjs b/scripts/pm/fleet-write/ops.mjs index 666872e57fe..c70dcd7c5bd 100644 --- a/scripts/pm/fleet-write/ops.mjs +++ b/scripts/pm/fleet-write/ops.mjs @@ -199,7 +199,10 @@ * `advisory_severity`, below) are * `repository-advisories: write`, and the two that read (`advisory_read` and * `advisory_list`, below) spend the same grant at `read` alone (each row's - * `grant`), the ten rows spending it; the + * `grant`), the ten rows spending it; the Dependabot alerts listing + * (`dependabot_list`, below) is `vulnerability-alerts: read`, the ONE row + * spending it, read from that ledger (`list-dependabot-alerts-for-a-repository`, + * read, server-to-server, no additional permission); the * front-of-queue enqueue (`pr_enqueue_front`, below) and the dequeue * (`pr_dequeue`, below) are `merge-queues: write`, the two rows spending it — * GitHub's GraphQL mutations are outside that ledger, @@ -208,7 +211,7 @@ * `GET /repos/{o}/{r}/collaborators/{login}/permission` is `metadata: read`. * `PERMISSIONS` is that set and nothing wider. The workflow declares the five * grants every stroke gets as literal `permission-*` inputs on - * `actions/create-github-app-token`, and the three grants a stroke gets only + * `actions/create-github-app-token`, and the four grants a stroke gets only * when it spends one (`STROKE_SCOPED_PERMISSIONS`) as inputs read from the * validator's output; `validate.mjs --self-test` pins both spellings equal to * this table. @@ -1037,6 +1040,27 @@ * is a FAILED action carrying `ADVISORY_LIST_ACCESS_REMEDY`, ⛔ never a retry * under a wider token. * + * ## The one row that LISTS Dependabot alerts — `dependabot_list`, sealed the same way + * + * The repository's Dependabot alerts name unfixed weaknesses in a public repository, and a seat's session token is + * refused them (403), so the relay reads them and they get the advisory listing's treatment. The maintainer's word, + * verbatim as the body of issue 39686 records it: 「立卡派发处理 长期办法:让车队中继能读。」 + * + * row request the payload carries + * `dependabot_list` `GET …/dependabot/alerts?state=open&per_page=100[&after=C]`, and at most one `GET /repos/{repo}` `public_key` alone + * + * The table holds the one page path the row reaches (`DEPENDABOT_LIST_PAGE_PATH_SHAPE`: the open state, the page + * size, at most one cursor) and the family refusing every other `dependabot` path (`REFUSED_PATH_FAMILIES`); the walk, + * the cursor, the fences, the projection, the pad and every sentence are `dependabot.mjs`'s, whose header is the + * authority on them. Sealed and emitted exactly as `advisory_list`'s listing, under `advisorySealAad`'s own spelling + * for this op, so neither listing opens as the other; `--reveal` alone prints it at the seat. + * + * The grant is its OWN: `vulnerability-alerts` (the App permission "Dependabot alerts") at `read`, stroke-scoped, so + * the validator writes `permission_vulnerability_alerts=read` for its stroke and an EMPTY value for every other, and the + * workflow's one new input reads that output — every other stroke's token is exactly what it was. It travels `alone`, + * and its `senderGate` is `target-write` (`ADVISORY_READ_SENDER_GATES`), the gate of the advisory read rows by the + * maintainer's ruling quoted in the section above. + * * ## The one row that APPENDS to an advisory — `advisory_note`, sealed to the relay's own key * * A security seat records a ruling at rule level on its public seat post, because no mechanism of an unfixed @@ -1222,16 +1246,20 @@ import { createCipheriv, createDecipheriv, createHash, createHmac, createPrivate import { GOVERNED_REPOS, HUMAN_MERGE_LINE_THRESHOLD } from '../check-governed-merges.mjs'; /** - * The relay's four files, repo-relative — the population a card touching any + * The relay's five files, repo-relative — the population a card touching any * of them implicates (the dispatch derivation reads these literals as path * leads, so a bare `fleet-write/…` spelling would name nothing from the repo - * root). `validate.mjs --self-test` checks each one is on disk. + * root). `validate.mjs --self-test` checks each one is on disk. The fifth, + * `dependabot.mjs`, is the Dependabot alerts listing's own module (header: + * "The one row that LISTS Dependabot alerts"), imported by the executor and + * the seat and tested by their self-tests and the validator's. */ export const RELAY_FILES = Object.freeze([ 'scripts/pm/fleet-write/ops.mjs', 'scripts/pm/fleet-write/validate.mjs', 'scripts/pm/fleet-write/execute.mjs', 'scripts/pm/fleet-write/dispatch.mjs', + 'scripts/pm/fleet-write/dependabot.mjs', ]); /** The board repository every relay lands on; `payload.repo` names the TARGET. */ @@ -3077,8 +3105,11 @@ export function advisoryListNextCursor(link, { api, repo, state, repoId = null } return String(repoId) === numeric[1] ? { after: afters[0] } : { fail: ADVISORY_LIST_CURSOR_REFUSED }; } -/** The targets of a `Link` header's `rel="next"` links — `[]` for none or an empty header, `null` for one that is no string. */ -function advisoryListNextLinks(link) { +/** + * The targets of a `Link` header's `rel="next"` links — `[]` for none or an empty header, `null` for one that is no string. + * Exported for the Dependabot alerts listing's walk (`dependabot.mjs`), which reads its next links the same way. + */ +export function advisoryListNextLinks(link) { if (link === null || link === undefined || link === '') return []; if (typeof link !== 'string') return null; const nexts = []; @@ -3220,9 +3251,10 @@ export function advisoryListDisplay(plaintext) { } /** - * The associated data a sealed answer is bound to, for either row that seals one — the ONE spelling the executor + * The associated data a sealed answer is bound to, for each row that seals one — the ONE spelling the executor * seals under and the seat opens under: `advisory_read`'s is `advisoryReadAad`, byte for byte (the request id, the - * action's index and the advisory's id); `advisory_list`'s binds the request id, the action's index and the op. + * action's index and the advisory's id); `advisory_list`'s and `dependabot_list`'s bind the request id, the action's + * index and the op. * `advisory_note`'s runs the other way — the seat seals, the executor opens — under the note's own label, binding the * request id, the action's index, the op and the advisory's id. Throws for any other op, with a message naming no * value. Pure. @@ -3230,6 +3262,9 @@ export function advisoryListDisplay(plaintext) { export function advisorySealAad({ requestId, action, op, ghsaId }) { if (op === 'advisory_read') return advisoryReadAad({ requestId, action, ghsaId }); if (op === 'advisory_list') return Buffer.from(`${ADVISORY_READ_INFO} request=${requestId} action=${action} op=advisory_list`, 'utf8'); + // The Dependabot alerts listing (header: "The one row that LISTS Dependabot alerts"): the listing's spelling under its + // own op, so neither listing ever opens as the other. + if (op === 'dependabot_list') return Buffer.from(`${ADVISORY_READ_INFO} request=${requestId} action=${action} op=dependabot_list`, 'utf8'); // The one INBOUND seal (header: "The one row that APPENDS"): the note's own label, the op and the advisory's id. if (op === 'advisory_note') return Buffer.from(`fleet-write:advisory_note:v1 request=${requestId} action=${action} op=advisory_note ghsa_id=${ghsaId}`, 'utf8'); // The same seal, the rewrite's (header: "The one row that REPLACES"): its own prefix and op, so a note never opens as @@ -3273,6 +3308,20 @@ export const ADVISORY_LIST_OVER_CAP = export const ADVISORY_LIST_LANDED = "sealed the listing to the seat's one-time key, padded to the run's full notice size so its length says nothing — only that seat's process opens it"; +// --------------------------------------------------------------------------- +// `dependabot_list` (header: "The one row that LISTS Dependabot alerts") — the one page path the table reaches. The +// walk, the cursor, the fences, the projection and the sentences are `dependabot.mjs`'s. +// --------------------------------------------------------------------------- + +/** The one alert state `dependabot_list` lists — the open alerts; the caller names no state. */ +export const DEPENDABOT_LIST_STATE = 'open'; +/** The page size its walk asks for — the endpoint's maximum `per_page`. A page shorter than this ends the walk. */ +export const DEPENDABOT_LIST_PAGE_SIZE = 100; +/** The query of a Dependabot alerts page, as a regex source: the one state, the page size and optionally one encoded cursor. */ +export const DEPENDABOT_LIST_QUERY_SOURCE = `\\?state=${DEPENDABOT_LIST_STATE}&per_page=${DEPENDABOT_LIST_PAGE_SIZE}(?:&after=(?:[A-Za-z0-9_-]|%2B|%2F|%3D){1,${ADVISORY_LIST_CURSOR_MAX_CHARS}})?`; +/** A Dependabot alerts page's path — the collection, then exactly that query. The one `dependabot` query any row reaches. */ +export const DEPENDABOT_LIST_PAGE_PATH_SHAPE = new RegExp(`^/repos/[^/?]+/[^/?]+/dependabot/alerts${DEPENDABOT_LIST_QUERY_SOURCE}$`); + // --------------------------------------------------------------------------- // `advisory_note` (header: "The one row that APPENDS to an advisory") — the relay's key, the seal, the digest, the // fences, the description and the read-back. @@ -3813,19 +3862,23 @@ export const FIELDS = Object.freeze({ * write alone, and minted only for a stroke carrying one of them, the same * way; `advisory_read` and `advisory_list` spend that grant at `read` (each * row's `grant`), so a read's stroke is minted the lower level and never write. + * `vulnerability-alerts: read` is spent by the `dependabot_list` row alone, and + * minted only for a stroke carrying it, the same way (header: "The one row that + * LISTS Dependabot alerts") — read is the level the table holds, and its grant. * `merge-queues: write` is spent by the `pr_enqueue_front` and `pr_dequeue` * rows alone, and minted only for a stroke carrying one of them, the same way * (header: "The one row that reorders the merge queue", "The one row that * takes a pull OUT of the merge queue"). */ -export const PERMISSIONS = Object.freeze({ issues: 'write', 'pull-requests': 'write', contents: 'write', workflows: 'write', metadata: 'read', actions: 'write', 'repository-advisories': 'write', 'merge-queues': 'write' }); +export const PERMISSIONS = Object.freeze({ issues: 'write', 'pull-requests': 'write', contents: 'write', workflows: 'write', metadata: 'read', actions: 'write', 'repository-advisories': 'write', 'merge-queues': 'write', 'vulnerability-alerts': 'read' }); /** * The permissions minted ONLY for a stroke carrying an op that spends them — * `actions: write`, the `workflow_dispatch` and `run_rerun_failed` rows' - * alone, `repository-advisories`, the eight advisory rows' alone, and - * `merge-queues`, the `pr_enqueue_front` and `pr_dequeue` rows' alone — at - * write, or at the row's `grant` (`advisory_read`'s and `advisory_list`'s `read`); each of those + * alone, `repository-advisories`, the eight advisory rows' alone, + * `merge-queues`, the `pr_enqueue_front` and `pr_dequeue` rows' alone, and + * `vulnerability-alerts`, the `dependabot_list` row's alone — at + * write, or at the row's `grant` (`advisory_read`'s, `advisory_list`'s and `dependabot_list`'s `read`); each of those * rows travels alone in its stroke. `validate.mjs` * computes a stroke's permission set (`tokenPermissionsOf`) and writes each of * these to `$GITHUB_OUTPUT` as `permission_=` or empty (a hyphen @@ -3835,7 +3888,7 @@ export const PERMISSIONS = Object.freeze({ issues: 'write', 'pull-requests': 'wr * returns the set unchanged), so every other stroke's token carries the * literal grants alone. */ -export const STROKE_SCOPED_PERMISSIONS = Object.freeze(['actions', 'repository-advisories', 'merge-queues']); +export const STROKE_SCOPED_PERMISSIONS = Object.freeze(['actions', 'repository-advisories', 'merge-queues', 'vulnerability-alerts']); const issues = (repo, n) => `/repos/${repo}/issues/${n}`; const pulls = (repo, n) => `/repos/${repo}/pulls/${n}`; @@ -4369,6 +4422,21 @@ export const OPS = Object.freeze({ alone: true, requests: (a, repo) => [{ verb: 'GET', path: `/repos/${repo}/security-advisories`, advisoryList: { publicKey: a.public_key } }], }), + // The one row that LISTS Dependabot alerts — see the header and `dependabot.mjs`. The collection's GET for the open + // alerts, walked by the executor page by page on the platform's own cursor, nothing written; each alert projected to + // DEPENDABOT_LIST_FIELDS, the listing padded to the channel's full size and sealed to the seat's one-time key, and + // nothing of it printed, not even a count. The caller names no state and no query: `public_key` alone. Its grant is + // its own permission at READ — `vulnerability-alerts`, minted for its stroke alone — and its gate advisory_list's, + // by the same ruling: `target-write`, any other gate refused before the first GET. + dependabot_list: Object.freeze({ + permission: 'vulnerability-alerts', + grant: 'read', + senderGate: 'target-write', + required: Object.freeze(['public_key']), + optional: Object.freeze([]), + alone: true, + requests: (a, repo) => [{ verb: 'GET', path: `/repos/${repo}/dependabot/alerts`, dependabotList: { publicKey: a.public_key } }], + }), // The one row that APPENDS to an advisory — see the header. The id and the note SEALED to the relay's committed key, // and no plaintext: the executor opens it inside its own step, reads the advisory twice (the fences, then the // description just before the write), sends ONE PATCH `{ description }` — the text already there unchanged, then the @@ -4466,6 +4534,10 @@ export const REFUSED_PATH_FAMILIES = Object.freeze([ // fork stay out of reach of any row. The GETs a row sends are `advisory_read`'s, of one advisory's path, and // `advisory_list`'s, of the collection's listing pages (the self-test pins the verbs). new RegExp(`/security-advisories(?!/(?:GHSA(-[0-9a-z]{4}){3}|reports)$|$|${ADVISORY_LIST_QUERY_SOURCE}$)`), + // Every `dependabot` path but the alerts collection (`dependabot_list`'s spelled request) and its listing page + // (`DEPENDABOT_LIST_PAGE_PATH_SHAPE`: the open state, the page size, at most one cursor): one alert's GET or PATCH, + // any other query on the collection, the secrets and every other Dependabot endpoint stay out of reach of any row. + new RegExp(`/dependabot(?!/alerts(?:${DEPENDABOT_LIST_QUERY_SOURCE})?$)`), /^\/orgs\//, /^\/admin\//, /\/collaborators\//, diff --git a/scripts/pm/fleet-write/validate.mjs b/scripts/pm/fleet-write/validate.mjs index eb32e586bdb..f6445ccf5a8 100644 --- a/scripts/pm/fleet-write/validate.mjs +++ b/scripts/pm/fleet-write/validate.mjs @@ -124,6 +124,13 @@ * `state`, a `per_page`, an `after`, a `ghsa_id` — is refused by name. Its * walk, the cursor's fences, the projection and the pad are the * executor's (`ops.mjs`, "The one row that LISTS advisories"); + * - a stroke carrying `dependabot_list` carries exactly that one action + * too, and its token carries `vulnerability-alerts: read`, its `grant`. + * It names `public_key` ALONE, judged the same way: no state, severity, + * package, page, cursor or other query, each refused by name. Its walk + * of the open alerts, the fences, the projection and the pad are the + * executor's (`dependabot.mjs`; `ops.mjs`, "The one row that LISTS + * Dependabot alerts"); * - a `pr_create` may carry `assignees` and `labels`, the typed lists * `assign` and `labels_add` take — judged here as every list is — and the * op table turns each into a later request of the SAME action, sent by @@ -144,14 +151,16 @@ * line, `permission_repository_advisories=write` for a stroke carrying one of * them and empty for every other — and `permission_repository_advisories=read` * for an `advisory_read` or `advisory_list` stroke, the two rows whose `grant` - * is lower than `PERMISSIONS` holds. One more line marks an `advisory_note` + * is lower than `PERMISSIONS` holds. The fourth such line is + * `permission_vulnerability_alerts=read`, for a `dependabot_list` stroke + * alone and empty for every other. One more line marks an `advisory_note` * or `advisory_rewrite` stroke — the two rows sealed to the relay's note key — * `advisory_note=yes`, and is empty for every other: the execute step reads it * to carry the relay's note key for that stroke alone (`ops.mjs`, "The one row * that APPENDS to an advisory" and "The one row that REPLACES"). The * workflow reads those outputs and never the payload, and `--self-test` pins - * the list to ONE name for every other op, two for a transfer, the grant to - * those two rows alone, and the workflow lines that read both. + * the list to ONE name for every other op, two for a transfer, each grant to + * its own rows alone, and the workflow lines that read both. * * A refusal is the WHOLE list of reasons, not the first one: a seat fixing a * payload reads every problem in one pass, and the runner's step summary @@ -174,6 +183,32 @@ import { fileURLToPath } from 'node:url'; import { isEntrypoint } from '../../invoked-as.mjs'; import { GOVERNED_REPOS } from '../check-governed-merges.mjs'; +import { + DEPENDABOT_LIST_ACCESS_REMEDY, + DEPENDABOT_LIST_CAP_HIT, + DEPENDABOT_LIST_CURSOR_REFUSED, + DEPENDABOT_LIST_FIELD_SHAPES, + DEPENDABOT_LIST_FIELDS, + DEPENDABOT_LIST_LANDED, + DEPENDABOT_LIST_OVER_CAP, + DEPENDABOT_LIST_PADDED_BYTES, + DEPENDABOT_LIST_PAGE_CAP, + DEPENDABOT_LIST_REPEATED, + DEPENDABOT_LIST_SCOPES, + DEPENDABOT_LIST_SENDER_REFUSED, + DEPENDABOT_LIST_SEVERITIES, + DEPENDABOT_LIST_SHORT_PAGE_NEXT, + DEPENDABOT_LIST_STRING_CAPS, + DEPENDABOT_LIST_UNREACHED, + dependabotListCall, + dependabotListFieldSentence, + dependabotListLinkShape, + dependabotListNextCursor, + dependabotListPageFailure, + dependabotListPagePath, + dependabotListPlaintext, + dependabotListProjection, +} from './dependabot.mjs'; import { ALLOWED_MUTATIONS, CLIENT_PAYLOAD_MAX_BYTES, @@ -272,6 +307,9 @@ import { ADVISORY_LIST_LANDED, ADVISORY_LIST_OVER_CAP, ADVISORY_LIST_PADDED_BYTES, + DEPENDABOT_LIST_PAGE_PATH_SHAPE, + DEPENDABOT_LIST_PAGE_SIZE, + DEPENDABOT_LIST_STATE, ADVISORY_LIST_PAGE_CAP, ADVISORY_LIST_PAGE_PATH_SHAPE, ADVISORY_LIST_PAGE_SIZE, @@ -1186,6 +1224,7 @@ const SELF_TEST_BATTERIES = Object.freeze({ "the advisory rows: advisory_report, advisory_create, advisory_collaborators_add, advisory_versions and advisory_state — closed keys, a malformed id, package or versions entry refused before any request, a refusal that names the key and the byte count and never echoes a value, published reached by advisory_state alone, from draft alone and through the versions fence; one request each, the draft's and the versions' bodies naming no state and the two other PATCH bodies left to the executor; each a stroke of its own, repository-advisories write minted for it and EMPTY for every other; the bare collection reached by the draft's POST alone and every other security-advisories path refused; the fences, the transitions, the merge and the five read-backs, printing nothing of an answer but the id, the state, the logins and counts": 91, "advisory_read: ghsa_id and public_key alone — the key its own kind, an X25519 key in base64 SPKI DER; a malformed key or id refused before any request and never echoed; ONE GET of one advisory; a stroke of its own whose token alone carries repository-advisories READ; the seal opening byte for byte for its own read and key alone, the parts inside the runner's caps, the sender gate's one setting with every other closed, and the fences, printing no id, state or field": 28, "advisory_list: public_key alone — no state, page, cursor or query the caller can pass; a stroke of its own whose token alone carries repository-advisories READ under the read's sender gate; the listing page's one path shape per listed state; the next cursor taken only from one rel=next link on this API's collection and this state, in its closed shape; each page fenced; each advisory projected to five fields before the seal; the JSON padded to one constant sealed size, ten parts, whatever the count, and one more advisory than fits refused; the shared associated data, advisory_read's byte for byte; and no id, count, state or cursor in any sentence": 28, + "dependabot_list: public_key alone — no state, page, cursor or query the caller can pass; a stroke of its own whose token alone carries vulnerability-alerts READ under the target-write sender gate, spelled permission_vulnerability_alerts=read and EMPTY on every other op's stroke, minted by the workflow from that output alone; the open state alone at 100 a page under a 3-page cap; the next cursor taken only from one rel=next link on this API's alerts collection and the open state; each page fenced; each alert projected to ten fields before the seal; the JSON padded to the listing's one sealed size; its own associated data; every other dependabot path refused; and no number, package, cursor or marker in any sentence": 23, "advisory_note: ghsa_id and sealed_note alone — the note its own kind, ciphertext of a capped length in canonical base64url, refused before any request and never echoed or opened here; ONE PATCH of one advisory whose body is the executor's; a stroke of its own minting repository-advisories write and marked advisory_note=yes, EMPTY for every other; the workflow handing the relay's note key to the execute step for that stroke alone, and no artifact; the seal opening for its own request, action, advisory and key alone and never as a read; the key judged against the committed half; the fences, the description, the read-back and the keyed digest, printing no byte of either text": 22, "advisory_rewrite: ghsa_id and sealed_note alone — the note's field, seal, key and mark, so the workflow hands it the relay's note key unchanged; ONE PATCH of one advisory whose fields are the executor's; alone; a payload carrying no plaintext and no file key; the rewrite's own associated data, so a note never opens as a rewrite; the fences refusing a published or withdrawn advisory; the text judged, an empty description refused; the read-back and the round-trip keyed digest over the stored text, printing no byte of either field": 14, "advisory_severity: ghsa_id and severity alone — severity the report's own quiet enum of GitHub's four, one copy; a missing or malformed id, a missing severity, a value outside the four and any other key each refused before any request, naming the key and echoing no value; ONE PATCH of one advisory whose body is exactly { severity }; alone; repository-advisories write minted for its stroke; the fences refusing a published or withdrawn advisory and one carrying a CVSS vector; the read-back landing only on the severity sent, and no sentence carrying the severity word": 17, @@ -1194,8 +1233,8 @@ const SELF_TEST_BATTERIES = Object.freeze({ // file's battery and the advisory rows' battery, 15 → 16 with advisory_read's, 16 → 17 with mailbox_branch_delete's, // 17 → 18 with advisory_list's, 18 → 19 with pr_enqueue_front's: one battery, one row; 19 → 20 with the workflow // table's repository key; 20 → 21 with advisory_note's; 21 → 22 with pr_dequeue's; 22 → 23 with advisory_rewrite's; -// 23 → 24 with advisory_severity's. -const SELF_TEST_BATTERY_FLOOR = 24; +// 23 → 24 with advisory_severity's; 24 → 25 with dependabot_list's. +const SELF_TEST_BATTERY_FLOOR = 25; const UNATTRIBUTED_BATTERY = '(unattributed)'; const SEVERITY_BATTERY = "advisory_severity: ghsa_id and severity alone — severity the report's own quiet enum of GitHub's four, one copy; a missing or malformed id, a missing severity, a value outside the four and any other key each refused before any request, naming the key and echoing no value; ONE PATCH of one advisory whose body is exactly { severity }; alone; repository-advisories write minted for its stroke; the fences refusing a published or withdrawn advisory and one carrying a CVSS vector; the read-back landing only on the severity sent, and no sentence carrying the severity word"; const REWRITE_BATTERY = "advisory_rewrite: ghsa_id and sealed_note alone — the note's field, seal, key and mark, so the workflow hands it the relay's note key unchanged; ONE PATCH of one advisory whose fields are the executor's; alone; a payload carrying no plaintext and no file key; the rewrite's own associated data, so a note never opens as a rewrite; the fences refusing a published or withdrawn advisory; the text judged, an empty description refused; the read-back and the round-trip keyed digest over the stored text, printing no byte of either field"; @@ -1214,7 +1253,7 @@ let selfTestReachedVerdict = false; * dispatch derivation reads every separator-bearing literal in this module's * body as a path this gate declares, and a slug names no tracked file, so a * bare `owner/name` here is a dead declaration `check:declared-population-live` - * refuses. This gate's real population is the relay's four files, inherited + * refuses. This gate's real population is the relay's five files, inherited * from `RELAY_FILES` in `ops.mjs` and checked on disk by the self-test below. */ export function fixturePayload(overrides = {}) { @@ -1366,6 +1405,7 @@ export async function selfTest() { advisory_state: { ghsa_id: GHSA, advisory_state: 'draft' }, advisory_read: { ghsa_id: GHSA, public_key: READER.spki }, advisory_list: { public_key: READER.spki }, + dependabot_list: { public_key: READER.spki }, advisory_note: { ghsa_id: GHSA, sealed_note: NOTE_SEALED }, advisory_rewrite: { ghsa_id: GHSA, sealed_note: REWRITE_SEALED }, advisory_severity: { ghsa_id: GHSA, severity: 'high' }, @@ -1414,7 +1454,7 @@ export async function selfTest() { const gitTails = ['refs', 'refs/heads/main', 'refs/heads/claude/project-thread-x', 'refs/heads/mailbox/os-zhuang/triage-1', 'refs/heads/claude/mailbox-ui-3/x', 'refs/heads/claude/mailbox-', 'refs/heads/claude/mailbox-UI-3', 'refs/heads/claude/mailbox-a..b', 'refs/tags/claude/mailbox-ui-3', 'ref/heads/claude/mailbox-ui-3', 'matching-refs/heads/claude', 'trees', 'blobs', 'commits', 'tags']; t('positive control: every other /git/ path — a ref create, another or a nested ref, a tag, a tree, blob or commit — and /contents/ are still caught, while the one mailbox ref is caught by none', [gitTails.filter((tail) => !REFUSED_PATH_FAMILIES.some((re) => re.test(`/repos/o/r/git/${tail}`))), REFUSED_PATH_FAMILIES.some((re) => re.test('/repos/o/r/contents/a')), REFUSED_PATH_FAMILIES.filter((re) => re.test('/repos/o/r/git/refs/heads/claude/mailbox-ui-3')).length], [[], true, 0]); t('⛔ the table\'s one PUT is pr_update_branch\'s update-branch, an action endpoint — no PUT reaches /labels or /assignees, the whole-set replaces', [everyRequest.filter((r) => r.verb === 'PUT').map((r) => `${r.op} ${r.path}`), everyRequest.some((r) => r.verb === 'PUT' && /\/(labels|assignees)$/.test(r.path))], [[`pr_update_branch /repos/${TARGET_OWNER}/objectstack/pulls/7/update-branch`], false]); - t("every verb is one of POST, PATCH, PUT, DELETE — but advisory_read's GET of one advisory and advisory_list's GET of the collection, the two GETs any row sends, which write nothing", [everyRequest.filter((r) => r.verb !== 'GET').every((r) => ['POST', 'PATCH', 'PUT', 'DELETE'].includes(r.verb)), everyRequest.filter((r) => r.verb === 'GET').map((r) => `${r.op} ${r.path}`)], [true, [`advisory_read /repos/${TARGET_OWNER}/objectstack/security-advisories/${GHSA}`, `advisory_list /repos/${TARGET_OWNER}/objectstack/security-advisories`]]); + t("every verb is one of POST, PATCH, PUT, DELETE — but advisory_read's GET of one advisory, advisory_list's GET of the collection and dependabot_list's GET of the open Dependabot alerts, the three GETs any row sends, which write nothing", [everyRequest.filter((r) => r.verb !== 'GET').every((r) => ['POST', 'PATCH', 'PUT', 'DELETE'].includes(r.verb)), everyRequest.filter((r) => r.verb === 'GET').map((r) => `${r.op} ${r.path}`)], [true, [`advisory_read /repos/${TARGET_OWNER}/objectstack/security-advisories/${GHSA}`, `advisory_list /repos/${TARGET_OWNER}/objectstack/security-advisories`, `dependabot_list /repos/${TARGET_OWNER}/objectstack/dependabot/alerts`]]); t('pr_update_branch spends pull-requests — where GitHub\'s ledger lists update-branch, server-to-server, no additional permission — and carries the sha in its body', [OPS.pr_update_branch.permission, OPS.pr_update_branch.requests({ op: 'pr_update_branch', pull: 7, expected_head_sha: SHA }, 'o/r')[0].body], ['pull-requests', { expected_head_sha: SHA }]); t('every GraphQL descriptor names an allowed mutation and its query spells that name', everyRequest.filter((r) => r.graphql).every((r) => ALLOWED_MUTATIONS.includes(r.graphql.mutation) && r.graphql.query.includes(r.graphql.mutation))); t('pr_create forces draft: true whatever the action said', OPS.pr_create.requests({ op: 'pr_create', title: 't', head: 'h', base: 'b' }, 'o/r')[0].body.draft, true); @@ -1434,9 +1474,9 @@ export async function selfTest() { // mailbox_branch_delete's one ref DELETE spends it (comment 6674408912) — no file write. `workflows: write` // is the maintainer's ruling (comment 6104822731): a literal grant on every stroke, spent by the // `automerge_enable` row alone (`alsoSpends`) when the pull it arms changes a workflow file. - t('the map is exactly issues/pull-requests/contents/workflows/actions/repository-advisories/merge-queues write and metadata read', PERMISSIONS, { issues: 'write', 'pull-requests': 'write', contents: 'write', workflows: 'write', metadata: 'read', actions: 'write', 'repository-advisories': 'write', 'merge-queues': 'write' }); + t('the map is exactly issues/pull-requests/contents/workflows/actions/repository-advisories/merge-queues write and metadata and vulnerability-alerts read', PERMISSIONS, { issues: 'write', 'pull-requests': 'write', contents: 'write', workflows: 'write', metadata: 'read', actions: 'write', 'repository-advisories': 'write', 'merge-queues': 'write', 'vulnerability-alerts': 'read' }); t('workflows is spent by the two enqueuing rows alone, automerge_enable and pr_enqueue_front, as alsoSpends, and is no row\'s permission', [OP_NAMES.filter((op) => (OPS[op].alsoSpends ?? []).includes('workflows')), OP_NAMES.filter((op) => OPS[op].permission === 'workflows')], [['automerge_enable', 'pr_enqueue_front'], []]); - t('nothing wider: every PERMISSIONS key but metadata (the sender gate\'s read) is spent by some row as its permission or an alsoSpends, and the two sets are exactly actions/contents/issues/merge-queues/pull-requests/repository-advisories/workflows', [Object.keys(PERMISSIONS).filter((name) => name !== 'metadata').sort(), [...new Set(OP_NAMES.flatMap((op) => [OPS[op].permission, ...(OPS[op].alsoSpends ?? [])]))].sort()], [['actions', 'contents', 'issues', 'merge-queues', 'pull-requests', 'repository-advisories', 'workflows'], ['actions', 'contents', 'issues', 'merge-queues', 'pull-requests', 'repository-advisories', 'workflows']]); + t('nothing wider: every PERMISSIONS key but metadata (the sender gate\'s read) is spent by some row as its permission or an alsoSpends, and the two sets are exactly actions/contents/issues/merge-queues/pull-requests/repository-advisories/vulnerability-alerts/workflows', [Object.keys(PERMISSIONS).filter((name) => name !== 'metadata').sort(), [...new Set(OP_NAMES.flatMap((op) => [OPS[op].permission, ...(OPS[op].alsoSpends ?? [])]))].sort()], [['actions', 'contents', 'issues', 'merge-queues', 'pull-requests', 'repository-advisories', 'vulnerability-alerts', 'workflows'], ['actions', 'contents', 'issues', 'merge-queues', 'pull-requests', 'repository-advisories', 'vulnerability-alerts', 'workflows']]); t('the two auto-merge rows spend contents', [OPS.automerge_enable.permission, OPS.automerge_disable.permission], ['contents', 'contents']); t('⛔ …and beside them mailbox_branch_delete alone: contents reaches the two auto-merge mutations and one ref DELETE', OP_NAMES.filter((op) => OPS[op].permission === 'contents').sort(), ['automerge_disable', 'automerge_enable', 'mailbox_branch_delete']); t('every row spending contents is a GraphQL auto-merge mutation but mailbox_branch_delete, whose one REST request is a DELETE of a head ref', OP_NAMES.filter((op) => OPS[op].permission === 'contents').map((op) => OPS[op].requests({ op, pull: 1, branch: 'claude/mailbox-x' }, 'o/r').map((r) => (r.graphql ? /PullRequestAutoMerge$/.test(r.graphql.mutation) : `${r.verb} ${r.path}`))), [[true], [true], ['DELETE /repos/o/r/git/refs/heads/claude/mailbox-x']]); @@ -1517,7 +1557,7 @@ export async function selfTest() { for (const f of ['missing.json', 'notjson.json', 'event-no-payload.json', 'event-list.json']) unfit.push((await drive(['--from-event'], { [EVENT_PATH_ENV]: f })).code); t('--from-event on an unreadable event file, one that is not JSON, one with no client_payload and one whose client_payload is not an object: each exit 3', unfit, [EXIT_PREREQUISITE, EXIT_PREREQUISITE, EXIT_PREREQUISITE, EXIT_PREREQUISITE]); const env = await drive(['--from-event', '--github-output'], { [EVENT_PATH_ENV]: 'event.json', GITHUB_OUTPUT: '/out.txt' }); - t('--from-event --github-output judges the event file\'s client_payload and writes repositories, request_id, action_count, session and an EMPTY permission_actions, permission_repository_advisories, permission_merge_queues and advisory_note to $GITHUB_OUTPUT for a comment', [env.code, env.appended[0]?.file, env.appended[0]?.text], [EXIT_OK, '/out.txt', 'repositories=objectstack\nrequest_id=fw-20260922T090000Z-abc123\naction_count=1\nsession=session_01ABCDEFGHJKMNPQRSTVWXYZ\npermission_actions=\npermission_repository_advisories=\npermission_merge_queues=\nadvisory_note=\n']); + t('--from-event --github-output judges the event file\'s client_payload and writes repositories, request_id, action_count, session and an EMPTY permission_actions, permission_repository_advisories, permission_merge_queues, permission_vulnerability_alerts and advisory_note to $GITHUB_OUTPUT for a comment', [env.code, env.appended[0]?.file, env.appended[0]?.text], [EXIT_OK, '/out.txt', 'repositories=objectstack\nrequest_id=fw-20260922T090000Z-abc123\naction_count=1\nsession=session_01ABCDEFGHJKMNPQRSTVWXYZ\npermission_actions=\npermission_repository_advisories=\npermission_merge_queues=\npermission_vulnerability_alerts=\nadvisory_note=\n']); t('--github-output without GITHUB_OUTPUT is exit 3', (await drive(['--from-event', '--github-output'], { [EVENT_PATH_ENV]: 'event.json' })).code, EXIT_PREREQUISITE); t('⛔ --from-env, the old route through a step\'s logged env, is gone: an unknown flag, usage, nothing judged', [(await drive(['--from-env'], { FLEET_WRITE_PAYLOAD: good })).code, KNOWN_FLAGS.includes('--from-env')], [EXIT_REFUSED, false]); t('--json prints the normalised payload as one line after the OK line', JSON.parse((await drive(['--file', 'good.json', '--json'])).out.split('\n')[1]).request_id, 'fw-20260922T090000Z-abc123'); @@ -1562,6 +1602,7 @@ export async function selfTest() { advisory_report: { summary: 's', description: 'd' }, advisory_create: { summary: 's', description: 'd', packages: ['p'] }, advisory_collaborators_add: { ghsa_id: GHSA, collaborators: ['u'] }, advisory_versions: { ghsa_id: GHSA, versions: [VERSION] }, advisory_state: { ghsa_id: GHSA, advisory_state: 'draft' }, advisory_read: { ghsa_id: GHSA, public_key: READER.spki }, advisory_list: { public_key: READER.spki }, + dependabot_list: { public_key: READER.spki }, advisory_note: { ghsa_id: GHSA, sealed_note: NOTE_SEALED }, advisory_rewrite: { ghsa_id: GHSA, sealed_note: REWRITE_SEALED }, advisory_severity: { ghsa_id: GHSA, severity: 'high' }, @@ -1607,12 +1648,12 @@ export async function selfTest() { t('an inputs key on a file whose entry is null is refused BY NAME — the relay sends none there', refuses(one(start({ inputs: { reason: true } })), `actions[0].inputs: ${FILE} declares no inputs`)); t('⛔ a workflow_dispatch beside any other op is refused — the stroke carries that one action alone', refuses(fixturePayload({ actions: [start(), { op: 'comment', issue: 7, body: 'x' }] }), 'actions[1] is `comment` in a stroke that carries a `workflow_dispatch`')); t('⛔ two workflow_dispatch in one stroke are refused too', refuses(fixturePayload({ actions: [start(), start()] }), 'a stroke carries exactly ONE `workflow_dispatch` and nothing else')); - t('the only rows that travel alone or widen the token: pr_enqueue_front, pr_dequeue, workflow_dispatch, run_rerun_failed and the ten advisory rows (alone) and transfer (second repository)', [OP_NAMES.filter((op) => OPS[op].alone), OP_NAMES.filter((op) => OPS[op].secondRepo)], [['pr_enqueue_front', 'pr_dequeue', 'workflow_dispatch', 'run_rerun_failed', 'advisory_report', 'advisory_create', 'advisory_collaborators_add', 'advisory_versions', 'advisory_state', 'advisory_read', 'advisory_list', 'advisory_note', 'advisory_rewrite', 'advisory_severity'], ['transfer']]); + t('the only rows that travel alone or widen the token: pr_enqueue_front, pr_dequeue, workflow_dispatch, run_rerun_failed, the ten advisory rows and dependabot_list (alone) and transfer (second repository)', [OP_NAMES.filter((op) => OPS[op].alone), OP_NAMES.filter((op) => OPS[op].secondRepo)], [['pr_enqueue_front', 'pr_dequeue', 'workflow_dispatch', 'run_rerun_failed', 'advisory_report', 'advisory_create', 'advisory_collaborators_add', 'advisory_versions', 'advisory_state', 'advisory_read', 'advisory_list', 'dependabot_list', 'advisory_note', 'advisory_rewrite', 'advisory_severity'], ['transfer']]); t('…and actions is spent by the workflow_dispatch and run_rerun_failed rows and NOTHING else — each of them alone in its stroke', [OP_NAMES.filter((op) => OPS[op].permission === 'actions'), OP_NAMES.filter((op) => OPS[op].permission === 'actions').every((op) => OPS[op].alone === true)], [['workflow_dispatch', 'run_rerun_failed'], true]); const plain = validatePayload(fixturePayload()).payload; const run = validatePayload(one(start())).payload; t('the token grants: a comment stroke carries the five literal grants and no actions; a workflow_dispatch stroke adds actions write', [tokenPermissionsOf(plain), tokenPermissionsOf(run)], [{ issues: 'write', 'pull-requests': 'write', contents: 'write', workflows: 'write', metadata: 'read' }, { issues: 'write', 'pull-requests': 'write', contents: 'write', workflows: 'write', metadata: 'read', actions: 'write' }]); - t('…and the GitHub output spells that as permission_actions=write for the run stroke, EMPTY for every other — the mint action skips an empty input', [outputLine(run, 'permission_actions'), outputLine(plain, 'permission_actions'), [...STROKE_SCOPED_PERMISSIONS]], ['permission_actions=write', 'permission_actions=', ['actions', 'repository-advisories', 'merge-queues']]); + t('…and the GitHub output spells that as permission_actions=write for the run stroke, EMPTY for every other — the mint action skips an empty input', [outputLine(run, 'permission_actions'), outputLine(plain, 'permission_actions'), [...STROKE_SCOPED_PERMISSIONS]], ['permission_actions=write', 'permission_actions=', ['actions', 'repository-advisories', 'merge-queues', 'vulnerability-alerts']]); // The fence on the grant: every path every row can spell, against the actions families — the dispatch call is the ONE // actions path reached; and a POSITIVE CONTROL that the families would catch what actions: write otherwise reaches. const filled = { issue: 7, pull: 7, comment_id: 7, body: 'b', title: 't', head: 'h', base: 'main', labels: ['a'], assignees: ['u'], reviewers: ['u'], team_reviewers: ['t'], state: 'closed', state_reason: 'completed', expected_head_sha: SHA, target_repo: `${TARGET_OWNER}/objectui`, workflow: FILE, ref: WORKFLOW_DISPATCH_REF, run_id: 7, sub_issue: 8, ghsa_id: GHSA, collaborators: ['u'], summary: 's', description: 'd', severity: 'low', cwe_ids: ['CWE-79'], advisory_state: 'closed', packages: ['p'], versions: [VERSION] }; @@ -1771,6 +1812,7 @@ export async function selfTest() { advisory_report: { summary: 's', description: 'd' }, advisory_create: { summary: 's', description: 'd', packages: ['p'] }, advisory_collaborators_add: { ghsa_id: GHSA, collaborators: ['u'] }, advisory_versions: { ghsa_id: GHSA, versions: [VERSION] }, advisory_state: { ghsa_id: GHSA, advisory_state: 'draft' }, advisory_read: { ghsa_id: GHSA, public_key: READER.spki }, advisory_list: { public_key: READER.spki }, + dependabot_list: { public_key: READER.spki }, advisory_note: { ghsa_id: GHSA, sealed_note: NOTE_SEALED }, advisory_rewrite: { ghsa_id: GHSA, sealed_note: REWRITE_SEALED }, advisory_severity: { ghsa_id: GHSA, severity: 'high' }, @@ -2160,6 +2202,7 @@ export async function selfTest() { automerge_enable: { pull: 1 }, automerge_disable: { pull: 1 }, pr_enqueue_front: { pull: 1, expected_head_sha: SHA }, pr_dequeue: { pull: 1, expected_head_sha: SHA, cause: 'conflict', reason: 'r' }, mailbox_branch_delete: { pull: 1, branch: 'claude/mailbox-ui-3' }, transfer: { issue: 1, target_repo: `${TARGET_OWNER}/objectui` }, sub_issue_add: { issue: 1, sub_issue: 2 }, sub_issue_remove: { issue: 1, sub_issue: 2 }, workflow_dispatch: { workflow: WORKFLOW_DISPATCH_ALLOWLIST[0], ref: WORKFLOW_DISPATCH_REF }, run_rerun_failed: { run_id: 1 }, + dependabot_list: { public_key: READER.spki }, }; const others = OP_NAMES.filter((op) => !ADVISORY_OPS.includes(op)); t('…the ledger of every other op, no more and no less', Object.keys(minimalOf).sort(), [...others].sort()); @@ -2318,7 +2361,7 @@ export async function selfTest() { const PREFIX = 'MCowBQYDK2VuAyEA'; // The row, its fields and its one request. t('the row: ghsa_id and public_key, and page alone optional; it spends repository-advisories at READ (its grant), travels alone, widens nothing else; public_key is its own kind, ghsa_id the existing one, and page a quiet integer capped at the page count', [OPS.advisory_read.required, OPS.advisory_read.optional, OPS.advisory_read.permission, OPS.advisory_read.grant, OPS.advisory_read.alone, OPS.advisory_read.alsoSpends ?? null, OPS.advisory_read.secondRepo ?? null, FIELDS.public_key, FIELDS.ghsa_id, FIELDS.page], [['ghsa_id', 'public_key'], ['page'], 'repository-advisories', 'read', true, null, null, { kind: 'x25519' }, { kind: 'ghsa' }, { kind: 'int', max: ADVISORY_READ_MAX_PAGES, quiet: true }]); - t("⚖ the sender gate, by the maintainer's ruling: ONE setting, target-write — write, maintain or admin on the target, the gate every other row keeps — on advisory_read and advisory_list, the two rows carrying one, whose grant stays read", [Object.keys(ADVISORY_READ_SENDER_GATES), OPS.advisory_read.senderGate, OP_NAMES.filter((op) => OPS[op].senderGate !== undefined), OPS.advisory_read.grant], [['target-write'], 'target-write', ['advisory_read', 'advisory_list'], 'read']); + t("⚖ the sender gate, by the maintainer's ruling: ONE setting, target-write — write, maintain or admin on the target, the gate every other row keeps — on advisory_read, advisory_list and dependabot_list, the three rows carrying one, whose grant stays read", [Object.keys(ADVISORY_READ_SENDER_GATES), OPS.advisory_read.senderGate, OP_NAMES.filter((op) => OPS[op].senderGate !== undefined), OPS.advisory_read.grant], [['target-write'], 'target-write', ['advisory_read', 'advisory_list', 'dependabot_list'], 'read']); const asked = OPS.advisory_read.requests(read(), REPO); t("its one request is a GET of one advisory's path — no body, no write — carrying the id and the key to the executor, and reaching no refused family", [asked.length, asked[0].verb, asked[0].path, 'body' in asked[0], asked[0].advisoryRead, ADVISORY_PATH_SHAPE.test(asked[0].path), REFUSED_PATH_FAMILIES.filter((re) => re.test(asked[0].path)).length, OPS.advisory_read.requests(read({ page: 3 }), REPO)[0].advisoryRead.page], [1, 'GET', `/repos/${REPO}/security-advisories/${GHSA}`, false, { ghsaId: GHSA, publicKey: READER.spki, page: 1 }, true, 0, 3]); // The page: a quiet integer, 1..ADVISORY_READ_MAX_PAGES — judged before any request, ⛔ never echoed. @@ -2352,7 +2395,7 @@ export async function selfTest() { const readStroke = validatePayload(one(read())).payload; const addStroke = validatePayload(one(add)).payload; t("⭐ fence grant: a read's stroke mints the five literal grants plus repository-advisories READ — never write, never actions — for ONE repository, and the GitHub output spells it permission_repository_advisories=read; a writing row's stroke still mints write", [tokenPermissionsOf(readStroke), tokenRepositoriesOf(readStroke), outputLine(readStroke, 'permission_repository_advisories'), outputLine(readStroke, 'permission_actions'), tokenPermissionsOf(addStroke)['repository-advisories']], [{ issues: 'write', 'pull-requests': 'write', contents: 'write', workflows: 'write', metadata: 'read', 'repository-advisories': 'read' }, [REPO], 'permission_repository_advisories=read', 'permission_actions=', 'write']); - t('⛔ the grant ledger: advisory_read and advisory_list alone name a grant, on a stroke-scoped permission, at a level no higher than PERMISSIONS holds — so no row can mint a grant the table does not carry', [OP_NAMES.filter((op) => OPS[op].grant !== undefined), OP_NAMES.filter((op) => OPS[op].grant !== undefined).every((op) => STROKE_SCOPED_PERMISSIONS.includes(OPS[op].permission) && (OPS[op].grant === 'read' || (OPS[op].grant === 'write' && PERMISSIONS[OPS[op].permission] === 'write')))], [['advisory_read', 'advisory_list'], true]); + t('⛔ the grant ledger: advisory_read, advisory_list and dependabot_list alone name a grant, on a stroke-scoped permission, at a level no higher than PERMISSIONS holds — so no row can mint a grant the table does not carry', [OP_NAMES.filter((op) => OPS[op].grant !== undefined), OP_NAMES.filter((op) => OPS[op].grant !== undefined).every((op) => STROKE_SCOPED_PERMISSIONS.includes(OPS[op].permission) && (OPS[op].grant === 'read' || (OPS[op].grant === 'write' && PERMISSIONS[OPS[op].permission] === 'write')))], [['advisory_read', 'advisory_list', 'dependabot_list'], true]); // The seal. const aad = advisoryReadAad({ requestId: 'fw-20261102T000000Z-abc123', action: 1, ghsaId: GHSA }); const TEXT = JSON.stringify({ ghsa_id: GHSA, summary: `${PROSE} — 漢字, é, 🎉, a quote " and a backslash \\`, description: 'line one\nline two
and a separator', vulnerabilities: [{ package: { ecosystem: 'npm', name: 'p' } }] }); @@ -2568,6 +2611,149 @@ export async function selfTest() { t('⛔ every sentence a listing prints names no id, no state word, no severity, no digit but its own caps and statuses, and no marker — the landed row says it landed and nothing more', [sentences.filter((x) => /GHSA|\b(?:triage|draft|closed|published|critical|high|medium|low)\b|ADVISORY LIST MARKER/.test(x)), ADVISORY_LIST_LANDED, sentences.flatMap((x) => x.match(/\d+/g) ?? []).filter((d) => !['3', '29939', '10', '200', '404', '403'].includes(d))], [[], "sealed the listing to the seat's one-time key, padded to the run's full notice size so its length says nothing — only that seat's process opens it", []]); } + // ── dependabot_list: the one row that lists Dependabot alerts, sealed the listing's way ───────────── + battery("dependabot_list: public_key alone — no state, page, cursor or query the caller can pass; a stroke of its own whose token alone carries vulnerability-alerts READ under the target-write sender gate, spelled permission_vulnerability_alerts=read and EMPTY on every other op's stroke, minted by the workflow from that output alone; the open state alone at 100 a page under a 3-page cap; the next cursor taken only from one rel=next link on this API's alerts collection and the open state; each page fenced; each alert projected to ten fields before the seal; the JSON padded to the listing's one sealed size; its own associated data; every other dependabot path refused; and no number, package, cursor or marker in any sentence"); + { + const REPO = `${TARGET_OWNER}/objectstack`; + const API = 'https://api.github.com'; + const dl = (extra = {}) => ({ op: 'dependabot_list', public_key: READER.spki, ...extra }); + const one = (action) => fixturePayload({ actions: [action] }); + const errorsOf = (action) => validatePayload(one(action)).errors; + const MARKER = 'DEPENDABOT LIST MARKER'; + // The row and its one request. + t('the row: public_key alone, nothing optional; vulnerability-alerts at READ, alone, the target-write gate; no second repository, no alsoSpends, no closed inputs', [OPS.dependabot_list.required, OPS.dependabot_list.optional, OPS.dependabot_list.permission, OPS.dependabot_list.grant, OPS.dependabot_list.alone, OPS.dependabot_list.senderGate, OPS.dependabot_list.secondRepo ?? null, OPS.dependabot_list.alsoSpends ?? null, OPS.dependabot_list.closedInputs ?? null], [['public_key'], [], 'vulnerability-alerts', 'read', true, 'target-write', null, null, null]); + const asked = OPS.dependabot_list.requests(dl(), REPO); + t('its one request is a GET of the bare alerts collection — no body, no write — carrying the key alone to the executor, which spells the pages; it reaches no refused family', [asked.length, asked[0].verb, asked[0].path, 'body' in asked[0], asked[0].dependabotList, REFUSED_PATH_FAMILIES.filter((re) => re.test(asked[0].path)).length], [1, 'GET', `/repos/${REPO}/dependabot/alerts`, false, { publicKey: READER.spki }, 0]); + // The validator. + const accepted = validatePayload(one(dl())); + t('accepted: one listing with a fresh key, normalised to exactly what was sent', [accepted.ok, accepted.payload?.actions[0]], [true, dl()], accepted.errors.join(' | ')); + const takes = 'is not a key `dependabot_list` takes (it takes public_key)'; + t('⛔ refused BY NAME beside a listing: a state, a severity, an ecosystem, a package, a manifest, a scope, a page size, a page, a cursor either way, a sort, a direction, an alert number, a private key and a body — the caller names nothing but the key', ['state', 'severity', 'ecosystem', 'package', 'manifest', 'scope', 'per_page', 'page', 'after', 'before', 'sort', 'direction', 'number', 'alert_number', 'private_key', 'body'].filter((key) => !refuses(one(dl({ [key]: 'x' })), `actions[0].${key} ${takes}`)), []); + t("⛔ refused: the key missing, and a malformed key — judged as the read's, never echoed", [refuses(one({ op: 'dependabot_list' }), 'actions[0].public_key is required by `dependabot_list`'), refuses(one(dl({ public_key: MARKER })), 'actions[0].public_key must be one X25519 public key'), errorsOf(dl({ public_key: MARKER })).some((e) => e.includes(MARKER))], [true, true, false]); + t('⛔ fence alone, refused: a listing beside a comment, beside the advisory listing either way, and two listings', [refuses(fixturePayload({ actions: [dl(), { op: 'comment', issue: 7, body: 'x' }] }), 'actions[1] is `comment` in a stroke that carries a `dependabot_list` — its token carries vulnerability-alerts read'), refuses(fixturePayload({ actions: [dl(), { op: 'advisory_list', public_key: keyPair().spki }] }), 'actions[1] is `advisory_list` in a stroke that carries a `dependabot_list`'), refuses(fixturePayload({ actions: [{ op: 'advisory_list', public_key: keyPair().spki }, dl()] }), 'in a stroke that carries a `advisory_list`'), refuses(fixturePayload({ actions: [dl(), dl({ public_key: keyPair().spki })] }), 'a stroke carries exactly ONE `dependabot_list` and nothing else')], [true, true, true, true]); + // ⭐ The grant: minted for this stroke alone, never for another. + const stroke = validatePayload(one(dl())).payload; + t("⭐ fence grant: a listing's stroke mints the five literal grants plus vulnerability-alerts READ — never write, and no repository-advisories — for ONE repository, spelled permission_vulnerability_alerts=read through its own input", [tokenPermissionsOf(stroke), tokenRepositoriesOf(stroke), outputLine(stroke, 'permission_vulnerability_alerts'), outputLine(stroke, 'permission_repository_advisories'), outputLine(stroke, 'permission_actions'), outputLine(stroke, 'permission_merge_queues')], [{ issues: 'write', 'pull-requests': 'write', contents: 'write', workflows: 'write', metadata: 'read', 'vulnerability-alerts': 'read' }, [REPO], 'permission_vulnerability_alerts=read', 'permission_repository_advisories=', 'permission_actions=', 'permission_merge_queues=']); + const minimalOf = { + comment: { issue: 1, body: 'b' }, comment_edit: { comment_id: 1, body: 'b' }, labels_add: { issue: 1, labels: ['a'] }, labels_remove: { issue: 1, labels: ['a'] }, + assign: { issue: 1, assignees: ['u'] }, unassign: { issue: 1, assignees: ['u'] }, issue_patch: { issue: 1, state: 'closed' }, issue_create: { title: 't', body: 'b' }, + pr_create: { title: 't', head: 'h', base: 'main' }, pr_request_reviewers: { pull: 1, reviewers: ['u'] }, pr_update_branch: { pull: 1, expected_head_sha: SHA }, pr_ready: { pull: 1 }, pr_draft: { pull: 1 }, + automerge_enable: { pull: 1 }, automerge_disable: { pull: 1 }, pr_enqueue_front: { pull: 1, expected_head_sha: SHA }, pr_dequeue: { pull: 1, expected_head_sha: SHA, cause: 'conflict', reason: 'r' }, mailbox_branch_delete: { pull: 1, branch: 'claude/mailbox-ui-3' }, transfer: { issue: 1, target_repo: `${TARGET_OWNER}/objectui` }, + workflow_dispatch: { workflow: WORKFLOW_DISPATCH_ALLOWLIST[0], ref: WORKFLOW_DISPATCH_REF }, run_rerun_failed: { run_id: 1 }, sub_issue_add: { issue: 1, sub_issue: 2 }, sub_issue_remove: { issue: 1, sub_issue: 2 }, + advisory_report: { summary: 's', description: 'd' }, advisory_create: { summary: 's', description: 'd', packages: ['p'] }, advisory_collaborators_add: { ghsa_id: GHSA, collaborators: ['u'] }, advisory_versions: { ghsa_id: GHSA, versions: [VERSION] }, advisory_state: { ghsa_id: GHSA, advisory_state: 'draft' }, + advisory_read: { ghsa_id: GHSA, public_key: READER.spki }, advisory_list: { public_key: READER.spki }, + advisory_note: { ghsa_id: GHSA, sealed_note: NOTE_SEALED }, advisory_rewrite: { ghsa_id: GHSA, sealed_note: REWRITE_SEALED }, advisory_severity: { ghsa_id: GHSA, severity: 'high' }, + }; + const others = OP_NAMES.filter((op) => op !== 'dependabot_list'); + t('…the ledger of every other op is every op but this one, no more and no less', Object.keys(minimalOf).sort(), [...others].sort()); + const vaLine = (actions) => { + const v = validatePayload(fixturePayload({ actions })); + return v.ok ? [outputLine(v.payload, 'permission_vulnerability_alerts'), 'vulnerability-alerts' in tokenPermissionsOf(v.payload)] : `refused: ${v.errors.join(' | ')}`; + }; + t("⛔ NO OTHER STROKE'S MINT GAINS IT: every other op writes an EMPTY permission_vulnerability_alerts and its token map lacks vulnerability-alerts — each alone in its stroke, and the stroke of them all that shares one token", [others.filter((op) => JSON.stringify(vaLine([{ op, ...minimalOf[op] }])) !== JSON.stringify(['permission_vulnerability_alerts=', false])), vaLine(others.filter((op) => !OPS[op].secondRepo && !OPS[op].alone).map((op) => ({ op, ...minimalOf[op] })))], [[], ['permission_vulnerability_alerts=', false]]); + const repoRoot = resolve(SELF_PATH, '../../../..'); + const workflowText = readFileSync(resolve(repoRoot, '.github/workflows/fleet-write.yml'), 'utf8'); + t("⛔ the workflow mints permission-vulnerability-alerts ONCE, from the validator's permission_vulnerability_alerts output — never as a literal, which would mint it for every stroke — and names no alert path", [[...workflowText.matchAll(/^\s+permission-vulnerability-alerts:\s*\$\{\{\s*steps\.validate\.outputs\.permission_vulnerability_alerts\s*\}\}\s*$/gm)].length, [...workflowText.matchAll(/^\s+permission-vulnerability-alerts:/gm)].length, /^\s+permission-vulnerability-alerts:\s*(read|write)\s*$/m.test(workflowText), workflowText.includes('dependabot/alerts?')], [1, 1, false, false]); + // The pages. + t('the state is open alone at 100 a page, under a cap of 3 pages', [DEPENDABOT_LIST_STATE, DEPENDABOT_LIST_PAGE_SIZE, DEPENDABOT_LIST_PAGE_CAP], ['open', 100, 3]); + t("each page's path is the alerts collection, the open state, the page size and at most one encoded cursor — in the page shape, caught by no refused family; the call prints the state, never a cursor", [dependabotListPagePath(REPO), dependabotListPagePath(REPO, 'Y3Vy+c29y/OnYy=='), [dependabotListPagePath(REPO), dependabotListPagePath(REPO, 'A'.repeat(ADVISORY_LIST_CURSOR_MAX_CHARS)), dependabotListPagePath(REPO, 'Y3Vy+c29y/OnYy==')].every((path) => DEPENDABOT_LIST_PAGE_PATH_SHAPE.test(path) && !REFUSED_PATH_FAMILIES.some((re) => re.test(path))), dependabotListCall(REPO)], [`/repos/${REPO}/dependabot/alerts?state=open&per_page=100`, `/repos/${REPO}/dependabot/alerts?state=open&per_page=100&after=Y3Vy%2Bc29y%2FOnYy%3D%3D`, true, `GET /repos/${REPO}/dependabot/alerts?state=open&per_page=100`]); + // ⛔ Every other Dependabot path stays refused: the family's negative lookahead admits the collection and its page shape alone. + const tails = ['alerts/7', 'alerts/7/', 'alerts?state=dismissed&per_page=100', 'alerts?state=open', 'alerts?state=open&per_page=100&after=a b', 'alerts?state=open&per_page=100&page=2', 'alerts/', 'secrets', 'secrets/public-key', 'secrets/X', 'alerts?state=open&per_page=100&after=abc&x=1']; + t('⛔ every other Dependabot path is caught by a refused family — one alert, its PATCH path, another state, no page size, a cursor off its shape, a page number, a trailing slash, the secrets endpoints and a tail — while the collection and its page shape are caught by none', [tails.filter((tail) => !REFUSED_PATH_FAMILIES.some((re) => re.test(`/repos/${REPO}/dependabot/${tail}`))), [`/repos/${REPO}/dependabot/alerts`, dependabotListPagePath(REPO), dependabotListPagePath(REPO, 'abc')].map((path) => REFUSED_PATH_FAMILIES.filter((re) => re.test(path)).length), DEPENDABOT_LIST_PAGE_PATH_SHAPE.test(`/repos/${REPO}/dependabot/alerts?state=dismissed&per_page=100`)], [[], [0, 0, 0], false]); + // The cursor. + const own = (after) => `${API}/repos/${REPO}/dependabot/alerts?state=open&per_page=100&after=${encodeURIComponent(after)}`; + const REPO_ID = '4242'; + const ctx = { api: API, repo: REPO, repoId: REPO_ID }; + t('⭐ the next cursor: from the one rel="next" link on this API\'s alerts collection and the open state, decoded — and no rel="next", an empty header or none at all ends the walk', [dependabotListNextCursor(`<${own('Y3Vy+c29y/OnYy==')}>; rel="next", <${API}/repos/${REPO}/dependabot/alerts?state=open&per_page=100>; rel="first"`, ctx), dependabotListNextCursor(`<${own('abc')}>; rel="prev"`, ctx), dependabotListNextCursor('', ctx), dependabotListNextCursor(null, ctx), dependabotListNextCursor(`<${own('abc')}>; REL="Next"`, ctx)], [{ after: 'Y3Vy+c29y/OnYy==' }, { after: null }, { after: null }, { after: null }, { after: 'abc' }]); + const refusedLinks = [ + `<${own('abc').replace('https://api.github.com', 'https://evil.test')}>; rel="next"`, + `<${own('abc').replace('https://', 'http://')}>; rel="next"`, + `; rel="next"`, + `; rel="next"`, + `; rel="next"`, + `; rel="next"`, + `; rel="next"`, + `; rel="next"`, + `<${own('abc').replace(`/repos/${REPO}/`, `/repos/${TARGET_OWNER}/objectui/`)}>; rel="next"`, + `<${own('abc').replace('alerts?', 'alerts/7?')}>; rel="next"`, + `<${API}/repos/${REPO}/dependabot/alerts?per_page=100&after=abc>; rel="next"`, + `<${own('abc')}&state=fixed>; rel="next"`, + `<${API}/repos/${REPO}/dependabot/alerts?state=open&per_page=100>; rel="next"`, + `<${own('abc')}&after=def>; rel="next"`, + `<${own('a'.repeat(ADVISORY_LIST_CURSOR_MAX_CHARS + 1))}>; rel="next"`, + `<${own(`${MARKER} x`)}>; rel="next"`, + `<${own('abc')}>; rel="next", <${own('def')}>; rel="next"`, + `; rel="next"`, + ]; + t('⛔ every other next link is FAILED, with the one sentence: another host, plain http, ANOTHER repository id, a trailing slash, another collection, a leading zero, another state, a page with no cursor, another repository, one alert, no state, two states, no cursor, two cursors, an over-long cursor, a cursor outside its shape, two next links, an unparsable URL and a header that is no string', [...refusedLinks, 17].map((link) => dependabotListNextCursor(link, ctx)), [...refusedLinks, 17].map(() => ({ fail: DEPENDABOT_LIST_CURSOR_REFUSED }))); + const CURSOR_REAL = 'Y3Vyc29yOnYyOpK0+Zm9v/YmFy=='; + const realNext = `; rel="next"`; + const noId = { api: API, repo: REPO }; + t("⭐ the numeric next link — the collection by the repository's id — is followed on its decoded cursor when the id is the repository's own; with no id read the rule asks for it, and never takes the link's; off the state or the cursor shape it is refused outright, no read", [dependabotListNextCursor(realNext, ctx), dependabotListNextCursor(realNext, noId), dependabotListNextCursor(realNext, { ...ctx, repoId: '4243' }), dependabotListNextCursor(realNext.replace('state=open', 'state=fixed'), noId), dependabotListNextCursor(realNext.replace(/after=[^&]*/, 'after=a%20b'), noId)], [{ after: CURSOR_REAL }, { needsRepoId: true }, { fail: DEPENDABOT_LIST_CURSOR_REFUSED }, { fail: DEPENDABOT_LIST_CURSOR_REFUSED }, { fail: DEPENDABOT_LIST_CURSOR_REFUSED }]); + const shapeLinks = [...refusedLinks, realNext.replace(/after=[^&]*/, `after=${encodeURIComponent(`${MARKER} ${CURSOR_REAL}`)}`), realNext.replace('&page=2', `&${encodeURIComponent(MARKER)}=1`), 17, '', null]; + const shapes = shapeLinks.map((link) => dependabotListLinkShape(link, ctx)); + const [owner, name] = REPO.split('/'); + const leaks = shapes.filter((text) => [CURSOR_REAL, encodeURIComponent(CURSOR_REAL), 'abc', 'def', REPO_ID, owner, name, 'objectui', 'evil.test', 'api.github.com', 'dismissed', 'fixed', MARKER, 'aaaa'].some((v) => text.includes(v))); + t('⛔ the refusal diagnostic prints the SHAPE alone — no cursor, id, owner, name, host, state or marker — and pinned on the real numeric shape', [shapes.length, leaks, dependabotListLinkShape(realNext, { ...ctx, repoId: '4243' })], [shapeLinks.length, [], 'link shape: 1 rel="next" link(s); on the relay\'s API origin; path /repositories/ID/dependabot/alerts (ID another repository\'s); query names [per_page,state,after,page]; state the walk\'s; after in its shape'], leaks.join(' | ')); + // A page's fences. + const alert = (extra = {}) => ({ + number: 7, state: 'open', html_url: `https://github.test/${MARKER}`, url: MARKER, + dependency: { package: { ecosystem: 'npm', name: 'left-pad' }, manifest_path: 'pnpm-lock.yaml', scope: 'runtime' }, + security_advisory: { ghsa_id: GHSA, cve_id: MARKER, summary: MARKER, description: MARKER, severity: 'high' }, + security_vulnerability: { package: { ecosystem: 'npm', name: 'left-pad' }, severity: 'high', vulnerable_version_range: '< 1.3.1', first_patched_version: { identifier: '1.3.1' } }, + created_at: '2026-11-01T00:00:00Z', dismissed_reason: MARKER, dismissed_comment: MARKER, + ...extra, + }); + const page = (json, status = 200) => ({ status, json }); + const ITEM = 'a page of the listing lists an item that is not an alert in the state the page asked for'; + const pageFails = [page([alert()]), page([]), page({ message: 'Not Found' }, 404), page({ message: 'Resource not accessible by integration' }, 403), page({}), page(null), page([alert({ state: 'dismissed' })]), page([alert({ state: 'fixed' })]), page([alert({ number: 0 })]), page([alert({ number: '7' })]), page([alert({ number: undefined })]), page(['x']), page([[alert()]])].map((pg) => dependabotListPageFailure(pg)); + t('⛔ a page holds only as 200 with a list of open alerts each carrying a positive integer number — an empty list among them; a refusal, a non-list, a dismissed or fixed alert, a zero, string or missing number and an item that is no object each fail, naming the status alone', pageFails, [null, null, 'a page of the listing answered HTTP 404', 'a page of the listing answered HTTP 403', 'a page of the listing answered HTTP 200 with no list', 'a page of the listing answered HTTP 200 with no list', ...Array.from({ length: 7 }, () => ITEM)]); + const sv = (patch) => alert({ security_vulnerability: { ...alert().security_vulnerability, ...patch } }); + const dep = (patch) => alert({ dependency: { ...alert().dependency, ...patch } }); + const pkg = (patch) => dep({ package: { ...alert().dependency.package, ...patch } }); + const fieldCases = [ + [sv({ severity: 'critical' }), null], [dep({ scope: null }), null], [dep({ scope: undefined }), null], [sv({ first_patched_version: null }), null], + [sv({ severity: 'HIGH' }), ['severity']], [sv({ severity: { level: MARKER } }), ['severity']], [sv({ severity: null }), ['severity']], + [pkg({ ecosystem: '' }), ['ecosystem']], [pkg({ name: 'x'.repeat(DEPENDABOT_LIST_STRING_CAPS.package + 1) }), ['package']], [pkg({ name: 7 }), ['package']], + [dep({ manifest_path: ['a'] }), ['manifest_path']], [dep({ scope: 'optional' }), ['scope']], [sv({ vulnerable_version_range: null }), ['vulnerable_version_range']], + [sv({ first_patched_version: '1.3.1' }), ['first_patched_version']], [sv({ first_patched_version: { identifier: null } }), ['first_patched_version']], + [alert({ security_advisory: { ghsa_id: MARKER } }), ['ghsa_id']], [alert({ security_advisory: null }), ['ghsa_id']], + [alert({ dependency: null }), ['ecosystem', 'package', 'manifest_path']], + [alert({ security_vulnerability: undefined }), ['severity', 'vulnerable_version_range', 'first_patched_version']], + ]; + const fieldFails = fieldCases.map(([it]) => dependabotListPageFailure(page([alert(), it]))); + t("⛔ a page holds only when every alert's fields are of their declared shapes — a severity of the platform's four, a capped non-empty ecosystem, package and manifest path, a scope of development, runtime, null or absent, a capped range, a patched version null or an object with a capped identifier, a GHSA id in its shape; each failure names EVERY failing field in the declared order and echoes no value", [DEPENDABOT_LIST_FIELD_SHAPES.map((x) => x.field), [...DEPENDABOT_LIST_SEVERITIES], [...DEPENDABOT_LIST_SCOPES], fieldFails, fieldFails.some((x) => x !== null && /DEPENDABOT LIST MARKER|HIGH|optional|left-pad|1\.3\.1|xxxx/.test(x))], [['severity', 'ecosystem', 'package', 'manifest_path', 'scope', 'vulnerable_version_range', 'first_patched_version', 'ghsa_id'], ['critical', 'high', 'medium', 'low'], ['development', 'runtime'], fieldCases.map(([, want]) => (want === null ? null : dependabotListFieldSentence(want))), false]); + // The projection. + const json = dependabotListPlaintext([alert(), alert({ number: 9, dependency: { package: { ecosystem: 'pip', name: 'requests' }, manifest_path: 'requirements.txt' } }), sv({ first_patched_version: null })]); + t("⭐ projected BEFORE the seal: exactly the ten fields, in order, as the platform answered them — no URL, CVE, summary, description, dismissal or date, and the marker nowhere in the plaintext; the patched version crosses as its identifier or null; an absent scope stays absent, never invented; the count beside the alerts", [[...DEPENDABOT_LIST_FIELDS], Object.keys(dependabotListProjection(alert())), json.includes(MARKER), JSON.parse(json)], [['number', 'state', 'severity', 'ecosystem', 'package', 'manifest_path', 'scope', 'vulnerable_version_range', 'first_patched_version', 'ghsa_id'], ['number', 'state', 'severity', 'ecosystem', 'package', 'manifest_path', 'scope', 'vulnerable_version_range', 'first_patched_version', 'ghsa_id'], false, { count: 3, alerts: [{ number: 7, state: 'open', severity: 'high', ecosystem: 'npm', package: 'left-pad', manifest_path: 'pnpm-lock.yaml', scope: 'runtime', vulnerable_version_range: '< 1.3.1', first_patched_version: '1.3.1', ghsa_id: GHSA }, { number: 9, state: 'open', severity: 'high', ecosystem: 'pip', package: 'requests', manifest_path: 'requirements.txt', vulnerable_version_range: '< 1.3.1', first_patched_version: '1.3.1', ghsa_id: GHSA }, { number: 7, state: 'open', severity: 'high', ecosystem: 'npm', package: 'left-pad', manifest_path: 'pnpm-lock.yaml', scope: 'runtime', vulnerable_version_range: '< 1.3.1', first_patched_version: null, ghsa_id: GHSA }] }]); + // The pad: one sealed size whatever the count, the advisory listing's own. + const typical = (k) => alert({ number: 100000 + k, dependency: { package: { ecosystem: 'npm', name: `@objectstack/package-${k}` }, manifest_path: 'packages/some-package/package.json', scope: 'development' } }); + let fits = 0; + while (advisoryListPadded(dependabotListPlaintext(Array.from({ length: fits + 1 }, (_, k) => typical(k)))) !== null) fits++; + const aad = advisorySealAad({ requestId: 'fw-20261204T000000Z-abc123', action: 1, op: 'dependabot_list' }); + const sealedFor = (n) => sealAdvisoryRead({ plaintext: advisoryListPadded(dependabotListPlaintext(Array.from({ length: n }, (_, k) => typical(k)))), publicKey: READER.spki, aad }); + const sizes = [0, 1, fits].map((n) => { + const sealed = sealedFor(n); + return [sealed.length, advisoryReadParts(sealed)?.length, JSON.parse(openAdvisoryRead({ sealed, privateKey: READER.privateKey, aad })).count]; + }); + t(`⭐ the pad: zero, one and the most that fit (${fits} of a typical fake alert, ${Buffer.byteLength(JSON.stringify(dependabotListProjection(typical(0))))} bytes each) seal to ONE length — 40,000 characters in 10 parts — opening to their own count; one more is refused, so nothing is emitted; the size is the advisory listing's`, [DEPENDABOT_LIST_PADDED_BYTES, sizes, fits >= 100], [ADVISORY_LIST_PADDED_BYTES, [[40000, 10, 0], [40000, 10, 1], [40000, 10, fits]], true]); + // The associated data. + const RID = 'fw-20261204T000000Z-abc123'; + const opensUnder = (sealed, under) => { + try { + openAdvisoryRead({ sealed, privateKey: READER.privateKey, aad: under }); + return 'opened'; + } catch (e) { + return e.message === ADVISORY_READ_OPEN_FAILED ? 'refused' : `threw: ${e.message}`; + } + }; + const sealedOne = sealedFor(1); + t("⛔ its own associated data binds the request id, the action and the op: it opens under its own, and never under another request, another action, or the advisory listing's for the same request and action", [advisorySealAad({ requestId: RID, action: 2, op: 'dependabot_list' }).toString('utf8'), opensUnder(sealedOne, aad), opensUnder(sealedOne, advisorySealAad({ requestId: 'fw-20261204T000000Z-abc124', action: 1, op: 'dependabot_list' })), opensUnder(sealedOne, advisorySealAad({ requestId: RID, action: 2, op: 'dependabot_list' })), opensUnder(sealedOne, advisorySealAad({ requestId: RID, action: 1, op: 'advisory_list' }))], [`fleet-write:advisory_read:v1 request=${RID} action=2 op=dependabot_list`, 'opened', 'refused', 'refused', 'refused']); + // The sentences. + const sentences = [DEPENDABOT_LIST_LANDED, DEPENDABOT_LIST_OVER_CAP, DEPENDABOT_LIST_CAP_HIT, DEPENDABOT_LIST_REPEATED, DEPENDABOT_LIST_SENDER_REFUSED, DEPENDABOT_LIST_UNREACHED, DEPENDABOT_LIST_CURSOR_REFUSED, DEPENDABOT_LIST_SHORT_PAGE_NEXT, DEPENDABOT_LIST_ACCESS_REMEDY, ...pageFails.filter(Boolean), ...fieldFails.filter(Boolean)]; + t('⛔ every sentence a listing prints names no GHSA id, no package, no severity word, no digit but its own caps and statuses, and no marker — the landed row says it landed and nothing more', [sentences.filter((x) => /GHSA|left-pad|\b(?:critical|high|medium|low|dismissed|fixed)\b|DEPENDABOT LIST MARKER/.test(x)), DEPENDABOT_LIST_LANDED, sentences.flatMap((x) => x.match(/\d+/g) ?? []).filter((d) => !['3', '29939', '10', '200', '404', '403'].includes(d))], [[], "sealed the Dependabot alerts listing to the seat's one-time key, padded to the run's full notice size so its length says nothing — only that seat's process opens it", []]); + } + // ── advisory_note: the one row that appends to an advisory, sealed inbound ───────────── battery("advisory_note: ghsa_id and sealed_note alone — the note its own kind, ciphertext of a capped length in canonical base64url, refused before any request and never echoed or opened here; ONE PATCH of one advisory whose body is the executor's; a stroke of its own minting repository-advisories write and marked advisory_note=yes, EMPTY for every other; the workflow handing the relay's note key to the execute step for that stroke alone, and no artifact; the seal opening for its own request, action, advisory and key alone and never as a read; the key judged against the committed half; the fences, the description, the read-back and the keyed digest, printing no byte of either text"); {