Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
10 changes: 7 additions & 3 deletions .github/actions/ci-reviewed-npm-audit/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ runs:
set -euo pipefail
current_bucket="$(( $(date -u +%s) / 43200 ))"
previous_bucket="$(( current_bucket - 1 ))"
node --input-type=module - "$GITHUB_ACTION_PATH/../../../ci/reviewed-npm-audit.json" <<'NODE'
node --experimental-strip-types --input-type=module - \
"$GITHUB_ACTION_PATH/../../../ci/reviewed-npm-audit.json" \
"$GITHUB_ACTION_PATH/../../../scripts/lib/repository-input-path.mts" <<'NODE'
import { createHash } from "node:crypto";
import { appendFileSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
const targetRoot = process.env.NEMOCLAW_REVIEWED_NPM_AUDIT_TARGET_ROOT;
const [configFile] = process.argv.slice(2);
const [configFile, resolverFile] = process.argv.slice(2);
if (!targetRoot) {
throw new Error("reviewed npm audit target root is required");
}
const { resolvePathWithinRoot } = await import(pathToFileURL(resolverFile).href);
const configSource = readFileSync(configFile, "utf8");
const config = JSON.parse(configSource);
if (!/^(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)$/.test(config.npmVersion) || /[\r\n]/.test(config.npmVersion)) {
Expand All @@ -62,7 +66,7 @@ runs:
for (const file of ["package.json", "package-lock.json"]) {
const relative = join(directory, file);
hash.update(relative);
hash.update(readFileSync(join(targetRoot, relative)));
hash.update(readFileSync(resolvePathWithinRoot(targetRoot, relative, "reviewed npm audit target input")));
}
}
appendFileSync(
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ jobs:
scripts/lib/reviewed-npm-archive.mts
scripts/lib/reviewed-npm-audit.mts
scripts/lib/npm-audit-receipt.mts
scripts/lib/repository-input-path.mts
sparse-checkout-cone-mode: false

- name: Set up Node for reviewed package download
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/managed-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ jobs:
ci/reviewed-npm-audit.json
scripts/audit-reviewed-npm-graph.mts
scripts/lib/npm-audit-receipt.mts
scripts/lib/repository-input-path.mts
scripts/lib/openclaw-npm-remediation.mts
scripts/lib/reviewed-npm-archive.mts
scripts/lib/reviewed-npm-audit.mts
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/openshell-sdk-package-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
scripts/lib/reviewed-npm-archive.mts
scripts/lib/reviewed-npm-audit.mts
scripts/lib/npm-audit-receipt.mts
scripts/lib/repository-input-path.mts
sparse-checkout-cone-mode: false

- name: Setup Node.js for reviewed package download
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ jobs:
scripts/lib/reviewed-npm-archive.mts
scripts/lib/reviewed-npm-audit.mts
scripts/lib/npm-audit-receipt.mts
scripts/lib/repository-input-path.mts
sparse-checkout-cone-mode: false

- name: Download verified OpenShell SDK archive
Expand Down Expand Up @@ -202,6 +203,7 @@ jobs:
scripts/lib/reviewed-npm-archive.mts
scripts/lib/reviewed-npm-audit.mts
scripts/lib/npm-audit-receipt.mts
scripts/lib/repository-input-path.mts
sparse-checkout-cone-mode: false

- name: Locate exact base-controlled SDK package run
Expand Down Expand Up @@ -388,6 +390,7 @@ jobs:
scripts/lib/reviewed-npm-archive.mts
scripts/lib/reviewed-npm-audit.mts
scripts/lib/npm-audit-receipt.mts
scripts/lib/repository-input-path.mts
sparse-checkout-cone-mode: false

- name: Download verified OpenShell SDK archive
Expand Down Expand Up @@ -448,6 +451,7 @@ jobs:
scripts/lib/reviewed-npm-archive.mts
scripts/lib/reviewed-npm-audit.mts
scripts/lib/npm-audit-receipt.mts
scripts/lib/repository-input-path.mts
sparse-checkout-cone-mode: false

- name: Download verified OpenShell SDK archive
Expand Down Expand Up @@ -507,6 +511,7 @@ jobs:
scripts/lib/reviewed-npm-archive.mts
scripts/lib/reviewed-npm-audit.mts
scripts/lib/npm-audit-receipt.mts
scripts/lib/repository-input-path.mts
sparse-checkout-cone-mode: false

- name: Download verified OpenShell SDK archive
Expand Down Expand Up @@ -545,6 +550,7 @@ jobs:
scripts/lib/reviewed-npm-archive.mts
scripts/lib/reviewed-npm-audit.mts
scripts/lib/npm-audit-receipt.mts
scripts/lib/repository-input-path.mts
sparse-checkout-cone-mode: false

- name: Audit reviewed production npm graphs
Expand Down Expand Up @@ -597,6 +603,7 @@ jobs:
scripts/lib/reviewed-npm-archive.mts
scripts/lib/reviewed-npm-audit.mts
scripts/lib/npm-audit-receipt.mts
scripts/lib/repository-input-path.mts
sparse-checkout-cone-mode: false

- name: Download verified OpenShell SDK archive
Expand Down Expand Up @@ -724,6 +731,7 @@ jobs:
scripts/lib/reviewed-npm-archive.mts
scripts/lib/reviewed-npm-audit.mts
scripts/lib/npm-audit-receipt.mts
scripts/lib/repository-input-path.mts
sparse-checkout-cone-mode: false

- name: Download verified OpenShell SDK archive
Expand Down Expand Up @@ -775,6 +783,7 @@ jobs:
scripts/lib/reviewed-npm-archive.mts
scripts/lib/reviewed-npm-audit.mts
scripts/lib/npm-audit-receipt.mts
scripts/lib/repository-input-path.mts
sparse-checkout-cone-mode: false

- name: Download verified OpenShell SDK archive
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ RUN --mount=type=bind,source=nemoclaw-blueprint/blueprint.yaml,target=/tmp/bluep
--registry https://registry.yarnpkg.com --threshold high \
--legacy-npmjs true \
--result /tmp/mcporter-npm-audit-policy.json \
--raw-copy /tmp/mcporter-npm-audit.json; \
&& cp "$MCPORTER_RAW_REPORT" /tmp/mcporter-npm-audit.json; \
else \
node --experimental-strip-types /scripts/lib/reviewed-npm-audit.mts \
--directory /usr/local/lib/nemoclaw/mcporter-runtime \
Expand Down
27 changes: 2 additions & 25 deletions scripts/audit-reviewed-npm-graph.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { remediateReviewedOpenClawPluginArchive } from "./lib/openclaw-npm-remediation.mts";
import { canonicalAuditReceipt, createAuditReceipt } from "./lib/npm-audit-receipt.mts";
import { resolvePathWithinRoot } from "./lib/repository-input-path.mts";
import {
packReviewedNpmArchive,
verifyInstalledNpmLock,
Expand Down Expand Up @@ -104,31 +105,7 @@ const OPENCLAW_DOMEXCEPTION_ALIAS = {
version: "1.0.28",
} as const;

export function resolvePathWithinRoot(root: string, relativePath: string, label: string): string {
if (!relativePath || path.isAbsolute(relativePath)) {
throw new Error(`${label} must be a nonempty relative path`);
}
const canonicalRoot = fs.realpathSync(path.resolve(root));
const resolved = path.resolve(canonicalRoot, relativePath);
if (!resolved.startsWith(`${canonicalRoot}${path.sep}`)) {
throw new Error(`${label} escapes its repository root: ${relativePath}`);
}
let current = canonicalRoot;
for (const component of path.relative(canonicalRoot, resolved).split(path.sep)) {
current = path.join(current, component);
let stat: fs.Stats;
try {
stat = fs.lstatSync(current);
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") break;
throw error;
}
if (stat.isSymbolicLink()) {
throw new Error(`${label} contains a symbolic-link component: ${relativePath}`);
}
}
return resolved;
}
export { resolvePathWithinRoot } from "./lib/repository-input-path.mts";

export function resolveTrustedAuditConfigPath(trustedRoot: string): string {
return resolvePathWithinRoot(
Expand Down
10 changes: 3 additions & 7 deletions scripts/lib/npm-audit-receipt.mts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function cli(args: readonly string[]): void {
const value = args[index + 1];
if (!args[index]?.startsWith("--") || value === undefined)
throw new Error(
"usage: npm-audit-receipt.mts --receipt FILE --package-json FILE --package-lock FILE --raw-report FILE --exceptions FILE --graph ID --audit-config FILE --registry ORIGIN --threshold SEVERITY [--legacy-npmjs true] [--result FILE] [--raw-copy FILE]",
"usage: npm-audit-receipt.mts --receipt FILE --package-json FILE --package-lock FILE --raw-report FILE --exceptions FILE --graph ID --audit-config FILE --registry ORIGIN --threshold SEVERITY [--legacy-npmjs true] [--result FILE]",
);
values.set(args[index], value);
}
Expand All @@ -253,12 +253,10 @@ function cli(args: readonly string[]): void {
"--registry",
"--threshold",
];
const allowed = [...required, "--result", "--raw-copy", "--legacy-npmjs"];
const allowed = [...required, "--result", "--legacy-npmjs"];
exactKeys(
Object.fromEntries(
[...values].filter(
([key]) => key !== "--result" && key !== "--raw-copy" && key !== "--legacy-npmjs",
),
[...values].filter(([key]) => key !== "--result" && key !== "--legacy-npmjs"),
),
required,
"verifier arguments",
Expand Down Expand Up @@ -297,8 +295,6 @@ function cli(args: readonly string[]): void {
);
if (values.has("--result"))
fs.writeFileSync(values.get("--result")!, `${JSON.stringify(policyResult, null, 2)}\n`);
if (values.has("--raw-copy"))
fs.copyFileSync(values.get("--raw-report")!, values.get("--raw-copy")!);
console.log("reviewed npm audit receipt and current policy verified");
}

Expand Down
31 changes: 31 additions & 0 deletions scripts/lib/repository-input-path.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import fs from "node:fs";
import path from "node:path";

export function resolvePathWithinRoot(root: string, relativePath: string, label: string): string {
if (!relativePath || path.isAbsolute(relativePath)) {
throw new Error(`${label} must be a nonempty relative path`);
}
const canonicalRoot = fs.realpathSync(path.resolve(root));
const resolved = path.resolve(canonicalRoot, relativePath);
if (!resolved.startsWith(`${canonicalRoot}${path.sep}`)) {
throw new Error(`${label} escapes its repository root: ${relativePath}`);
}
let current = canonicalRoot;
for (const component of path.relative(canonicalRoot, resolved).split(path.sep)) {
current = path.join(current, component);
let stat: fs.Stats;
try {
stat = fs.lstatSync(current);
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") break;
throw error;
}
if (stat.isSymbolicLink()) {
throw new Error(`${label} contains a symbolic-link component: ${relativePath}`);
}
}
return resolved;
}
22 changes: 11 additions & 11 deletions src/lib/sandbox/build-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ function stageManagedStartupRuntimeSources(rootDir: string, buildCtx: string): v
);
}

function stageReviewedNpmAuditPolicy(rootDir: string, buildCtx: string): void {
const stagedCiDir = path.join(buildCtx, "ci");
fs.mkdirSync(stagedCiDir, { recursive: true });
for (const fileName of ["npm-audit-exceptions.json", "reviewed-npm-audit.json"]) {
fs.copyFileSync(path.join(rootDir, "ci", fileName), path.join(stagedCiDir, fileName));
}
normalizeReadModesForDockerCopy(stagedCiDir);
}

function stageLegacySandboxBuildContext(
rootDir: string,
tmpDir: string = os.tmpdir(),
Expand All @@ -161,6 +170,7 @@ function stageLegacySandboxBuildContext(
path.join(rootDir, "tsconfig.runtime-preloads.json"),
path.join(buildCtx, "tsconfig.runtime-preloads.json"),
);
stageReviewedNpmAuditPolicy(rootDir, buildCtx);
stageOpenClawRuntimeGraphs(rootDir, buildCtx);
stageMcpToolDiscoveryRuntime(rootDir, buildCtx);
fs.cpSync(path.join(rootDir, "nemoclaw"), path.join(buildCtx, "nemoclaw"), {
Expand Down Expand Up @@ -207,7 +217,6 @@ function stageOptimizedSandboxBuildContext(
const stagedNemoclawDir = path.join(buildCtx, "nemoclaw");
const sourceBlueprintDir = path.join(rootDir, "nemoclaw-blueprint");
const stagedBlueprintDir = path.join(buildCtx, "nemoclaw-blueprint");
const stagedCiDir = path.join(buildCtx, "ci");
const stagedScriptsDir = path.join(buildCtx, "scripts");

fs.copyFileSync(path.join(rootDir, "Dockerfile"), stagedDockerfile);
Expand All @@ -218,16 +227,7 @@ function stageOptimizedSandboxBuildContext(
stageOpenClawRuntimeGraphs(rootDir, buildCtx);
stageMcpToolDiscoveryRuntime(rootDir, buildCtx);

fs.mkdirSync(stagedCiDir, { recursive: true });
fs.copyFileSync(
path.join(rootDir, "ci", "npm-audit-exceptions.json"),
path.join(stagedCiDir, "npm-audit-exceptions.json"),
);
fs.copyFileSync(
path.join(rootDir, "ci", "reviewed-npm-audit.json"),
path.join(stagedCiDir, "reviewed-npm-audit.json"),
);
normalizeReadModesForDockerCopy(stagedCiDir);
stageReviewedNpmAuditPolicy(rootDir, buildCtx);

fs.mkdirSync(stagedNemoclawDir, { recursive: true });
for (const fileName of [
Expand Down
Loading
Loading