Skip to content

Commit 13687b8

Browse files
authored
fix(sbom-tools): properly do relative lookups for external prod dependencies (#544)
We are currently receiving a vulnerability report for `brace-expansion` in mongosh even though we do not include said package in our production bundle. Tracking down this discrepancy led to this bug in our webpack dependency plugin.
1 parent 005f626 commit 13687b8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/sbom-tools/src/production-deps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function findAllProdDepsTreeLocations(from = process.cwd()): string[] {
7373
...Object.keys(optionalDependencies),
7474
].forEach((dep) => {
7575
try {
76-
const depLocation = findPackageLocation(dep, from);
76+
const depLocation = findPackageLocation(dep, packageLocation);
7777

7878
if (depLocation) {
7979
allLocations.add(depLocation);

packages/sbom-tools/src/webpack-dependencies-plugin.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ describe('WebpackDependenciesPlugin', function () {
185185
version: '0.1.0',
186186
dependencies: {
187187
pkg2: '^0.1.0',
188+
pkg4: '^1.2.3',
188189
},
189190
}),
190191
'node_modules/pkg1/index.js': '',
@@ -206,6 +207,16 @@ describe('WebpackDependenciesPlugin', function () {
206207
version: '0.1.0',
207208
}),
208209
'node_modules/pkg3/index.js': '',
210+
'node_modules/pkg4/package.json': JSON.stringify({
211+
name: 'pkg4',
212+
version: '1.2.4', // should be ignored in favor of nested one
213+
}),
214+
'node_modules/pkg4/index.js': '',
215+
'node_modules/pkg1/node_modules/pkg4/package.json': JSON.stringify({
216+
name: 'pkg4',
217+
version: '1.2.5',
218+
}),
219+
'node_modules/pkg1/node_modules/pkg4/index.js': '',
209220
};
210221

211222
const dependencies = await runPlugin(structure, {
@@ -233,6 +244,11 @@ describe('WebpackDependenciesPlugin', function () {
233244
name: 'pkg3',
234245
version: '0.1.0',
235246
},
247+
{
248+
licenseFiles: [],
249+
name: 'pkg4',
250+
version: '1.2.5',
251+
},
236252
]);
237253
});
238254

0 commit comments

Comments
 (0)