Skip to content

[BUG] buildID is cut from version #551

Description

@chrsch-dev

Describe the bug

If a projects version contains also build metadata (e.g "version": "1.0.0-123+456" following the semver definition) the build metadata part +456 is omitted in the purl that is put in the generated sbom. I would expect the build metadata to also be part of the version in the purl.

To Reproduce

Create a package.json file like this one:

{
  "name": "sbomtest",
  "version": "1.0.0-123+456",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@cyclonedx/cyclonedx-npm": "^1.9.0"
  }
}

run npm pkg get version which will return "1.0.0-123+456" as expected.

Then generate the sbom npx cyclonedx-npm --output-file sbom.json
This will generate a sbom like this (note: I removed irrelevant parts)

{
  "$schema": "http://cyclonedx.org/schema/bom-1.4.schema.json",
  "bomFormat": "CycloneDX",
  "specVersion": "1.4",
  "version": 1,
  "serialNumber": "urn:uuid:b368281e-6ad1-4f66-87ef-9e3cf5ed8cc2",
  "metadata": {
    "timestamp": "2023-03-10T09:24:29.674Z",
    "component": {
      "type": "application",
      "name": "sbomtest",
      "version": "1.0.0-123",
      "bom-ref": "sbomtest@1.0.0-123+456",
      "purl": "pkg:npm/sbomtest@1.0.0-123"
    }
  }
}

As you can see for the bom-ref the version part is as expected but the purl property misses the build metadata.

Expected behavior

The purl in the sbom should be "purl": "pkg:npm/sbomtest@1.0.0-123+456"

Environment

  • @cyclonedx/cyclonedx-npm version: 1.9.0
  • NPM version: 8.19.1
  • Node version: v18.9.0
  • OS: macOS Ventura

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions