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
5 changes: 5 additions & 0 deletions .changeset/twenty-planes-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nodesecure/scanner": minor
---

Keep NPM provenance (attestations) in Dependency version
11 changes: 8 additions & 3 deletions workspaces/scanner/src/registry/NpmRegistryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export class NpmRegistryProvider {
links: getLinks(packumentVersion),
integrity,
deprecated: packumentVersion.deprecated,
signatures: packumentVersion.dist.signatures
signatures: packumentVersion.dist.signatures,
attestations: packumentVersion.dist.attestations
};
}

Expand Down Expand Up @@ -147,13 +148,17 @@ export class NpmRegistryProvider {
org: string | null | undefined
) {
try {
const { integrity, deprecated, links, signatures } = await this.collectPackageVersionData();
const {
integrity, deprecated, links,
signatures, attestations
} = await this.collectPackageVersionData();

Object.assign(
dependency.versions[this.version],
{
links,
deprecated
deprecated,
attestations
}
);
dependency.metadata.integrity[this.version] = integrity;
Expand Down
3 changes: 2 additions & 1 deletion workspaces/scanner/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { PackageModuleType } from "@nodesecure/mama";

import type { SpdxFileLicenseConformance } from "@nodesecure/conformance";
import type { IlluminatedContact } from "@nodesecure/contact";
import type { Contact } from "@nodesecure/npm-types";
import type { Contact, Dist } from "@nodesecure/npm-types";

export type Maintainer = Contact & {
/**
Expand Down Expand Up @@ -114,6 +114,7 @@ export interface DependencyVersion {
integrity?: string;
links?: DependencyLinks;
deprecated?: string;
attestations?: Dist["attestations"];
}

export interface Dependency {
Expand Down
59 changes: 44 additions & 15 deletions workspaces/scanner/test/NpmRegistryProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getNpmRegistryURL } from "@nodesecure/npm-registry-sdk";
import { HttpieOnHttpError } from "@openally/httpie";

// Import Internal Dependencies
import { Logger, type Dependency } from "../src/index.js";
import { Logger, type Dependency, type DependencyConfusionWarning } from "../src/index.js";
import { NpmRegistryProvider } from "../src/registry/NpmRegistryProvider.js";

describe("NpmRegistryProvider", () => {
Expand Down Expand Up @@ -59,6 +59,7 @@ describe("NpmRegistryProvider", () => {
}
});
assert.deepEqual(dep.versions["1.5.0"], {
attestations: undefined,
deprecated: undefined,
links: {
npm: "https://www.npmjs.com/package/@slimio/is/v/1.5.0",
Expand All @@ -68,6 +69,34 @@ describe("NpmRegistryProvider", () => {
});
});

test("should enrich dependency with a valid NPM attestations (provenance)", async() => {
const dep = {
metadata: {
integrity: {}
},
versions: {
"3.1.0": {}
}
};
const provider = new NpmRegistryProvider("@nodesecure/cli", "3.1.0");

await provider.enrichDependencyVersion(dep as any, [], "nodesecure");
assert.deepEqual(dep.versions["3.1.0"], {
attestations: {
provenance: {
predicateType: "https://slsa.dev/provenance/v1"
},
url: "https://registry.npmjs.org/-/npm/v1/attestations/@nodesecure%2fcli@3.1.0"
},
deprecated: undefined,
links: {
homepage: "https://github.com/NodeSecure/cli#readme",
npm: "https://www.npmjs.com/package/@nodesecure/cli/v/3.1.0",
repository: "https://github.com/NodeSecure/cli"
}
});
});

test("should configure the npmApiClient on the given registry", async(t) => {
const packumentVersionMock = t.mock.fn<(name: string, version: string) => Promise<PackumentVersion>>();
const provider = new NpmRegistryProvider("foobarrxldkedeoxcjek", "1.5.0", {
Expand Down Expand Up @@ -117,7 +146,7 @@ describe("NpmRegistryProvider", () => {
packumentVersion: packumentVersionMock
}
});
const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
const dep = {
metadata: {
integrity: {}
Expand Down Expand Up @@ -182,7 +211,7 @@ describe("NpmRegistryProvider", () => {
packumentVersion: packumentVersionMock
}
});
const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
const dep = {
metadata: {
integrity: {}
Expand Down Expand Up @@ -234,7 +263,7 @@ describe("NpmRegistryProvider", () => {
packumentVersion: packumentVersionMock
}
});
const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
const dep = {
metadata: {
integrity: {}
Expand Down Expand Up @@ -281,7 +310,7 @@ describe("NpmRegistryProvider", () => {
}
});

const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
const dep = {
metadata: {
integrity: {}
Expand Down Expand Up @@ -326,7 +355,7 @@ describe("NpmRegistryProvider", () => {
packumentVersion: packumentVersionMock
}
});
const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
const dep = {
metadata: {
integrity: {}
Expand Down Expand Up @@ -379,7 +408,7 @@ describe("NpmRegistryProvider", () => {
packumentVersion: packumentVersionMock
}
});
const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
const dep = {
metadata: {
integrity: {}
Expand Down Expand Up @@ -426,7 +455,7 @@ describe("NpmRegistryProvider", () => {
packumentVersion: packumentVersionMock
}
});
const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
const dep = {
metadata: {
integrity: {}
Expand Down Expand Up @@ -476,7 +505,7 @@ describe("NpmRegistryProvider", () => {
packumentVersion: packumentVersionMock
}
});
const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
const dep = {
metadata: {
integrity: {}
Expand Down Expand Up @@ -532,7 +561,7 @@ describe("NpmRegistryProvider", () => {
packumentVersion: packumentVersionMock
}
});
const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
const dep = {
metadata: {
integrity: {}
Expand Down Expand Up @@ -582,7 +611,7 @@ describe("NpmRegistryProvider", () => {
packumentVersion: packumentVersionMock
}
});
const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
const dep = {
metadata: {
integrity: {}
Expand All @@ -608,7 +637,7 @@ describe("NpmRegistryProvider", () => {
const logger = new Logger().start("registry");
const provider = new NpmRegistryProvider("foobarrxldkedeoxcjek", "1.5.0");

const warnings = [];
const warnings: DependencyConfusionWarning[] = [];

await provider.enrichDependency(logger, {} as any);
assert.deepEqual(warnings, []);
Expand Down Expand Up @@ -727,7 +756,7 @@ describe("NpmRegistryProvider", () => {
},
registry: privateRegistry
});
const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
await provider.enrichScopedDependencyConfusionWarnings(warnings, "foo");
assert.deepEqual(warnings, [{
type: "dependency-confusion",
Expand All @@ -754,7 +783,7 @@ describe("NpmRegistryProvider", () => {
},
registry: privateRegistry
});
const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
await provider.enrichScopedDependencyConfusionWarnings(warnings, "foo");
assert.deepEqual(warnings, []);
assert.strictEqual(mockOrg.mock.callCount(), 1);
Expand All @@ -770,7 +799,7 @@ describe("NpmRegistryProvider", () => {
},
registry: privateRegistry
});
const warnings = [];
const warnings: DependencyConfusionWarning[] = [];
await provider.enrichScopedDependencyConfusionWarnings(warnings, "foo");
assert.deepEqual(warnings, []);
assert.strictEqual(mockOrg.mock.callCount(), 1);
Expand Down