diff --git a/docs/assets/readme/incident-tj-actions.json b/docs/assets/readme/incident-tj-actions.json new file mode 100644 index 00000000..f86e68d6 --- /dev/null +++ b/docs/assets/readme/incident-tj-actions.json @@ -0,0 +1,78 @@ +{ + "title": "Pin actions to a commit, not a tag", + "frames": [ + "Your repository and CI", + "The action's repo" + ], + "cards": { + "workflow": { + "name": "Workflow file", + "line": "uses: tj-actions/changed-files\n@v44.5.1", + "mono": true + }, + "job": { + "name": "CI job", + "line": "runs whatever the tag points to today" + }, + "tag": { + "name": "Tag v44.5.1", + "line": "one of the tags the advisory lists as moved to the malicious commit" + }, + "bad": { + "name": "Malicious commit", + "line": "printed CI secrets into the job logs" + }, + "fix": { + "name": "Pin it to a commit", + "line": "uses: tj-actions/changed-files@<40-hex commit SHA> # v44.5.1", + "mono": true, + "badge": "same checks: exit 0" + } + }, + "arrows": { + "tag-bad": "points to", + "workflow-fix": "instead" + }, + "diamonds": [ + { + "id": "hook", + "label": "commit hook" + }, + { + "id": "ci", + "label": "CI gate" + } + ], + "exit": "exit 1", + "key": { + "path": "the incident's path: the workflow runs whatever the tag points to", + "stopped": "never reached once a check refuses", + "acts": "a check that refuses the line" + }, + "printed_title": "What the check prints", + "printed": [ + { + "kind": "cmd", + "text": "$ git commit # tag.yml staged" + }, + { + "kind": "out", + "text": "exit 1 Unpinned GitHub Action detected: a workflow references an action by a tag or branch (owner/repo at a movable ref) rather than a full 40-character commit SHA, ..." + }, + { + "kind": "out", + "text": " - .github/workflows/changed-files.yml: content pattern" + }, + { + "kind": "cmd", + "text": "$ git commit # the same file pinned to a full commit SHA" + }, + { + "kind": "out", + "text": "exit 0" + } + ], + "limit": "A pin freezes what you pinned. If an update bot bumps it to a bad commit, that commit runs: the advisory tells anyone referencing the malicious commit by its SHA to update.", + "source": "What happened: GitHub advisory GHSA-mrrh-fwg8-r2c3 (CVE-2025-30066); CISA alert of 2025-03-18. Same line, same exit codes: rule pin-github-actions, catalog 1.2.0.", + "footer": "The example rule here is from Chock." +} diff --git a/docs/assets/readme/incident.mjs b/docs/assets/readme/incident.mjs new file mode 100644 index 00000000..9fef25fc --- /dev/null +++ b/docs/assets/readme/incident.mjs @@ -0,0 +1,78 @@ +// An incident teardown figure in the harness picture's look: cards in dashed frames, the incident's path as a line, the checks that refuse it as diamonds. Every word comes from incident-.json; positions are computed here and `layout` reports every shape so a test can check nothing overlaps. +import { DEFAULT_PALETTE } from './where-chock-sits.mjs'; + +const FW = 560, RX = 600, RW = 240, CW = 130, AW = 230, GAP = 8, ROW1 = 40; +const lines = (text, width, per = 6.4) => text.split('\n').reduce((n, t) => n + Math.max(1, Math.ceil((t.length * per) / width)), 0); +const PANEL_LINES = (D) => D.printed.reduce((n, l) => n + lines(l.text, 808, 7.4), 0); + +export const layout = (D) => { + const shapes = [], add = (id, x, y, w, h) => shapes.push({ id, x, y, w, h }); + const C = {}; + const card = (id, x, y, w) => { + const c = { ...D.cards[id], id, x, y, w }; + c.h = 12 + lines(c.name, w - 16, 8.2) * 18 + 4 + lines(c.line, w - 16, c.mono ? 7.1 : 7.8) * 16 + (c.badge ? 28 : 8); + C[id] = c; add(`card-${id}`, x, y, w, c.h); + }; + card('workflow', 16, ROW1, AW); card('job', FW - 16 - CW, ROW1, CW); card('tag', RX + 16, ROW1, RW - 32); + const row2 = ROW1 + Math.max(C.workflow.h, C.job.h, C.tag.h) + 56; + card('bad', RX + 16, row2, RW - 32); card('fix', 16, row2, FW - 32); + const rowH = Math.max(C.bad.h, C.fix.h); C.bad.h = C.fix.h = rowH; + shapes.filter((s) => s.id === 'card-bad' || s.id === 'card-fix').forEach((s) => { s.h = rowH; }); + const frameH = row2 + rowH + 24, ya = C.workflow.y + 26; + const dx = [C.workflow.x + AW + 50, C.workflow.x + AW + 126]; + const diamonds = D.diamonds.map((d, i) => ({ ...d, x: dx[i], y: ya })); + diamonds.forEach((d) => { add(`${d.id}-exit`, d.x - 24, d.y - 30, 48, 14); add(`${d.id}-name`, d.x - Math.ceil(d.label.length * 3.2), d.y + 14, Math.ceil(d.label.length * 6.4), 14); add(`${d.id}-diamond`, d.x - 5, d.y - 5, 10, 10); }); + const labels = [['tag-bad', C.tag.x + (RW - 32) / 2 + 10, (C.tag.y + C.tag.h + row2) / 2 - 7], ['workflow-fix', C.workflow.x + AW / 2 + 10, (C.workflow.y + C.workflow.h + row2) / 2 - 7]] + .map(([k, x, y]) => { const w = Math.ceil(D.arrows[k].length * 6 + 2); const lx = x; add(`label-${k}`, lx, y, w, 14); return { text: D.arrows[k], x: lx, y, w }; }); + const base = frameH + 20, panelTop = base + 140, panelH = PANEL_LINES(D) * 19 + 28; + const limitTop = panelTop + panelH + 18, sourceTop = limitTop + 48, footTop = sourceTop + 42, total = footTop + 34; + return { shapes, C, diamonds, labels, frameH, ya, base, panelTop, panelH, limitTop, sourceTop, footTop, total, height: total + 78 }; +}; + +// Shapes closer than GAP. +export const crowded = (L) => { + const bad = [], near = (a, b) => a.x < b.x + b.w + GAP && b.x < a.x + a.w + GAP && a.y < b.y + b.h + GAP && b.y < a.y + a.h + GAP; + L.shapes.forEach((a, i) => L.shapes.slice(i + 1).forEach((b) => { if (!(a.id.split('-')[0] === b.id.split('-')[0] && /-(exit|name|diamond)$/.test(a.id) && /-(exit|name|diamond)$/.test(b.id)) && near(a, b)) bad.push([a.id, b.id]); })); + return bad; +}; + +export const where = (page, D, palette = DEFAULT_PALETTE) => { + const L = layout(D), bad = crowded(L); + if (bad.length) throw new Error(`figure shapes too close: ${JSON.stringify(bad)}`); + const { ink: INK, soft: SOFT, line: LINE, paper: PAPER, accent: ACCENT, grey: GREY, chip: CHIP } = palette; + const FILL = { workflow: '#EFE9F9', job: '#DCEAF9', tag: '#E9E4F3', bad: '#F6E2EC', fix: '#DDF0EE' }; + const esc = (s) => s.replace(/&/g, '&').replace(/ `${inner}`; + const diamond = (x, y, acts, s = 10) => abs(x - s / 2, y - s / 2, s, s, `transform:rotate(45deg);box-sizing:border-box;border:2px solid ${acts ? ACCENT : GREY};background:${acts ? ACCENT : PAPER}`, ''); + const frame = (x, w, h, title) => abs(x, 0, w, h, `border:2px dashed ${LINE};border-radius:18px;box-sizing:border-box`, `
${esc(title)}
`); + const ghost = (id) => id === 'job' || id === 'tag' || id === 'bad'; + const card = (c) => abs(c.x, c.y, c.w, c.h, `box-sizing:border-box;background:${FILL[c.id]};border:1.5px ${ghost(c.id) ? 'dashed' : 'solid'} ${LINE};border-radius:12px;padding:10px 8px;${ghost(c.id) ? 'opacity:.8' : ''}`, + `
${esc(c.name)}
${esc(c.line)}
` + + (c.badge ? abs(4, c.h - 28, c.w - 8, 20, `box-sizing:border-box;display:flex;align-items:center;gap:4px;padding:0 5px;border-radius:999px;background:${CHIP};font-size:12px;font-weight:600;color:${ACCENT}`, `${diamond(5, 5, true)}${esc(c.badge)}`) : ''), true); + const { C, ya } = L, [d1, d2] = L.diamonds; + const head = (id, c) => ``; + const seg = (d, stroke, dash, marker) => ``; + const mid = (c) => c.x + c.w / 2, bt = (c) => c.y + c.h; + const paths = [seg(`M${C.workflow.x + AW} ${ya} H${d1.x - 7}`, ACCENT, false), ``, + seg(`M${d1.x + 7} ${ya} H${C.job.x}`, LINE, true, 'g'), seg(`M${C.job.x + CW} ${ya} H${C.tag.x}`, LINE, true, 'g'), + seg(`M${mid(C.tag)} ${bt(C.tag)} V${C.bad.y}`, LINE, true, 'g'), seg(`M${mid(C.workflow)} ${bt(C.workflow)} V${C.fix.y}`, LINE, false, 'g')].join(''); + const dmarks = L.diamonds.map((d) => diamond(d.x, d.y, true) + abs(d.x - 24, d.y - 30, 48, 14, `font-size:12px;font-weight:700;color:${ACCENT};text-align:center;white-space:nowrap`, esc(D.exit)) + + abs(d.x - Math.ceil(d.label.length * 3.2), d.y + 14, Math.ceil(d.label.length * 6.4), 14, `font-size:12px;font-weight:600;color:${SOFT};white-space:nowrap`, esc(d.label))).join(''); + const labels = L.labels.map((l) => abs(l.x, l.y, l.w, 14, `font-size:12px;line-height:14px;font-weight:600;color:${SOFT};white-space:nowrap`, esc(l.text))).join(''); + const key = (inner, text, y) => `
${inner}${esc(text)}
`; + const line = (stroke, dash) => ``; + const rows = D.printed.map((l) => `
${l.kind === 'out' && l.text.startsWith('exit 1') ? `exit 1${esc(l.text.slice(6))}` : esc(l.text)}
`).join(''); + return page(`
+
${esc(D.title)}
+
+${frame(0, FW, L.frameH, D.frames[0])}${frame(RX, RW, L.frameH, D.frames[1])} +${head('g', LINE)}${paths} +${Object.values(C).map(card).join('')}${dmarks}${labels} +${key(line(ACCENT, false), D.key.path, L.base)}${key(line(LINE, true), D.key.stopped, L.base + 28)}${key(`${diamond(7, 7, true, 12)}`, D.key.acts, L.base + 56)} +
${esc(D.printed_title)}
+${abs(0, L.panelTop, 840, L.panelH, `box-sizing:border-box;border:1.5px solid ${LINE};border-radius:12px;background:${CHIP};padding:14px 16px;font-size:12px;line-height:19px`, rows.replace(/
${esc(D.footer)}
+
`); +}; diff --git a/docs/assets/readme/render.mjs b/docs/assets/readme/render.mjs index 29702131..5d4e8a19 100644 --- a/docs/assets/readme/render.mjs +++ b/docs/assets/readme/render.mjs @@ -6,6 +6,7 @@ import { fileURLToPath } from 'node:url'; import path from 'node:path'; import { where, SITE_PALETTE } from './where-chock-sits.mjs'; import { where as sessionPath } from './session-path.mjs'; +import { where as incident } from './incident.mjs'; const HERE = path.dirname(fileURLToPath(import.meta.url)); const OUT = process.env.OUT_DIR || HERE; @@ -218,11 +219,12 @@ ${grid(3, 16, [['commit', 'A git hook or CI gate that exits non-zero.'], ['in-ag ${grid(3, 16, [[A.grades.enforced, 'matrix cells graded “enforced”: no agent reaches it'], [`${D.asi.refused_at_commit.length} of ${D.asi.with_policy}`, 'OWASP Agentic risks with a slice refused at commit'], [D.asi.fully_covered, 'OWASP Agentic risks fully covered: every mapping is partial']].map(([n, l]) => stat(n, l)))}`); const FIGURE = JSON.parse(readFileSync(path.join(HERE, 'where-chock-sits.json'), 'utf8')); +const TJ = incident(page, JSON.parse(readFileSync(path.join(HERE, 'incident-tj-actions.json'), 'utf8'))); const WHERE = where(page, FIGURE), WHERE_SITE = where(page, FIGURE, SITE_PALETTE), SESSION_PATH = sessionPath(page, FIGURE); const ALL_NEW = { layers: LAYERS, quickstart: QUICKSTART, matrix: MATRIX, catalog: CATALOG, family: FAMILY, honest: HONEST }; // README v2 panels go under v2/; the titled refusal, roles and contribute PNGs at the old paths stay frozen until RW-7b. -const V2 = { 'v2/refusal': REFUSAL, 'v2/roles': ROLES, 'v2/contribute': CONTRIBUTE, 'v2/where-chock-sits': WHERE, 'v2/where-chock-sits-site': WHERE_SITE, 'v2/session-path': SESSION_PATH }; +const V2 = { 'v2/refusal': REFUSAL, 'v2/roles': ROLES, 'v2/contribute': CONTRIBUTE, 'v2/where-chock-sits': WHERE, 'v2/where-chock-sits-site': WHERE_SITE, 'v2/session-path': SESSION_PATH, 'v2/incidents/tj-actions': TJ }; // 1280x640 social preview banners: the same specs as the covers, laid out for the fixed canvas. const social = ({ repo, title, sub, chips, right }) => `