Skip to content

feat(spdx): add default-off SPDX 3.0 document detection - #1903

Merged
Ryan Brandenburg (ryanbrandenburg) merged 7 commits into
microsoft:mainfrom
sfoslund:sfoslund/spdx3-detector
Oct 23, 2026
Merged

Ryan Brandenburg (ryanbrandenburg) merged 7 commits into
microsoft:mainfrom
sfoslund:sfoslund/spdx3-detector

Conversation

@sfoslund

Copy link
Copy Markdown
Member

Add Spdx30ComponentDetector (SPDX30SBOM) as a default-off detector for SPDX 3.0.0 and 3.0.1 compact JSON-LD documents.

  • Discover only *.spdx.json files and register each document as one existing SpdxComponent, rather than importing its packages or dependency relationships.
  • Resolve embedded or referenced creation information and creator tool/organization nodes.
  • Record the document IRI, name, first root element, file path, and lowercase SHA1 checksum. Use the document IRI when the name or root element is absent, and warn when selecting among multiple roots.
  • Reject unsupported versions, ambiguous documents, and duplicate element identifiers.
  • Register the detector in DI and add focused unit tests plus a local verification fixture. Leave the existing SPDX 2.2 detector unchanged.

Enable alongside SPDX 2.2 with:

--DetectorArgs SPDX22SBOM=EnableIfDefaultOff,SPDX30SBOM=EnableIfDefaultOff

Validation

  • dotnet build test\Microsoft.ComponentDetection.Detectors.Tests\Microsoft.ComponentDetection.Detectors.Tests.csproj --no-restore --verbosity quiet — passed, zero warnings or errors.
  • dotnet run --project test\Microsoft.ComponentDetection.Detectors.Tests\Microsoft.ComponentDetection.Detectors.Tests.csproj --no-build -- --filter "FullyQualifiedName~Spdx" — passed, all 36 SPDX tests.
  • dotnet build src\Microsoft.ComponentDetection\Microsoft.ComponentDetection.csproj --no-restore --verbosity quiet — passed, zero warnings or errors.
  • The following CLI smoke test passed and produced exactly one SPDX30SBOM document component with both detectors enabled:
dotnet run --project src\Microsoft.ComponentDetection\Microsoft.ComponentDetection.csproj --no-build -- scan `
  --SourceDirectory test\Microsoft.ComponentDetection.VerificationTests\resources\spdx30 `
  --DetectorArgs "SPDX22SBOM=EnableIfDefaultOff,SPDX30SBOM=EnableIfDefaultOff" `
  --ManifestFile "$env:TEMP\component-detection-spdx30-pr-result.json" `
  --NoSummary

Combined scans containing both SPDX 2.2 and 3.0 documents also found both document components. Default-off behavior and exclusion of alternate filename suffixes were checked locally.

The full solution test suite and snapshot verification suite were not run. The fixture is included in this repository; a separate verification-repository PR has not been created. No README feature-table changes are included.

New Detector Checklist

  • I have gone through the docs for creating a new detector here
  • My new detector implements IDefaultOffComponentDetector
  • I have created a PR to the verification repo with components that my new detector can find
  • (If necessary) I have updated the Feature Overview table in the README

Detect SPDX 3.0.0 and 3.0.1 compact JSON-LD documents as SBOM references, including root elements and creator metadata. Register the detector and add focused tests and a verification fixture.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 74ac0491-574a-40fc-bf08-180aea181b07
Update detector tests and rename the verification fixture to match the sole supported search pattern.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 74ac0491-574a-40fc-bf08-180aea181b07
Rename the detector, its ID, tests, and verification fixture to reserve distinct identities for future SPDX minor versions. Continue accepting SPDX 3.0.0 and 3.0.1 only.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 74ac0491-574a-40fc-bf08-180aea181b07
Extract shared SPDX metadata, SHA1 hashing, JSON loading, and component registration into SpdxComponentDetector. Keep format-specific parsing and exception handling in the concrete detectors, with regression coverage for their differing error policies.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 74ac0491-574a-40fc-bf08-180aea181b07
This reverts commit b7caee8, restoring independent SPDX detector implementations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 74ac0491-574a-40fc-bf08-180aea181b07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Embedded-reference resolution can skip supported documents, and component registration leaves the document without a dependency root.

2 open issues
What changed in this PR

Adds an opt-in SPDX 3.0 detector that records each supported document as one existing SpdxComponent, alongside the unchanged SPDX 2.2 detector.

Changes:

  • Parses SPDX 3.0.0 and 3.0.1 compact JSON-LD documents, including document metadata, creators, roots, and checksums.
  • Registers SPDX30SBOM as a default-off detector.
  • Adds focused unit tests and a local verification fixture.
File Description
test/​Microsoft.ComponentDetection.VerificationTests/​resources/​spdx30/​manifest.spdx.json Adds a sample SPDX 3.0.1 document.
test/​Microsoft.ComponentDetection.Detectors.Tests/​Spdx30ComponentDetectorTests.cs Tests detection, metadata resolution, fallbacks, and rejection cases.
src/​Microsoft.ComponentDetection.Orchestrator/​Extensions/​ServiceCollectionExtensions.cs Registers the new detector in dependency injection.
src/​Microsoft.ComponentDetection.Detectors/​spdx/​Spdx30ComponentDetector.cs Implements document discovery, parsing, validation, and component registration.

Review effort: Balanced

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some questions about edge-case stuff but nothing to block on for a default-off Detector as long as you give them some thought.

Comment thread src/Microsoft.ComponentDetection.Detectors/spdx/Spdx30ComponentDetector.cs Outdated
Log detector version mismatches at debug level and accept stable SPDX 3.0 patch versions. Warn and skip SPDX 3.0 files that exhaust memory or overflow size limits, without stopping subsequent files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e4f54f6-111a-4ceb-85fb-5b08c49779af
Copilot AI balanced review requested due to automatic review settings October 23, 2026 19:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Valid standalone SPDX documents are skipped because the detector requires an @graph wrapper.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Handle root-level SPDX 3.0 documents without @​graph

src/​Microsoft.ComponentDetection.Detectors/​spdx/​Spdx30ComponentDetector.cs:146

This guard skips compact SPDX documents that put SpdxDocument directly at the JSON root. The SPDX project's 3.0.0 example uses this form with embedded creationInfo and no @graph. It therefore produces no component here even though the remaining parsing logic supports its fields and version. Normalize a standalone document into a one-element sequence while retaining graph support, and add a regression test for this form.

2 resolved since last review

Review effort: Balanced

Comment thread src/Microsoft.ComponentDetection.Detectors/spdx/Spdx30ComponentDetector.cs Outdated
Preserve stable 3.0.x matching, including multi-digit patches, while rejecting leading zeros and non-ASCII digits.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 3e4f54f6-111a-4ceb-85fb-5b08c49779af
Copilot AI balanced review requested due to automatic review settings October 23, 2026 21:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No blocking issues remain in the opt-in detector, its integration, or its focused test coverage.

No open issues 🎉

Review effort: Balanced

@ryanbrandenburg
Ryan Brandenburg (ryanbrandenburg) merged commit fbacec6 into microsoft:main Oct 23, 2026
9 of 12 checks passed
@github-actions

Copy link
Copy Markdown

👋 Hi! It looks like you modified some files in the Detectors folder.
You may need to bump the detector versions if any of the following scenarios apply:

  • The detector detects more or fewer components than before
  • The detector generates different parent/child graph relationships than before
  • The detector generates different devDependencies values than before

If none of the above scenarios apply, feel free to ignore this comment 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants