feat(sbom): added support for specifying --sbom-spec-version#11389
Conversation
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds a CycloneDX-only CLI flag ChangesSBOM Specification Version Configuration
Sequence DiagramsequenceDiagram
participant CLI
participant CommandHandler
participant Serializer
CLI->>CommandHandler: parse args (includes --sbom-spec-version)
CommandHandler->>CommandHandler: validate sbomSpecVersion (format & allowed values)
CommandHandler->>Serializer: serializeCycloneDx(project, { specVersion })
Serializer->>Serializer: version = specVersion || "1.7"
Serializer->>CLI: emit CycloneDX BOM with $schema and specVersion set
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Add reference to pull request pnpm#11389 for sbom spec version change.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
deps/compliance/commands/src/sbom/sbom.ts (1)
220-227:⚠️ Potential issue | 🟠 Major | ⚡ Quick winValidate
--sbom-spec-versionbefore passing it through.Line 226 forwards raw user input without checks. This allows invalid CycloneDX versions and silently ignores the flag for SPDX, which can produce confusing/non-compliant output. Fail fast with explicit validation and format gating.
💡 Suggested patch
@@ const sbomType = validateSbomType(opts.sbomType) + const sbomSpecVersion = validateSbomSpecVersion(opts.sbomSpecVersion, format) @@ const output = format === 'cyclonedx' ? serializeCycloneDx(result, { pnpmVersion: packageManager.version, lockfileOnly: opts.lockfileOnly, sbomAuthors: opts.sbomAuthors?.split(',').map((s) => s.trim()).filter(Boolean), sbomSupplier: opts.sbomSupplier, - specVersion: opts.sbomSpecVersion, + specVersion: sbomSpecVersion, }) : serializeSpdx(result) @@ function validateSbomType (value: string | undefined): SbomComponentType { if (!value || value === 'library') return 'library' if (value === 'application') return 'application' throw new PnpmError( @@ ) } + +function validateSbomSpecVersion (value: string | undefined, format: SbomFormat): string | undefined { + if (value == null) return undefined + + if (format !== 'cyclonedx') { + throw new PnpmError( + 'SBOM_SPEC_VERSION_UNSUPPORTED_FORMAT', + 'The --sbom-spec-version option is supported only with --sbom-format cyclonedx.' + ) + } + + const normalized = value.trim() + const match = /^(\d+)\.(\d+)$/.exec(normalized) + if (!match) { + throw new PnpmError( + 'SBOM_INVALID_SPEC_VERSION', + `Invalid CycloneDX spec version "${value}". Use a version >= 1.5 (for example: 1.5, 1.6, 1.7).` + ) + } + + const major = Number(match[1]) + const minor = Number(match[2]) + if (major < 1 || (major === 1 && minor < 5)) { + throw new PnpmError( + 'SBOM_INVALID_SPEC_VERSION', + `Invalid CycloneDX spec version "${value}". Use a version >= 1.5.` + ) + } + + return `${major}.${minor}` +}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@deps/compliance/commands/src/sbom/sbom.ts` around lines 220 - 227, Before calling serializeCycloneDx, validate opts.sbomSpecVersion when format === 'cyclonedx': check that opts.sbomSpecVersion is one of the supported CycloneDX spec versions (use a small whitelist constant) and if not, throw or exit with a clear error message; do not forward raw input to serializeCycloneDx. Also ensure that when format !== 'cyclonedx' the presence of --sbom-spec-version is ignored or produces a helpful error/warning (fail fast) instead of being silently dropped. Locate this logic around the serializeCycloneDx call and the format variable, and perform validation prior to invoking serializeCycloneDx.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@deps/compliance/commands/src/sbom/sbom.ts`:
- Around line 220-227: Before calling serializeCycloneDx, validate
opts.sbomSpecVersion when format === 'cyclonedx': check that
opts.sbomSpecVersion is one of the supported CycloneDX spec versions (use a
small whitelist constant) and if not, throw or exit with a clear error message;
do not forward raw input to serializeCycloneDx. Also ensure that when format !==
'cyclonedx' the presence of --sbom-spec-version is ignored or produces a helpful
error/warning (fail fast) instead of being silently dropped. Locate this logic
around the serializeCycloneDx call and the format variable, and perform
validation prior to invoking serializeCycloneDx.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7a1cbe83-e34f-4468-b50e-ebbb647ac9e1
📒 Files selected for processing (3)
.changeset/honest-moose-grin.mddeps/compliance/commands/src/sbom/sbom.tsdeps/compliance/sbom/src/serializeCycloneDx.ts
There was a problem hiding this comment.
Pull request overview
Adds a new --sbom-spec-version CLI option so pnpm sbom --sbom-format cyclonedx can emit a caller-selected CycloneDX specVersion/$schema instead of always hardcoding 1.7.
Changes:
- Added
sbomSpecVersionto the SBOM command options and CLI help. - Threaded the selected spec version from the CLI into CycloneDX serialization.
- Added a changeset for the new SBOM version-selection feature.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
deps/compliance/sbom/src/serializeCycloneDx.ts |
Makes CycloneDX $schema and specVersion configurable. |
deps/compliance/commands/src/sbom/sbom.ts |
Exposes --sbom-spec-version on the SBOM command and passes it to the serializer. |
.changeset/honest-moose-grin.md |
Records the release note for the new SBOM option. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Currently only supported for cyclonedx. The version is not validated, but the currently generated json should be supported for cyclonedx >=1.5
Add reference to pull request pnpm#11389 for sbom spec version change.
84f3ad6 to
2082689
Compare
Reject unsupported CycloneDX spec versions and reject the flag when combined with --sbom-format spdx. Restrict accepted values to 1.5+ since the serializer emits metadata.lifecycles, which only exists from 1.5.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@deps/compliance/commands/src/sbom/sbom.ts`:
- Around line 247-262: In validateSbomSpecVersion, trim the incoming value
string before performing the null/format/allowed-version checks so inputs like
"1.6 " succeed; specifically, call value = value.trim() (or equivalent) after
the initial null check, then proceed to verify format (format !== 'cyclonedx'),
membership against SUPPORTED_CYCLONEDX_SPEC_VERSIONS, and return the trimmed
value; keep the same PnpmError codes ('SBOM_SPEC_VERSION_UNSUPPORTED_FORMAT' and
'SBOM_INVALID_SPEC_VERSION') on failure.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: de7c7e7c-b864-48d0-bc26-94ac64c6fdf6
📒 Files selected for processing (3)
deps/compliance/commands/src/sbom/sbom.tsdeps/compliance/commands/test/sbom/index.tsdeps/compliance/sbom/test/serializeCycloneDx.test.ts
✅ Files skipped from review due to trivial changes (1)
- deps/compliance/commands/test/sbom/index.ts
|
Congrats on merging your first pull request! 🎉🎉🎉 |
Currently only supported for cyclonedx. Allowed values are 1.5, 1.6, and 1.7 (defaulting to 1.7); the lower bound is 1.5 because the generated JSON uses fields (e.g.
metadata.lifecycles) that are only valid from CycloneDX 1.5+.Summary by CodeRabbit
New Features
Validation
Tests