diff --git a/config/ci/contract-baseline.json b/config/ci/contract-baseline.json index 66397689..8b63dfd9 100644 --- a/config/ci/contract-baseline.json +++ b/config/ci/contract-baseline.json @@ -1,11 +1,11 @@ { "schemaVersion": 1, - "owner": "frontend-platform", - "reason": "U7: FE-GATE-020 runs test:feature-scaffold, which creates a feature with create:feature in a copy and runs the merge gates on it", + "owner": "DongHyeonka", + "reason": "1103/13-03: FE-GATE-027 also runs scan:dependency-advisories, a non-blocking release-stage advisory signal", "gates": 27, - "commands": 99, - "commandReferences": 103, + "commands": 100, + "commandReferences": 104, "artifacts": 110, "stages": 5, - "gateShapeSha256": "02e87e35b87fbc5114af7e1b1ce1ec030062c60ae8bd03c151f1ec9538f2db3b" + "gateShapeSha256": "6225494d6447a2065d921a34597a744d180a7a68e601119e32f8fc42e18eb1c1" } diff --git a/config/ci/gates.json b/config/ci/gates.json index 4dfb4a39..46a4d27f 100644 --- a/config/ci/gates.json +++ b/config/ci/gates.json @@ -595,6 +595,11 @@ "id": "check-release-admission", "script": "check:release-admission", "expect": "pass" + }, + { + "id": "scan-dependency-advisories", + "script": "scan:dependency-advisories", + "expect": "pass" } ], "artifactSchemas": [ @@ -2200,7 +2205,8 @@ "id": "FE-GATE-027", "name": "release-admission", "commandIds": [ - "check-release-admission" + "check-release-admission", + "scan-dependency-advisories" ], "logArtifactId": "artifact-artifacts-quality-gates-FE-GATE-027-txt", "evidenceArtifactIds": [ diff --git a/docs/operations/ci-quality-gates.md b/docs/operations/ci-quality-gates.md index 63634d0f..2fbbbfc7 100644 --- a/docs/operations/ci-quality-gates.md +++ b/docs/operations/ci-quality-gates.md @@ -476,6 +476,18 @@ Repository variables required by higher tiers: job runs FE-GATE-015 and then FE-GATE-027, and FE-GATE-027 refuses the candidate when `APP_PROFILE` is set and differs from `RELEASE_TARGET`. Both are repository-wide variables, so set them together for each release. + FE-GATE-027 then runs `scan:dependency-advisories` (1103/13-03). It applies + `config/security/vulnerability-policy.json` and its exceptions to the + registry's advisory report for the lockfile (pnpm's audit command with + `--json`) and writes the result to the gate log + and `artifacts/security/dependency-advisories.json`: `PASS`, + `POLICY_VIOLATION` (what the production promotion would refuse, with the + findings) or `UNVERIFIED` (no registry). It never fails the gate, because an + advisory database that changes under unchanged code would break releases; + the signed verdict of the vulnerability provider still decides promotion. + `renovate.json` opens security update PRs once a Renovate runner is attached; + a dependency update re-approves the dependency baseline in the same change + (`update:dependency-baseline`). - `FIELD_WEB_VITALS_INPUT` for the privacy-approved field sample document - `MIN_ELIGIBLE_SAMPLES` after the baseline decision - `VULNERABILITY_PROVIDER_COMMAND` and `PROVENANCE_PROVIDER_COMMAND` for the @@ -484,6 +496,17 @@ Repository variables required by higher tiers: `PROVENANCE_PUBLIC_KEY_PATH`, and `PROVENANCE_KEY_ID` for separately managed trusted Ed25519 verification material +Advisories at or above the policy's `high` that `scan:dependency-advisories` +reports for this lockfile, checked 2026-11-04 (review 1103/13-03). Check again +by 2026-12-04 or when the update below is made. The development-only ones +(storybook, vite, vitest, undici, brace-expansion, nanoid, source-map-js) were +updated within their declared ranges and are gone. + +| Advisory | Package | Fixed in | Why it is not updated yet | +|---|---|---|---| +| GHSA-mrhx-c7xc-m3w5 (high) | `zod` 4.4.3 (production) | 4.6.6 | A direct production upgrade needs a `config/security/dependency-change-evidence.json` entry whose reviewer is not its owner. 4.6.7 also adds about 7 KB gzip of initial JavaScript, over the bundle budget, so the update needs a budget decision as well. The app reads HTTP bodies with a byte limit, which narrows the large-collection input the advisory needs (review estimate) | +| GHSA-qwww-vcr4-c8h2 (high) | `react-router` 7.18.1, through `react-router-dom` (production) | 7.18.2 | Same evidence rule. The advisory concerns RSC mode, which this browser-router SPA does not use (review estimate, not verified). 7.18.5 adds about 470 B of initial JavaScript | + 두 provider role은 서로 다른 key ID뿐 아니라 canonical DER-SPKI public-key bytes도 사용해야 한다. 동일 key를 서로 다른 ID로 재등록한 구성도 finalizer가 거절한다. diff --git a/package.json b/package.json index e3d6dcff..e9e05a39 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "check:adapter-inventory": "node scripts/check-adapter-inventory.ts", "check:remediation-ledger": "node scripts/check-remediation-ledger.ts", "check:release-admission": "node scripts/generate-product-feature-index.ts && node scripts/check-release-admission.ts", + "scan:dependency-advisories": "node scripts/scan-dependency-advisories.ts", "check:diagnostics": "node scripts/generate-product-feature-index.ts && node scripts/check-diagnostics.ts", "check:diagnostics:fixture": "node scripts/generate-product-feature-index.ts && node scripts/check-diagnostics.ts --fixture", "check:types": "corepack pnpm check:types:app && corepack pnpm check:types:node && corepack pnpm check:types:test && corepack pnpm check:types:recipes && corepack pnpm check:types:web-worker && corepack pnpm check:types:service-worker", diff --git a/renovate.json b/renovate.json new file mode 100644 index 00000000..a09a6ea3 --- /dev/null +++ b/renovate.json @@ -0,0 +1,37 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "description": [ + "Review 1103/13-03: dependency security updates. The template had no update automation, so a known advisory stayed in every copy until someone ran pnpm audit by hand.", + "Inert until a Renovate runner is attached to the Gitea instance; the release-stage signal is `corepack pnpm scan:dependency-advisories` (FE-GATE-027).", + "Renovate regenerates pnpm-lock.yaml. A maintainer re-approves the dependency baseline in the same PR (`DEPENDENCY_BASELINE_OWNER=... DEPENDENCY_BASELINE_REASON=... corepack pnpm update:dependency-baseline`) and reviews the inventory diff before the PR can merge.", + "Versions stay exact (pnpm-workspace.yaml saveExact) and a release must be a day old, the pnpm minimumReleaseAge default." + ], + "extends": [ + "config:recommended", + "security:only-security-updates" + ], + "rangeStrategy": "pin", + "minimumReleaseAge": "1 day", + "vulnerabilityAlerts": { + "description": "A vulnerability alert opens a security PR at once, ignoring the schedule.", + "enabled": true, + "labels": [ + "security", + "dependencies" + ] + }, + "osvVulnerabilityAlerts": true, + "packageRules": [ + { + "description": "Every update is reviewed and merged by a person after the merge gates pass.", + "matchUpdateTypes": [ + "patch", + "pin", + "digest", + "minor", + "major" + ], + "automerge": false + } + ] +} diff --git a/scripts/lib/dependency-advisories.ts b/scripts/lib/dependency-advisories.ts new file mode 100644 index 00000000..083540be --- /dev/null +++ b/scripts/lib/dependency-advisories.ts @@ -0,0 +1,100 @@ +import { validateVulnerabilityReport } from "./supply-chain.ts"; + +/** + * 1103/13-03. The vulnerability verdict belongs to the external provider of + * the production promotion (signed, independent of the build). Without a + * provider nothing told the project that its lockfile already broke the + * template's own policy (high and above, no exception). This summary is the + * early signal: it reads `pnpm audit --json` and applies that policy, so it + * names what the promotion would refuse. It does not replace the provider and + * blocks nothing. + */ +export type AdvisoryStatus = "PASS" | "POLICY_VIOLATION" | "UNVERIFIED"; +type Severity = "critical" | "high" | "moderate" | "low" | "info"; +type SeverityCounts = Record; + +export type DependencyAdvisorySummary = Readonly<{ + status: AdvisoryStatus; + reason: string | null; + counts: Readonly<{ production: SeverityCounts; development: SeverityCounts }>; + /** Findings the vulnerability policy would block at promotion: `id:package@version:severity`. */ + blocking: readonly string[]; + advisories: readonly Readonly<{ + id: string; + packageName: string; + versions: readonly string[]; + severity: string; + development: boolean; + patchedVersions: string; + }>[]; +}>; + +const SEVERITIES: readonly Severity[] = ["critical", "high", "moderate", "low", "info"]; + +function isRecord(value: unknown): value is Record { + return Boolean(value) && typeof value === "object" && !Array.isArray(value); +} + +function emptyCounts(): SeverityCounts { + return { critical: 0, high: 0, moderate: 0, low: 0, info: 0 }; +} + +export function summarizeDependencyAdvisories( + audit: unknown, + policy: Readonly>, + exceptions: Readonly>, + lockfileSha256: string, + now: Date = new Date(), +): DependencyAdvisorySummary { + const counts = { production: emptyCounts(), development: emptyCounts() }; + if (!isRecord(audit) || !isRecord(audit["advisories"]) || !isRecord(audit["metadata"])) { + return { + status: "UNVERIFIED", + reason: "pnpm audit returned no advisory report (network or registry unavailable)", + counts, + blocking: [], + advisories: [], + }; + } + const advisories = Object.values(audit["advisories"]).filter(isRecord).map((advisory) => { + const findings = Array.isArray(advisory["findings"]) ? advisory["findings"].filter(isRecord) : []; + return { + id: String(advisory["github_advisory_id"] ?? advisory["id"] ?? "unknown"), + packageName: String(advisory["module_name"] ?? "unknown"), + versions: findings.map((finding) => String(finding["version"] ?? "unknown")), + severity: String(advisory["severity"] ?? "unknown").toLowerCase(), + // A package reached only through development dependencies never ships. + development: findings.length > 0 && findings.every((finding) => finding["dev"] === true), + patchedVersions: String(advisory["patched_versions"] ?? ""), + }; + }); + for (const advisory of advisories) { + const scope = advisory.development ? counts.development : counts.production; + if ((SEVERITIES as readonly string[]).includes(advisory.severity)) scope[advisory.severity as Severity] += 1; + } + const verdict = validateVulnerabilityReport( + { + provider: "pnpm-audit (local, not the promotion provider)", + scannedLockfileSha256: lockfileSha256, + findings: advisories.flatMap((advisory) => + advisory.versions.map((version) => ({ + id: advisory.id, + packageName: advisory.packageName, + version, + severity: advisory.severity, + })), + ), + }, + policy, + exceptions, + lockfileSha256, + now, + ); + return { + status: verdict.blocking.length > 0 ? "POLICY_VIOLATION" : "PASS", + reason: null, + counts, + blocking: verdict.blocking, + advisories, + }; +} diff --git a/scripts/scan-dependency-advisories.ts b/scripts/scan-dependency-advisories.ts new file mode 100644 index 00000000..dc5a8fdf --- /dev/null +++ b/scripts/scan-dependency-advisories.ts @@ -0,0 +1,77 @@ +import { spawnSync } from "node:child_process"; +import { createHash } from "node:crypto"; +import { mkdir, readFile, writeFile } from "node:fs/promises"; + +import { summarizeDependencyAdvisories } from "./lib/dependency-advisories.ts"; + +/** + * 1103/13-03. Release-stage signal for known dependency advisories + * (FE-GATE-027, next to the release admission of the candidate). It runs + * `pnpm audit --json` over the lockfile and applies + * config/security/vulnerability-policy.json with its exceptions, the policy the + * production promotion provider is held to. The result is a line in the gate + * log and artifacts/security/dependency-advisories.json. + * + * It never fails the gate. An advisory database that changes under unchanged + * code would otherwise break a release run, and without the registry the + * result is UNVERIFIED, not PASS. The signed verdict of the vulnerability + * provider stays the only one that decides a promotion. + */ +const RECORD_PATH = "artifacts/security/dependency-advisories.json"; + +const [policy, exceptions, lockfile] = await Promise.all([ + readFile("config/security/vulnerability-policy.json", "utf8").then((text) => JSON.parse(text) as Record), + readFile("config/security/vulnerability-exceptions.json", "utf8").then((text) => JSON.parse(text) as Record), + readFile("pnpm-lock.yaml"), +]); +const lockfileSha256 = createHash("sha256").update(lockfile).digest("hex"); + +// pnpm audit exits 1 when it finds advisories; the JSON on stdout is the result. +const run = spawnSync("corepack", ["pnpm", "audit", "--json"], { + encoding: "utf8", + maxBuffer: 64 * 1024 * 1024, + timeout: 120_000, +}); +let audit: unknown; +try { + audit = JSON.parse(run.stdout ?? ""); +} catch { + audit = null; +} +const summary = summarizeDependencyAdvisories(audit, policy, exceptions, lockfileSha256); + +await mkdir("artifacts/security", { recursive: true }); +await writeFile( + RECORD_PATH, + `${JSON.stringify( + { + schemaVersion: 1, + generatedAt: new Date().toISOString(), + source: "pnpm audit --json", + authoritative: false, + lockfileSha256, + blockAtSeverity: policy["blockAtSeverity"] ?? null, + ...summary, + }, + null, + 2, + )}\n`, +); + +const count = (scope: Readonly>) => + `critical ${scope["critical"]}, high ${scope["high"]}, moderate ${scope["moderate"]}, low ${scope["low"]}`; +process.stdout.write( + `Dependency advisories: ${summary.status} (production: ${count(summary.counts.production)}; ` + + `development: ${count(summary.counts.development)}); record at ${RECORD_PATH}. ` + + "Not blocking: the production promotion provider decides.\n", +); +if (summary.status === "POLICY_VIOLATION") { + process.stderr.write( + `WARNING: the vulnerability policy (block at ${String(policy["blockAtSeverity"])}) would refuse this lockfile at production promotion:\n` + + summary.blocking.map((finding) => ` ${finding}\n`).join("") + + "Update the dependency or record a reviewed exception in config/security/vulnerability-exceptions.json.\n", + ); +} +if (summary.status === "UNVERIFIED") { + process.stderr.write(`WARNING: dependency advisories UNVERIFIED: ${summary.reason}\n`); +} diff --git a/tests/unit/ci-workflow-generation.test.ts b/tests/unit/ci-workflow-generation.test.ts index ea0d5866..36b62591 100644 --- a/tests/unit/ci-workflow-generation.test.ts +++ b/tests/unit/ci-workflow-generation.test.ts @@ -195,8 +195,8 @@ describe("CI gate contract", () => { ).filter((gateId) => gateId !== "FE-GATE-016"), ); expect(contract.jobs).toHaveLength(10); - expect(contract.commands).toHaveLength(99); - expect(contract.gates.reduce((total, gate) => total + gate.commandIds.length, 0)).toBe(103); + expect(contract.commands).toHaveLength(100); + expect(contract.gates.reduce((total, gate) => total + gate.commandIds.length, 0)).toBe(104); expect(contract.commands.filter(({ expect }) => expect === "fail")).toHaveLength(30); expect(contract.gates.reduce((total, gate) => total + gate.evidenceArtifactIds.length, 0)).toBe(88); expect(contract.artifacts).toHaveLength(110); diff --git a/tests/unit/dependency-advisories.test.ts b/tests/unit/dependency-advisories.test.ts new file mode 100644 index 00000000..a0f51329 --- /dev/null +++ b/tests/unit/dependency-advisories.test.ts @@ -0,0 +1,111 @@ +import { readFile } from "node:fs/promises"; + +import { describe, expect, it } from "vitest"; + +import { summarizeDependencyAdvisories } from "../../scripts/lib/dependency-advisories.ts"; + +/** + * 1103/13-03. The lockfile broke the template's own vulnerability policy + * (high and above, no exception) and nothing said so before the production + * promotion provider, which a template copy may not have. The summary applies + * that policy to `pnpm audit --json`. + */ +const POLICY = { blockAtSeverity: "high" }; +const NO_EXCEPTIONS = { schemaVersion: 1, exceptions: [] }; +const LOCKFILE = "a".repeat(64); + +const advisory = ( + id: string, + module: string, + severity: string, + findings: readonly Readonly<{ version: string; dev: boolean }>[], +) => ({ + github_advisory_id: id, + module_name: module, + severity, + patched_versions: ">=9.9.9", + findings: findings.map((finding) => ({ ...finding, paths: [`.>${module}`] })), +}); +const audit = (...advisories: ReturnType[]) => ({ + advisories: Object.fromEntries(advisories.map((entry, index) => [String(index), entry])), + metadata: { vulnerabilities: {} }, +}); + +describe("dependency advisory summary (1103/13-03)", () => { + it("names what the policy would block at promotion, in production and development", () => { + const summary = summarizeDependencyAdvisories( + audit( + advisory("GHSA-prod-high", "zod", "high", [{ version: "4.4.3", dev: false }]), + advisory("GHSA-dev-critical", "storybook", "critical", [{ version: "10.5.4", dev: true }]), + advisory("GHSA-dev-moderate", "postcss", "moderate", [{ version: "8.5.22", dev: true }]), + ), + POLICY, + NO_EXCEPTIONS, + LOCKFILE, + ); + expect(summary.status).toBe("POLICY_VIOLATION"); + expect(summary.blocking).toEqual([ + "GHSA-prod-high:zod@4.4.3:high", + "GHSA-dev-critical:storybook@10.5.4:critical", + ]); + expect(summary.counts.production).toMatchObject({ high: 1, critical: 0 }); + expect(summary.counts.development).toMatchObject({ critical: 1, moderate: 1 }); + }); + + it("passes when nothing reaches the blocking severity", () => { + const summary = summarizeDependencyAdvisories( + audit(advisory("GHSA-dev-moderate", "postcss", "moderate", [{ version: "8.5.22", dev: true }])), + POLICY, + NO_EXCEPTIONS, + LOCKFILE, + ); + expect(summary).toMatchObject({ status: "PASS", blocking: [] }); + }); + + it("honours a valid exception the way the promotion verdict does", () => { + const exceptions = { + schemaVersion: 1, + exceptions: [ + { + vulnerabilityId: "GHSA-prod-high", + packageName: "zod", + owner: "frontend-platform", + reviewer: "security-review", + reason: "not reachable", + expiresAt: "2027-01-01T00:00:00.000Z", + }, + ], + }; + expect( + summarizeDependencyAdvisories( + audit(advisory("GHSA-prod-high", "zod", "high", [{ version: "4.4.3", dev: false }])), + POLICY, + exceptions, + LOCKFILE, + new Date("2026-11-04T00:00:00.000Z"), + ), + ).toMatchObject({ status: "PASS", blocking: [] }); + }); + + it("is UNVERIFIED, not PASS, when the audit returned no report", () => { + for (const output of [null, {}, { error: { code: "ENOTFOUND" } }]) { + expect(summarizeDependencyAdvisories(output, POLICY, NO_EXCEPTIONS, LOCKFILE)).toMatchObject({ + status: "UNVERIFIED", + reason: expect.stringContaining("pnpm audit"), + }); + } + }); + + it("runs at release admission (FE-GATE-027) and never fails the gate by itself", async () => { + const contract = JSON.parse(await readFile("config/ci/gates.json", "utf8")) as { + gates: { id: string; commandIds: string[] }[]; + commands: { id: string; script: string }[]; + }; + const scripts = (contract.gates.find(({ id }) => id === "FE-GATE-027")?.commandIds ?? []).map( + (commandId) => contract.commands.find(({ id }) => id === commandId)?.script, + ); + expect(scripts).toEqual(["check:release-admission", "scan:dependency-advisories"]); + const source = await readFile("scripts/scan-dependency-advisories.ts", "utf8"); + expect(source).not.toMatch(/process\.exit(?:Code)?\s*(?:=|\()\s*[1-9]/u); + }); +});