Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ci/reviewed-npm-audit.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schemaVersion": 2,
"schemaVersion": 3,
"nodeVersion": "22.23.1",
"registryOrigin": "https://registry.npmjs.org/",
"severityThreshold": "high",
Expand Down Expand Up @@ -70,7 +70,10 @@
"integrity": "sha512-ge/Xss99CHAjPL/ikmH/UFoiOrjcxDB4sW3y9mhyCD+dYW3wzV7TKbAVdkrXFgAG2d2BjpJofP97zUZ+umxo8g==",
"tarballUrl": "https://registry.npmjs.org/openclaw/-/openclaw-2026.7.1.tgz",
"directory": "agents/openclaw/openclaw-runtime",
"lockSha256": "82489f62febb12da52833c0b1f7f6969f7e21a098c565ef1f91342b1e5e32d88"
"reviewedLockSha256": [
"82489f62febb12da52833c0b1f7f6969f7e21a098c565ef1f91342b1e5e32d88",
"fdbee91a3f3a0222ec2e8e34864d09dfcff4711e86ac6bfa4d475af0593acd51"
]
},
{
"id": "mcporter-runtime",
Expand All @@ -79,7 +82,9 @@
"integrity": "sha512-egoPVYqTnWb3NjRIxo+xc8OrAI0dlPrJm9pAiZx0pImuNIV5rKhGtTnIfH/Y1ldGPVu74ibj3KR5c9U/QSdQFA==",
"tarballUrl": "https://registry.npmjs.org/mcporter/-/mcporter-0.7.3.tgz",
"directory": "agents/openclaw/mcporter-runtime",
"lockSha256": "c31959d7950903f7477ca2e143b3f1f4adfd10f1961fe97db40cd72f62b84830"
"reviewedLockSha256": [
"c31959d7950903f7477ca2e143b3f1f4adfd10f1961fe97db40cd72f62b84830"
]
}
]
}
38 changes: 31 additions & 7 deletions scripts/audit-reviewed-npm-graph.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

import { spawnSync } from "node:child_process";
import { createHash } from "node:crypto";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
Expand All @@ -27,7 +28,7 @@ type ReviewedPackage = Readonly<{
tarballUrl: string;
}>;
type LockedGraph = ReviewedPackage &
Readonly<{ directory: string; id: string; lockSha256: string }>;
Readonly<{ directory: string; id: string; reviewedLockSha256: readonly string[] }>;
type AuditConfig = Readonly<{
archivePackages: readonly ReviewedPackage[];
archiveGraphId: string;
Expand All @@ -36,7 +37,7 @@ type AuditConfig = Readonly<{
lockedGraphs: readonly LockedGraph[];
nodeVersion: string;
registryOrigin: string;
schemaVersion: 2;
schemaVersion: 3;
severityThreshold: Severity;
}>;

Expand Down Expand Up @@ -118,7 +119,7 @@ function run(command: string, args: readonly string[], cwd: string) {
function readConfig(): AuditConfig {
const parsed = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8")) as AuditConfig;
if (
parsed.schemaVersion !== 2 ||
parsed.schemaVersion !== 3 ||
!SEVERITIES.includes(parsed.severityThreshold) ||
typeof parsed.archiveGraphId !== "string" ||
!parsed.archiveGraphId ||
Expand All @@ -134,8 +135,12 @@ function readConfig(): AuditConfig {
!graph.id ||
typeof graph.directory !== "string" ||
!graph.directory ||
typeof graph.lockSha256 !== "string" ||
!/^[0-9a-f]{64}$/.test(graph.lockSha256),
!Array.isArray(graph.reviewedLockSha256) ||
graph.reviewedLockSha256.length === 0 ||
graph.reviewedLockSha256.some(
(digest: unknown) => typeof digest !== "string" || !/^[0-9a-f]{64}$/.test(digest),
) ||
new Set(graph.reviewedLockSha256).size !== graph.reviewedLockSha256.length,
)
) {
throw new Error("ci/reviewed-npm-audit.json is invalid");
Expand Down Expand Up @@ -192,9 +197,14 @@ function materializeLockedGraph(
path.join(graph.directory, "package-lock.json"),
`${graph.label} lockfile`,
);
const expectedLockSha256 = selectReviewedLockSha256(
sourceLock,
graph.reviewedLockSha256,
graph.label,
);
verifyReviewedNpmLock({
expectedIntegrity: graph.integrity,
expectedLockSha256: graph.lockSha256,
expectedLockSha256,
label: graph.label,
lockfilePath: sourceLock,
packageSpec: graph.packageSpec,
Expand All @@ -207,14 +217,28 @@ function materializeLockedGraph(
fs.copyFileSync(sourceLock, path.join(destination, "package-lock.json"));
run("npm", ["ci", "--ignore-scripts", "--omit=dev", "--no-audit", "--no-fund"], destination);
verifyInstalledNpmLock({
expectedLockSha256: graph.lockSha256,
expectedLockSha256,
installRoot: destination,
label: graph.label,
lockfilePath: path.join(destination, "package-lock.json"),
});
return destination;
}

export function selectReviewedLockSha256(
lockfilePath: string,
reviewedDigests: readonly string[],
label: string,
): string {
const actual = createHash("sha256").update(fs.readFileSync(lockfilePath)).digest("hex");
if (!reviewedDigests.includes(actual)) {
throw new Error(
`${label} lock SHA-256 mismatch\nExpected one of: ${reviewedDigests.join(", ")}\nActual: ${actual}`,
);
}
return actual;
}

function readJsonObject(file: string, label: string): Record<string, any> {
const parsed = JSON.parse(fs.readFileSync(file, "utf-8")) as unknown;
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
Expand Down
2 changes: 1 addition & 1 deletion test/openclaw-locked-install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ describe("locked OpenClaw production installation (#5896)", () => {
expect.arrayContaining([
expect.objectContaining({
directory: "agents/openclaw/openclaw-runtime",
lockSha256: LOCK_SHA256,
packageSpec: PACKAGE_SPEC,
reviewedLockSha256: expect.arrayContaining([LOCK_SHA256]),
}),
]),
);
Expand Down
21 changes: 20 additions & 1 deletion test/reviewed-npm-audit-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { createRequire } from "node:module";
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { normalizeOpenClawSignatureAlias } from "../scripts/audit-reviewed-npm-graph.mts";
import {
normalizeOpenClawSignatureAlias,
selectReviewedLockSha256,
} from "../scripts/audit-reviewed-npm-graph.mts";
import { readYaml } from "./helpers/e2e-workflow-contract";

type WorkflowStep = {
Expand Down Expand Up @@ -46,6 +49,22 @@ function requiredStep(job: WorkflowJob, name: string): WorkflowStep {
}

describe("trusted reviewed npm audit workflow (#5896)", () => {
it("accepts only an explicitly reviewed lock during a dependency transition", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-reviewed-lock-transition-"));
const lockfile = path.join(root, "package-lock.json");
fs.writeFileSync(lockfile, "reviewed lock\n");
const reviewed = "534ade489fdb2d8ff619a8b110c28fedbd2066e16ebf434738f64a5a44ec9860";
const previous = "a".repeat(64);
try {
expect(selectReviewedLockSha256(lockfile, [previous, reviewed], "test graph")).toBe(reviewed);
expect(() => selectReviewedLockSha256(lockfile, [previous], "test graph")).toThrow(
"lock SHA-256 mismatch",
);
} finally {
fs.rmSync(root, { recursive: true, force: true });
}
});

// source-shape-contract: security -- PR dependency audit code must come from the base SHA or the one-time signed bootstrap
it("runs PR audits from trusted code and keeps the main audit on the checked-in action", () => {
const pr = readYaml<Workflow>(".github/workflows/pr.yaml");
Expand Down
Loading