@trustify-da/trustify-da-javascript-client 0.3.0-ea.e12bc82 → 0.3.0-ea.e258fba
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +367 -13
- package/dist/package.json +48 -28
- package/dist/src/analysis.d.ts +28 -5
- package/dist/src/analysis.js +99 -89
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +346 -9
- package/dist/src/cyclone_dx_sbom.d.ts +30 -3
- package/dist/src/cyclone_dx_sbom.js +95 -9
- package/dist/src/index.d.ts +202 -12
- package/dist/src/index.js +365 -30
- package/dist/src/license/index.d.ts +28 -0
- package/dist/src/license/index.js +103 -0
- package/dist/src/license/license_utils.d.ts +40 -0
- package/dist/src/license/license_utils.js +137 -0
- package/dist/src/license/licenses_api.d.ts +34 -0
- package/dist/src/license/licenses_api.js +98 -0
- package/dist/src/license/project_license.d.ts +20 -0
- package/dist/src/license/project_license.js +62 -0
- package/dist/src/oci_image/images.d.ts +4 -5
- package/dist/src/oci_image/images.js +15 -1
- package/dist/src/oci_image/utils.d.ts +7 -7
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/package_version.d.ts +8 -0
- package/dist/src/package_version.js +31 -0
- package/dist/src/provider.d.ts +18 -5
- package/dist/src/provider.js +33 -5
- package/dist/src/providers/base_java.d.ts +68 -15
- package/dist/src/providers/base_java.js +82 -61
- package/dist/src/providers/base_javascript.d.ts +99 -12
- package/dist/src/providers/base_javascript.js +243 -27
- package/dist/src/providers/base_pyproject.d.ts +158 -0
- package/dist/src/providers/base_pyproject.js +322 -0
- package/dist/src/providers/containerfile_parser.d.ts +5 -0
- package/dist/src/providers/containerfile_parser.js +20 -0
- package/dist/src/providers/golang_gomodules.d.ts +30 -13
- package/dist/src/providers/golang_gomodules.js +219 -122
- package/dist/src/providers/gomod_parser.d.ts +4 -0
- package/dist/src/providers/gomod_parser.js +16 -0
- package/dist/src/providers/java_gradle.d.ts +76 -3
- package/dist/src/providers/java_gradle.js +323 -21
- package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
- package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
- package/dist/src/providers/java_maven.d.ts +45 -10
- package/dist/src/providers/java_maven.js +300 -14
- package/dist/src/providers/javascript_bun.d.ts +22 -0
- package/dist/src/providers/javascript_bun.js +141 -0
- package/dist/src/providers/javascript_npm.d.ts +19 -0
- package/dist/src/providers/javascript_npm.js +61 -1
- package/dist/src/providers/javascript_pnpm.d.ts +14 -1
- package/dist/src/providers/javascript_pnpm.js +55 -5
- package/dist/src/providers/javascript_yarn.d.ts +12 -0
- package/dist/src/providers/javascript_yarn.js +75 -2
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +28 -7
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/oci_dockerfile.d.ts +51 -0
- package/dist/src/providers/oci_dockerfile.js +177 -0
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_berry_processor.js +91 -7
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
- package/dist/src/providers/python_controller.d.ts +10 -3
- package/dist/src/providers/python_controller.js +122 -63
- package/dist/src/providers/python_pip.d.ts +16 -4
- package/dist/src/providers/python_pip.js +51 -58
- package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
- package/dist/src/providers/python_pip_pyproject.js +146 -0
- package/dist/src/providers/python_poetry.d.ts +98 -0
- package/dist/src/providers/python_poetry.js +286 -0
- package/dist/src/providers/python_uv.d.ts +46 -0
- package/dist/src/providers/python_uv.js +269 -0
- package/dist/src/providers/requirements_parser.d.ts +6 -0
- package/dist/src/providers/requirements_parser.js +24 -0
- package/dist/src/providers/rust_cargo.d.ts +56 -0
- package/dist/src/providers/rust_cargo.js +682 -0
- package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
- package/dist/src/remediate.d.ts +21 -0
- package/dist/src/remediate.js +149 -0
- package/dist/src/remediation.d.ts +57 -0
- package/dist/src/remediation.js +436 -0
- package/dist/src/remediation_report.d.ts +40 -0
- package/dist/src/remediation_report.js +159 -0
- package/dist/src/sbom.d.ts +28 -2
- package/dist/src/sbom.js +26 -4
- package/dist/src/tools.d.ts +48 -6
- package/dist/src/tools.js +138 -2
- package/dist/src/updaters/maven_updater.d.ts +26 -0
- package/dist/src/updaters/maven_updater.js +322 -0
- package/dist/src/updaters/toml_updater.d.ts +33 -0
- package/dist/src/updaters/toml_updater.js +244 -0
- package/dist/src/workspace.d.ts +70 -0
- package/dist/src/workspace.js +256 -0
- package/package.json +49 -29
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { generateImageSBOM, parseImageRef } from '../oci_image/utils.js';
|
|
3
|
+
import { getArgQuery, getFromQuery, getParser } from './containerfile_parser.js';
|
|
4
|
+
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest, packageManagerName() { return 'oci'; } };
|
|
5
|
+
/** @typedef {import('../provider').Provider} */
|
|
6
|
+
/** @typedef {import('../provider').Provided} Provided */
|
|
7
|
+
/**
|
|
8
|
+
* @type {string} ecosystem identifier for OCI image packages
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
const ecosystem = 'oci';
|
|
12
|
+
/**
|
|
13
|
+
* Check if the given manifest name is a Dockerfile or Containerfile.
|
|
14
|
+
* Supports dot-suffixed variants such as Dockerfile.dev or Containerfile.prod.
|
|
15
|
+
* @param {string} manifestName the manifest file name to check
|
|
16
|
+
* @returns {boolean} true if the manifest is a Dockerfile or Containerfile
|
|
17
|
+
*/
|
|
18
|
+
function isSupported(manifestName) {
|
|
19
|
+
return /^(Dockerfile|Containerfile)(\..+)?$/.test(manifestName);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Dockerfiles have no lock file, so validation always passes.
|
|
23
|
+
* @returns {boolean} always true
|
|
24
|
+
*/
|
|
25
|
+
function validateLockFile() { return true; }
|
|
26
|
+
/**
|
|
27
|
+
* Check whether a syntax node contains any expansion (variable substitution) children.
|
|
28
|
+
* @param {import('web-tree-sitter').SyntaxNode} node
|
|
29
|
+
* @returns {boolean}
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
function containsExpansion(node) {
|
|
33
|
+
if (node.type === 'expansion') {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
37
|
+
if (containsExpansion(node.child(i))) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Strip surrounding single or double quotes from a string.
|
|
45
|
+
* @param {string} text
|
|
46
|
+
* @returns {string}
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
function stripQuotes(text) {
|
|
50
|
+
if ((text.startsWith('"') && text.endsWith('"')) || (text.startsWith("'") && text.endsWith("'"))) {
|
|
51
|
+
return text.slice(1, -1);
|
|
52
|
+
}
|
|
53
|
+
return text;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Collect ARG key-value pairs from the Dockerfile AST.
|
|
57
|
+
* Only ARGs with a default value are collected (ARGs without defaults cannot be resolved statically).
|
|
58
|
+
* @param {import('web-tree-sitter').Tree} tree the parsed Dockerfile tree
|
|
59
|
+
* @param {import('web-tree-sitter').Query} argQuery the tree-sitter query for arg_instruction nodes
|
|
60
|
+
* @returns {Map<string, string>} map of ARG names to their default values
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
function collectArgs(tree, argQuery) {
|
|
64
|
+
const args = new Map();
|
|
65
|
+
for (const match of argQuery.matches(tree.rootNode)) {
|
|
66
|
+
const name = match.captures.find(c => c.name === 'name')?.node.text;
|
|
67
|
+
const defaultValue = match.captures.find(c => c.name === 'default')?.node.text;
|
|
68
|
+
if (name && defaultValue) {
|
|
69
|
+
args.set(name, stripQuotes(defaultValue));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return args;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Resolve ARG substitutions in an image spec text using the collected ARG map.
|
|
76
|
+
* Replaces ${VAR} and $VAR patterns with their ARG default values.
|
|
77
|
+
* @param {string} text the image spec text potentially containing variable references
|
|
78
|
+
* @param {Map<string, string>} args map of ARG names to their default values
|
|
79
|
+
* @returns {string|null} the resolved text, or null if any variable could not be resolved
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
function resolveArgs(text, args) {
|
|
83
|
+
let resolved = text;
|
|
84
|
+
let hasUnresolved = false;
|
|
85
|
+
resolved = resolved.replace(/\$\{([^}]+)\}|\$([A-Za-z_]\w*)/g, (_match, braced, plain) => {
|
|
86
|
+
const key = braced || plain;
|
|
87
|
+
if (args.has(key)) {
|
|
88
|
+
return args.get(key);
|
|
89
|
+
}
|
|
90
|
+
hasUnresolved = true;
|
|
91
|
+
return _match;
|
|
92
|
+
});
|
|
93
|
+
return hasUnresolved ? null : resolved;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parse all FROM instructions from a Dockerfile using tree-sitter to extract base image references.
|
|
97
|
+
* In multi-stage builds, every FROM line is returned so each image can be analyzed independently.
|
|
98
|
+
* ARG substitutions are resolved using declared default values. FROM lines with unresolvable
|
|
99
|
+
* variables (ARGs without defaults) are silently skipped.
|
|
100
|
+
* @param {string} manifestContent the content of the Dockerfile
|
|
101
|
+
* @returns {Promise<string[]>} array of image references from all resolvable FROM instructions
|
|
102
|
+
* @throws {Error} when no FROM instruction is found or when no FROM lines can be resolved
|
|
103
|
+
*/
|
|
104
|
+
export async function parseAllFromImages(manifestContent) {
|
|
105
|
+
const [parser, fromQuery, argQuery] = await Promise.all([getParser(), getFromQuery(), getArgQuery()]);
|
|
106
|
+
const tree = parser.parse(manifestContent);
|
|
107
|
+
const matches = fromQuery.matches(tree.rootNode);
|
|
108
|
+
if (matches.length === 0) {
|
|
109
|
+
throw new Error('No FROM line found in Dockerfile');
|
|
110
|
+
}
|
|
111
|
+
const args = collectArgs(tree, argQuery);
|
|
112
|
+
const images = [];
|
|
113
|
+
for (const match of matches) {
|
|
114
|
+
const imageSpec = match.captures.find(c => c.name === 'image').node;
|
|
115
|
+
if (containsExpansion(imageSpec)) {
|
|
116
|
+
const resolved = resolveArgs(imageSpec.text, args);
|
|
117
|
+
if (resolved != null) {
|
|
118
|
+
images.push(resolved);
|
|
119
|
+
}
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
images.push(imageSpec.text);
|
|
123
|
+
}
|
|
124
|
+
if (images.length === 0) {
|
|
125
|
+
throw new Error('Dockerfile uses ARG substitution in all FROM lines — cannot resolve variable references');
|
|
126
|
+
}
|
|
127
|
+
return images;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Generate image SBOMs for all FROM instructions in a Dockerfile manifest using syft.
|
|
131
|
+
* Returns a batch result with a purl-to-SBOM map suitable for the batch-analysis endpoint.
|
|
132
|
+
* @param {string} manifest path to the Dockerfile
|
|
133
|
+
* @param {{}} [opts={}] optional various options to pass along the application
|
|
134
|
+
* @returns {Promise<{ecosystem: string, content: string, contentType: string, batch: boolean}>}
|
|
135
|
+
* @private
|
|
136
|
+
*/
|
|
137
|
+
async function getImageSBOM(manifest, opts = {}) {
|
|
138
|
+
const manifestContent = fs.readFileSync(manifest, 'utf-8');
|
|
139
|
+
const images = await parseAllFromImages(manifestContent);
|
|
140
|
+
const sbomByPurl = {};
|
|
141
|
+
for (const image of images) {
|
|
142
|
+
const imageRef = parseImageRef(image, opts);
|
|
143
|
+
const purl = imageRef.getPackageURL().toString();
|
|
144
|
+
if (purl in sbomByPurl)
|
|
145
|
+
continue;
|
|
146
|
+
sbomByPurl[purl] = generateImageSBOM(imageRef, opts);
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
ecosystem,
|
|
150
|
+
content: JSON.stringify(sbomByPurl),
|
|
151
|
+
contentType: 'application/vnd.cyclonedx+json',
|
|
152
|
+
batch: true
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Provide content and content type for Dockerfile component analysis.
|
|
157
|
+
* @param {string} manifest path to the Dockerfile
|
|
158
|
+
* @param {{}} [opts={}] optional various options to pass along the application
|
|
159
|
+
* @returns {Promise<Provided>}
|
|
160
|
+
*/
|
|
161
|
+
async function provideComponent(manifest, opts = {}) {
|
|
162
|
+
return getImageSBOM(manifest, opts);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Provide content and content type for Dockerfile stack analysis.
|
|
166
|
+
* @param {string} manifest path to the Dockerfile
|
|
167
|
+
* @param {{}} [opts={}] optional various options to pass along the application
|
|
168
|
+
* @returns {Promise<Provided>}
|
|
169
|
+
*/
|
|
170
|
+
async function provideStack(manifest, opts = {}) {
|
|
171
|
+
return getImageSBOM(manifest, opts);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Dockerfiles contain no license information.
|
|
175
|
+
* @returns {null} always null
|
|
176
|
+
*/
|
|
177
|
+
function readLicenseFromManifest() { return null; }
|
|
@@ -29,13 +29,17 @@ export default class Yarn_berry_processor extends Yarn_processor {
|
|
|
29
29
|
* @param {Object} depTree - The dependency tree object
|
|
30
30
|
* @returns {Map<string, PackageURL>} Map of dependency names to their PackageURL objects
|
|
31
31
|
*/
|
|
32
|
-
getRootDependencies(depTree:
|
|
32
|
+
getRootDependencies(depTree: Object): Map<string, PackageURL>;
|
|
33
33
|
/**
|
|
34
34
|
* Adds dependencies to the SBOM
|
|
35
35
|
* @param {Sbom} sbom - The SBOM object to add dependencies to
|
|
36
36
|
* @param {Object} depTree - The dependency tree object
|
|
37
|
+
* @param {function(PackageURL): (Array<{alg: string, content: string}>|undefined)} [hashesForPurl] - Resolves lock-file hashes for a purl
|
|
37
38
|
*/
|
|
38
|
-
addDependenciesToSbom(sbom: Sbom, depTree:
|
|
39
|
+
addDependenciesToSbom(sbom: Sbom, depTree: Object, hashesForPurl?: (arg0: PackageURL) => (Array<{
|
|
40
|
+
alg: string;
|
|
41
|
+
content: string;
|
|
42
|
+
}> | undefined)): void;
|
|
39
43
|
#private;
|
|
40
44
|
}
|
|
41
45
|
import Yarn_processor from "./yarn_processor.js";
|
|
@@ -15,7 +15,10 @@ export default class Yarn_berry_processor extends Yarn_processor {
|
|
|
15
15
|
* @returns {string[]} Command arguments for listing dependencies
|
|
16
16
|
*/
|
|
17
17
|
listCmdArgs(includeTransitive) {
|
|
18
|
-
|
|
18
|
+
// --all is needed to include workspace members in the output
|
|
19
|
+
return includeTransitive
|
|
20
|
+
? ['info', '--recursive', '--all', '--json']
|
|
21
|
+
: ['info', '--all', '--json'];
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
21
24
|
* Returns the command arguments for updating the lock file
|
|
@@ -48,13 +51,15 @@ export default class Yarn_berry_processor extends Yarn_processor {
|
|
|
48
51
|
if (!depTree) {
|
|
49
52
|
return new Map();
|
|
50
53
|
}
|
|
51
|
-
return new Map(depTree.filter(dep => !this.#isRoot(dep.value))
|
|
54
|
+
return new Map(depTree.filter(dep => !this.#isRoot(dep.value))
|
|
55
|
+
.map(dep => {
|
|
52
56
|
const depName = dep.value;
|
|
53
57
|
const idx = depName.lastIndexOf('@');
|
|
54
58
|
const name = depName.substring(0, idx);
|
|
55
59
|
const version = dep.children.Version;
|
|
56
60
|
return [name, toPurl(purlType, name, version)];
|
|
57
|
-
})
|
|
61
|
+
})
|
|
62
|
+
.filter(([name]) => this._manifest.dependencies.includes(name)));
|
|
58
63
|
}
|
|
59
64
|
/**
|
|
60
65
|
* Checks if a dependency is the root package
|
|
@@ -66,32 +71,111 @@ export default class Yarn_berry_processor extends Yarn_processor {
|
|
|
66
71
|
if (!name) {
|
|
67
72
|
return false;
|
|
68
73
|
}
|
|
69
|
-
|
|
74
|
+
// Workspace members use paths like "member-a@workspace:packages/member-a", not just "@workspace:."
|
|
75
|
+
return name.startsWith(`${this._manifest.name}@workspace:`);
|
|
70
76
|
}
|
|
71
77
|
/**
|
|
72
78
|
* Adds dependencies to the SBOM
|
|
73
79
|
* @param {Sbom} sbom - The SBOM object to add dependencies to
|
|
74
80
|
* @param {Object} depTree - The dependency tree object
|
|
81
|
+
* @param {function(PackageURL): (Array<{alg: string, content: string}>|undefined)} [hashesForPurl] - Resolves lock-file hashes for a purl
|
|
75
82
|
*/
|
|
76
|
-
addDependenciesToSbom(sbom, depTree) {
|
|
83
|
+
addDependenciesToSbom(sbom, depTree, hashesForPurl = () => undefined) {
|
|
77
84
|
if (!depTree) {
|
|
78
85
|
return;
|
|
79
86
|
}
|
|
87
|
+
// Build index of nodes by their value for quick lookup
|
|
88
|
+
const nodeIndex = new Map();
|
|
89
|
+
depTree.forEach(n => nodeIndex.set(n.value, n));
|
|
90
|
+
// Determine the set of node values reachable from root via production deps
|
|
91
|
+
const prodDeps = new Set(this._manifest.dependencies);
|
|
92
|
+
const reachable = new Set();
|
|
93
|
+
const queue = [];
|
|
94
|
+
// Seed with root's production dependencies
|
|
95
|
+
const rootNode = depTree.find(n => this.#isRoot(n.value));
|
|
96
|
+
if (rootNode?.children?.Dependencies) {
|
|
97
|
+
for (const d of rootNode.children.Dependencies) {
|
|
98
|
+
const to = this.#purlFromLocator(d.locator);
|
|
99
|
+
if (to) {
|
|
100
|
+
const fullName = to.namespace ? `${to.namespace}/${to.name}` : to.name;
|
|
101
|
+
if (prodDeps.has(fullName)) {
|
|
102
|
+
queue.push(d.locator);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// BFS to find all transitively reachable packages
|
|
108
|
+
while (queue.length > 0) {
|
|
109
|
+
const locator = queue.shift();
|
|
110
|
+
if (reachable.has(locator)) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
reachable.add(locator);
|
|
114
|
+
const node = nodeIndex.get(this.#nodeValueFromLocator(locator));
|
|
115
|
+
if (node?.children?.Dependencies) {
|
|
116
|
+
for (const d of node.children.Dependencies) {
|
|
117
|
+
if (!reachable.has(d.locator)) {
|
|
118
|
+
queue.push(d.locator);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Only emit edges for root and reachable nodes
|
|
80
124
|
depTree.forEach(n => {
|
|
81
125
|
const depName = n.value;
|
|
82
|
-
const
|
|
126
|
+
const isRoot = this.#isRoot(depName);
|
|
127
|
+
if (!isRoot && !this.#isReachableNode(depName, reachable)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const from = isRoot ? toPurlFromString(sbom.getRoot().purl) : this.#purlFromNode(depName, n);
|
|
83
131
|
const deps = n.children?.Dependencies;
|
|
84
132
|
if (!deps) {
|
|
85
133
|
return;
|
|
86
134
|
}
|
|
87
135
|
deps.forEach(d => {
|
|
136
|
+
if (!reachable.has(d.locator)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
88
139
|
const to = this.#purlFromLocator(d.locator);
|
|
89
140
|
if (to) {
|
|
90
|
-
sbom.addDependency(from, to);
|
|
141
|
+
sbom.addDependency(from, to, undefined, hashesForPurl(to));
|
|
91
142
|
}
|
|
92
143
|
});
|
|
93
144
|
});
|
|
94
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Converts a locator to the node value format used in yarn info output
|
|
148
|
+
* @param {string} locator - e.g. "express@npm:4.17.1"
|
|
149
|
+
* @returns {string} The node value, same as locator for non-virtual
|
|
150
|
+
* @private
|
|
151
|
+
*/
|
|
152
|
+
#nodeValueFromLocator(locator) {
|
|
153
|
+
// Virtual locators: "@scope/name@virtual:hash#npm:version" → "@scope/name@npm:version"
|
|
154
|
+
const virtualMatch = Yarn_berry_processor.VIRTUAL_LOCATOR_PATTERN.exec(locator);
|
|
155
|
+
if (virtualMatch) {
|
|
156
|
+
return `${virtualMatch[1]}@npm:${virtualMatch[2]}`;
|
|
157
|
+
}
|
|
158
|
+
return locator;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Checks if a node is in the reachable set by matching its value against reachable locators
|
|
162
|
+
* @param {string} depName - The node value (e.g. "express@npm:4.17.1")
|
|
163
|
+
* @param {Set<string>} reachable - Set of reachable locators
|
|
164
|
+
* @returns {boolean}
|
|
165
|
+
* @private
|
|
166
|
+
*/
|
|
167
|
+
#isReachableNode(depName, reachable) {
|
|
168
|
+
if (reachable.has(depName)) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
// Check if any reachable locator resolves to this node value
|
|
172
|
+
for (const locator of reachable) {
|
|
173
|
+
if (this.#nodeValueFromLocator(locator) === depName) {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
95
179
|
/**
|
|
96
180
|
* Creates a PackageURL from a dependency locator
|
|
97
181
|
* @param {string} locator - The dependency locator
|
|
@@ -25,13 +25,17 @@ export default class Yarn_classic_processor extends Yarn_processor {
|
|
|
25
25
|
* @param {Object} depTree - The dependency tree object
|
|
26
26
|
* @returns {Map<string, PackageURL>} Map of dependency names to their PackageURL objects
|
|
27
27
|
*/
|
|
28
|
-
getRootDependencies(depTree:
|
|
28
|
+
getRootDependencies(depTree: Object): Map<string, PackageURL>;
|
|
29
29
|
/**
|
|
30
30
|
* Adds dependencies to the SBOM
|
|
31
31
|
* @param {Sbom} sbom - The SBOM object to add dependencies to
|
|
32
32
|
* @param {Object} depTree - The dependency tree object
|
|
33
|
+
* @param {function(PackageURL): (Array<{alg: string, content: string}>|undefined)} [hashesForPurl] - Resolves lock-file hashes for a purl
|
|
33
34
|
*/
|
|
34
|
-
addDependenciesToSbom(sbom: Sbom, depTree:
|
|
35
|
+
addDependenciesToSbom(sbom: Sbom, depTree: Object, hashesForPurl?: (arg0: PackageURL) => (Array<{
|
|
36
|
+
alg: string;
|
|
37
|
+
content: string;
|
|
38
|
+
}> | undefined)): void;
|
|
35
39
|
#private;
|
|
36
40
|
}
|
|
37
41
|
import Yarn_processor from "./yarn_processor.js";
|
|
@@ -50,8 +50,9 @@ export default class Yarn_classic_processor extends Yarn_processor {
|
|
|
50
50
|
* Adds dependencies to the SBOM
|
|
51
51
|
* @param {Sbom} sbom - The SBOM object to add dependencies to
|
|
52
52
|
* @param {Object} depTree - The dependency tree object
|
|
53
|
+
* @param {function(PackageURL): (Array<{alg: string, content: string}>|undefined)} [hashesForPurl] - Resolves lock-file hashes for a purl
|
|
53
54
|
*/
|
|
54
|
-
addDependenciesToSbom(sbom, depTree) {
|
|
55
|
+
addDependenciesToSbom(sbom, depTree, hashesForPurl = () => undefined) {
|
|
55
56
|
if (!depTree?.data?.trees) {
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
@@ -60,12 +61,12 @@ export default class Yarn_classic_processor extends Yarn_processor {
|
|
|
60
61
|
depTree.data.trees.forEach(n => {
|
|
61
62
|
const dep = new NodeMetaData(n);
|
|
62
63
|
if (this._manifest.dependencies.includes(dep.name)) {
|
|
63
|
-
sbom.addDependency(rootPurl, dep.purl);
|
|
64
|
+
sbom.addDependency(rootPurl, dep.purl, undefined, hashesForPurl(dep.purl));
|
|
64
65
|
}
|
|
65
66
|
purls.set(dep.name, dep.purl);
|
|
66
67
|
});
|
|
67
68
|
depTree.data.trees.forEach(n => {
|
|
68
|
-
this.#addChildrenToSbom(sbom, n, purls);
|
|
69
|
+
this.#addChildrenToSbom(sbom, n, purls, hashesForPurl);
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
@@ -73,9 +74,10 @@ export default class Yarn_classic_processor extends Yarn_processor {
|
|
|
73
74
|
* @param {Sbom} sbom - The SBOM object to add dependencies to
|
|
74
75
|
* @param {Object} node - The current dependency node
|
|
75
76
|
* @param {Map<string, PackageURL>} purls - Map of dependency names to their PackageURL objects
|
|
77
|
+
* @param {function(PackageURL): (Array<{alg: string, content: string}>|undefined)} hashesForPurl - Resolves lock-file hashes for a purl
|
|
76
78
|
* @private
|
|
77
79
|
*/
|
|
78
|
-
#addChildrenToSbom(sbom, node, purls) {
|
|
80
|
+
#addChildrenToSbom(sbom, node, purls, hashesForPurl) {
|
|
79
81
|
const dep = new NodeMetaData(node);
|
|
80
82
|
const children = node.children ? node.children : [];
|
|
81
83
|
children.forEach(c => {
|
|
@@ -83,9 +85,9 @@ export default class Yarn_classic_processor extends Yarn_processor {
|
|
|
83
85
|
const from = dep.shadow ? purls.get(dep.name) : dep.purl;
|
|
84
86
|
const to = child.shadow ? purls.get(child.name) : child.purl;
|
|
85
87
|
if (from && to) {
|
|
86
|
-
sbom.addDependency(from, to);
|
|
88
|
+
sbom.addDependency(from, to, undefined, hashesForPurl(to));
|
|
87
89
|
}
|
|
88
|
-
this.#addChildrenToSbom(sbom, c, purls);
|
|
90
|
+
this.#addChildrenToSbom(sbom, c, purls, hashesForPurl);
|
|
89
91
|
});
|
|
90
92
|
}
|
|
91
93
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @typedef {{name: string, version: string, dependencies: DependencyEntry[]}} DependencyEntry */
|
|
1
|
+
/** @typedef {{name: string, version: string, dependencies: DependencyEntry[], hashes?: Array<{alg: string, content: string}>}} DependencyEntry */
|
|
2
2
|
export default class Python_controller {
|
|
3
3
|
/**
|
|
4
4
|
* Constructor to create new python controller instance to interact with pip package manager
|
|
@@ -15,17 +15,24 @@ export default class Python_controller {
|
|
|
15
15
|
realEnvironment: boolean;
|
|
16
16
|
pathToRequirements: string;
|
|
17
17
|
options: {};
|
|
18
|
+
parser: Promise<import("web-tree-sitter").Parser>;
|
|
19
|
+
requirementsQuery: Promise<import("web-tree-sitter").Query>;
|
|
20
|
+
pinnedVersionQuery: Promise<import("web-tree-sitter").Query>;
|
|
18
21
|
prepareEnvironment(): void;
|
|
19
22
|
/**
|
|
20
23
|
*
|
|
21
24
|
* @param {boolean} includeTransitive - whether to return include in returned object transitive dependencies or not
|
|
22
|
-
* @return {[DependencyEntry]}
|
|
25
|
+
* @return {Promise<[DependencyEntry]>}
|
|
23
26
|
*/
|
|
24
|
-
getDependencies(includeTransitive: boolean): [DependencyEntry]
|
|
27
|
+
getDependencies(includeTransitive: boolean): Promise<[DependencyEntry]>;
|
|
25
28
|
#private;
|
|
26
29
|
}
|
|
27
30
|
export type DependencyEntry = {
|
|
28
31
|
name: string;
|
|
29
32
|
version: string;
|
|
30
33
|
dependencies: DependencyEntry[];
|
|
34
|
+
hashes?: Array<{
|
|
35
|
+
alg: string;
|
|
36
|
+
content: string;
|
|
37
|
+
}>;
|
|
31
38
|
};
|