@cyclonedx/cdxgen 10.2.3 → 10.2.5

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/bin/cdxgen.js CHANGED
@@ -348,11 +348,13 @@ const applyAdvancedOptions = (options) => {
348
348
  "oci",
349
349
  "android",
350
350
  "apk",
351
- "aab"
351
+ "aab",
352
+ "go",
353
+ "golang"
352
354
  ].includes(options.projectType)
353
355
  ) {
354
356
  console.log(
355
- "PREVIEW: post-build lifecycle SBOM generation is supported only for android and dotnet projects. Please specify the type using the -t argument."
357
+ "PREVIEW: post-build lifecycle SBOM generation is supported only for android, dotnet, and go projects. Please specify the type using the -t argument."
356
358
  );
357
359
  process.exit(1);
358
360
  }
package/index.js CHANGED
@@ -4412,7 +4412,7 @@ export async function createCsharpBom(path, options) {
4412
4412
  }
4413
4413
  } else if (pkgLockFiles.length) {
4414
4414
  manifestFiles = manifestFiles.concat(pkgLockFiles);
4415
- let parentDependsOn = [];
4415
+ const parentDependsOn = new Set();
4416
4416
  // packages.lock.json from nuget
4417
4417
  for (const af of pkgLockFiles) {
4418
4418
  if (DEBUG_MODE) {
@@ -4432,13 +4432,15 @@ export async function createCsharpBom(path, options) {
4432
4432
  // Keep track of the direct dependencies so that we can construct one complete
4433
4433
  // list after processing all lock files
4434
4434
  if (rootList && rootList.length) {
4435
- parentDependsOn = parentDependsOn.concat(rootList);
4435
+ for (const p of rootList) {
4436
+ parentDependsOn.add(p["bom-ref"]);
4437
+ }
4436
4438
  }
4437
4439
  }
4438
- if (parentDependsOn.length) {
4440
+ if (parentDependsOn.size) {
4439
4441
  dependencies.splice(0, 0, {
4440
4442
  ref: parentComponent["bom-ref"],
4441
- dependsOn: parentDependsOn.map((p) => p["bom-ref"])
4443
+ dependsOn: Array.from(parentDependsOn)
4442
4444
  });
4443
4445
  }
4444
4446
  } else if (pkgConfigFiles.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyclonedx/cdxgen",
3
- "version": "10.2.3",
3
+ "version": "10.2.5",
4
4
  "description": "Creates CycloneDX Software Bill of Materials (SBOM) from source or container image",
5
5
  "homepage": "http://github.com/cyclonedx/cdxgen",
6
6
  "author": "Prabhu Subramanian <prabhu@appthreat.com>",
@@ -57,8 +57,8 @@
57
57
  "url": "https://github.com/cyclonedx/cdxgen/issues"
58
58
  },
59
59
  "dependencies": {
60
- "@babel/parser": "^7.24.0",
61
- "@babel/traverse": "^7.24.0",
60
+ "@babel/parser": "^7.24.1",
61
+ "@babel/traverse": "^7.24.1",
62
62
  "@npmcli/arborist": "7.4.0",
63
63
  "ajv": "^8.12.0",
64
64
  "ajv-formats": "^2.1.1",
@@ -84,7 +84,7 @@
84
84
  "yargs": "^17.7.2"
85
85
  },
86
86
  "optionalDependencies": {
87
- "@appthreat/atom": "2.0.8",
87
+ "@appthreat/atom": "2.0.9",
88
88
  "@appthreat/cdx-proto": "^0.0.4",
89
89
  "@cyclonedx/cdxgen-plugins-bin": "^1.5.8",
90
90
  "@cyclonedx/cdxgen-plugins-bin-arm64": "^1.5.8",
package/utils.js CHANGED
@@ -825,19 +825,25 @@ export async function parsePkgLock(pkgLockFile, options = {}) {
825
825
  // which isn't installed
826
826
  // Bug #795. At times, npm loses the integrity node completely and such packages are getting missed out
827
827
  // To keep things safe, we include these packages.
828
- const edgeToIntegrity = edge.to ? edge.to.integrity : undefined;
829
- if (!edgeToIntegrity) {
828
+ let edgeToIntegrityOrLocation = edge.to ? edge.to.integrity : undefined;
829
+ // Fallback to location based lookups when integrity is missing
830
+ if (!edgeToIntegrityOrLocation && edge.to && edge.to.location) {
831
+ edgeToIntegrityOrLocation = edge.to.location;
832
+ }
833
+ if (!edgeToIntegrityOrLocation) {
830
834
  // This hack is required to fix the package name
831
- targetName = node.name.replace(/-cjs$/, "");
832
- targetVersion = node.version;
833
- foundMatch = true;
835
+ targetName = edge.name.replace(/-cjs$/, "");
836
+ foundMatch = false;
834
837
  } else {
835
838
  // the edges don't actually contain a version, so we need to search the root node
836
839
  // children to find the correct version. we check the node children first, then
837
840
  // we check the root node children
838
841
  for (const child of node.children) {
839
- if (edgeToIntegrity) {
840
- if (child[1].integrity == edgeToIntegrity) {
842
+ if (edgeToIntegrityOrLocation) {
843
+ if (
844
+ child[1].integrity === edgeToIntegrityOrLocation ||
845
+ child[1].location === edgeToIntegrityOrLocation
846
+ ) {
841
847
  targetName = child[0].replace(/node_modules\//g, "");
842
848
  // The package name could be different from the targetName retrieved
843
849
  // Eg: "string-width-cjs": "npm:string-width@^4.2.0",
@@ -853,7 +859,11 @@ export async function parsePkgLock(pkgLockFile, options = {}) {
853
859
  }
854
860
  if (!foundMatch) {
855
861
  for (const child of rootNode.children) {
856
- if (child[1].integrity == edgeToIntegrity) {
862
+ if (
863
+ edgeToIntegrityOrLocation &&
864
+ (child[1].integrity == edgeToIntegrityOrLocation ||
865
+ child[1].location == edgeToIntegrityOrLocation)
866
+ ) {
857
867
  targetName = child[0].replace(/node_modules\//g, "");
858
868
  targetVersion = child[1].version;
859
869
  // The package name could be different from the targetName retrieved
@@ -897,7 +907,6 @@ export async function parsePkgLock(pkgLockFile, options = {}) {
897
907
  pkgList = pkgList.concat(childPkgList);
898
908
  dependenciesList = dependenciesList.concat(childDependenciesList);
899
909
  }
900
-
901
910
  dependenciesList.push({
902
911
  ref: decodeURIComponent(purlString),
903
912
  dependsOn: workspaceDependsOn
@@ -6024,11 +6033,15 @@ export function parseCsPkgLockData(csLockData, pkgLockFile) {
6024
6033
  const dependsOn = [];
6025
6034
  if (libData.dependencies) {
6026
6035
  for (const adep of Object.keys(libData.dependencies)) {
6036
+ // get the resolved version of the dependency
6037
+ const adepResolvedVersion =
6038
+ assetData.dependencies[aversion][adep].resolved;
6039
+
6027
6040
  const adpurl = new PackageURL(
6028
6041
  "nuget",
6029
6042
  "",
6030
6043
  adep,
6031
- libData.dependencies[adep],
6044
+ adepResolvedVersion,
6032
6045
  null,
6033
6046
  null
6034
6047
  ).toString();
@@ -6746,7 +6759,16 @@ function purlFromUrlString(type, repoUrl, version) {
6746
6759
  const pathnameLastElement = pathnameParts.pop();
6747
6760
  name = pathnameLastElement.replace(".git", "");
6748
6761
  const urlpath = pathnameParts.join("/");
6749
- namespace = hostname + ":" + urlpath;
6762
+ namespace = hostname + "/" + urlpath;
6763
+ } else if (repoUrl && repoUrl.startsWith("ssh://git@bitbucket")) {
6764
+ repoUrl = repoUrl.replace("ssh://git@", "");
6765
+ const parts = repoUrl.split(":");
6766
+ const hostname = parts[0];
6767
+ const pathnameParts = parts[1].split("/").slice(1);
6768
+ const pathnameLastElement = pathnameParts.pop();
6769
+ name = pathnameLastElement.replace(".git", "");
6770
+ const urlpath = pathnameParts.join("/");
6771
+ namespace = hostname + "/" + urlpath;
6750
6772
  } else if (repoUrl && repoUrl.startsWith("/")) {
6751
6773
  const parts = repoUrl.split("/");
6752
6774
  name = parts[parts.length - 1];
package/utils.test.js CHANGED
@@ -3257,7 +3257,7 @@ test("parse swift deps files", () => {
3257
3257
  repository: { url: "https://github.com/apple/swift-argument-parser" }
3258
3258
  });
3259
3259
  pkgList = parseSwiftResolved("./test/data/Package2.resolved");
3260
- expect(pkgList.length).toEqual(6);
3260
+ expect(pkgList.length).toEqual(7);
3261
3261
  expect(pkgList[0]).toEqual({
3262
3262
  name: "swift-argument-parser",
3263
3263
  group: "github.com/apple",
@@ -3280,6 +3280,54 @@ test("parse swift deps files", () => {
3280
3280
  "bom-ref": "pkg:swift/github.com/apple/swift-argument-parser@1.2.2",
3281
3281
  repository: { url: "https://github.com/apple/swift-argument-parser.git" }
3282
3282
  });
3283
+ expect(pkgList[4]).toEqual({
3284
+ name: "swift-http-server",
3285
+ group: "github.com/swift",
3286
+ version: "0.7.4",
3287
+ purl: "pkg:swift/github.com/swift/swift-http-server@0.7.4",
3288
+ properties: [{ name: "SrcFile", value: "./test/data/Package2.resolved" }],
3289
+ evidence: {
3290
+ identity: {
3291
+ field: "purl",
3292
+ confidence: 1,
3293
+ methods: [
3294
+ {
3295
+ technique: "manifest-analysis",
3296
+ confidence: 1,
3297
+ value: "./test/data/Package2.resolved"
3298
+ }
3299
+ ]
3300
+ }
3301
+ },
3302
+ "bom-ref": "pkg:swift/github.com/swift/swift-http-server@0.7.4",
3303
+ repository: {
3304
+ url: "git@github.com:swift/swift-http-server.git"
3305
+ }
3306
+ });
3307
+ expect(pkgList[5]).toEqual({
3308
+ name: "swift-http-server",
3309
+ group: "bitbucket.org/swift",
3310
+ version: "0.7.4",
3311
+ purl: "pkg:swift/bitbucket.org/swift/swift-http-server@0.7.4",
3312
+ properties: [{ name: "SrcFile", value: "./test/data/Package2.resolved" }],
3313
+ evidence: {
3314
+ identity: {
3315
+ field: "purl",
3316
+ confidence: 1,
3317
+ methods: [
3318
+ {
3319
+ technique: "manifest-analysis",
3320
+ confidence: 1,
3321
+ value: "./test/data/Package2.resolved"
3322
+ }
3323
+ ]
3324
+ }
3325
+ },
3326
+ "bom-ref": "pkg:swift/bitbucket.org/swift/swift-http-server@0.7.4",
3327
+ repository: {
3328
+ url: "ssh://git@bitbucket.org:7999/swift/swift-http-server.git"
3329
+ }
3330
+ });
3283
3331
  });
3284
3332
 
3285
3333
  test("pypi version solver tests", () => {