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
6 changes: 6 additions & 0 deletions scripts/security/run-endor-plugin-scan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ describe("runEndorPluginScan", () => {
name: "fixture-plugin",
dependencies: { "runtime-workspace": "workspace:*", lodash: "4.17.20" },
devDependencies: { "dev-workspace": "workspace:^", typescript: "6.0.3" },
packageManager: "pnpm@10.33.2",
})}\n`,
);
await writeFile(join(root, "npm-shrinkwrap.json"), '{"lockfileVersion":3}\n');
await writeFile(join(root, "pnpm-workspace.yaml"), "allowBuilds:\n esbuild: true\n");
await writeFile(
join(workspace, "docker-run-stdout"),
report([
Expand Down Expand Up @@ -159,6 +161,10 @@ describe("runEndorPluginScan", () => {
await expect(
readFile(join(workspace, "endor-artifact", "package-lock.json"), "utf8"),
).resolves.toContain('"lockfileVersion":3');
// Either pnpm marker makes endorctl demand the pnpm binary.
await expect(
stat(join(workspace, "endor-artifact", "pnpm-workspace.yaml")),
).rejects.toMatchObject({ code: "ENOENT" });
// The uploaded artifact stays untouched.
await expect(readFile(join(root, "npm-shrinkwrap.json"), "utf8")).resolves.toContain(
'"lockfileVersion":3',
Expand Down
20 changes: 17 additions & 3 deletions scripts/security/run-endor-plugin-scan.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { randomUUID } from "node:crypto";
import { chmod, cp, lstat, readFile, readdir, rename, writeFile } from "node:fs/promises";
import { chmod, cp, lstat, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
import { join, relative } from "node:path";
import { z } from "zod";
import type { EndorAnalysis } from "../../convex/lib/endorAnalysis";
Expand Down Expand Up @@ -86,6 +86,7 @@ async function normalizePackageRoot(scanRoot: string, manifestDirectory: string)
throw new Error(`Endor scan package.json is invalid at ${packageRoot}`, { cause: error });
}
const manifest = unknownRecordSchema.parse(parsedManifest);
let manifestChanged = false;
const devDependenciesValue = manifest.devDependencies;
if (devDependenciesValue !== undefined) {
const devDependencies = unknownRecordSchema.safeParse(devDependenciesValue);
Expand All @@ -99,9 +100,21 @@ async function normalizePackageRoot(scanRoot: string, manifestDirectory: string)
if (workspaceDependencyNames.length > 0) {
for (const name of workspaceDependencyNames) delete devDependencies.data[name];
manifest.devDependencies = devDependencies.data;
await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
manifestChanged = true;
}
}
// endorctl requires the pnpm binary whenever packageManager names pnpm, even
// next to an npm lockfile. A root pnpm-lock.yaml is skipped before this runs,
// so these packages resolve with npm like any lockfile-less package.
if (typeof manifest.packageManager === "string" && /^pnpm(@|$)/.test(manifest.packageManager)) {
delete manifest.packageManager;
manifestChanged = true;
}
if (manifestChanged) {
await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
}
// pnpm-workspace.yaml makes endorctl require pnpm too; npm never reads it.
await rm(join(manifestDirectory, "pnpm-workspace.yaml"), { force: true, recursive: true });

const shrinkwrapPath = join(manifestDirectory, "npm-shrinkwrap.json");
const packageLockPath = join(manifestDirectory, "package-lock.json");
Expand All @@ -111,10 +124,11 @@ async function normalizePackageRoot(scanRoot: string, manifestDirectory: string)
}

async function normalizePackageTree(scanRoot: string, directory = scanRoot): Promise<void> {
const entries = await readdir(directory, { withFileTypes: true });
if (await isRegularFile(join(directory, "package.json"))) {
await normalizePackageRoot(scanRoot, directory);
}
// List after normalizing, which can remove entries.
const entries = await readdir(directory, { withFileTypes: true });
for (const entry of entries) {
if (!entry.isDirectory() || entry.name === ".git" || entry.name === "node_modules") continue;
await normalizePackageTree(scanRoot, join(directory, entry.name));
Expand Down
6 changes: 5 additions & 1 deletion specs/endor-plugin-scans.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ under a shared 20-minute preparation ceiling.

The worker copies the artifact into a disposable directory and normalizes it for
npm: it renames `npm-shrinkwrap.json` to `package-lock.json` and drops
`workspace:` dev dependencies, which published packages cannot resolve. Runtime
`workspace:` dev dependencies, which published packages cannot resolve. It also
removes a `packageManager` value naming pnpm and any `pnpm-workspace.yaml` beside a `package.json`.
Either one makes `endorctl` demand the pnpm binary at host-check, even when an
npm lockfile is present, though neither changes what npm resolves. Without a
pnpm lockfile, these packages scan like any other npm package. Runtime
dependencies are unchanged. The uploaded artifact remains the source of truth.

Endor runs with `docker run --rm` from a digest-pinned image built by the manual
Expand Down
Loading