Skip to content

fix: Omit null fields in CycloneDX SBOM license export

What does this MR do and why?

  • The dependency list exports feature fails with SchemaValidationError when exporting CycloneDX SBOMs that have missing optional fields. Although the ingested SBOMs pass CycloneDX validation, GitLab's export fails because null values for optional fields (like license IDs or component versions) are included in the JSON output, violating the CycloneDX schema.

  • This MR adds expose_nil: false to the optional fields in the SBOM serialization code:

    • License properties (spdx_identifier, name, url)
    • Component properties (version, purl, licenses)
  • In addition, the code now properly validates licenses with the following rules:

    • Valid SPDX ID is the primary validator (even with unknown name) - the license exposure logic was refactored to prioritize SPDX identifiers over names, replacing the previous unknown? method with a valid_id? method that handles all license validation scenarios.
    • license fields with null values are omitted from the output JSON.
    • components with null licenses or empty license arrays skip license serialization.

The following scenarios are now properly handled:

Case SPDX Identifier Name Expected
Standard MIT MIT { id: "MIT", url: "https://spdx.org/licenses/MIT.html" }
Valid ID, custom name Apache-2.0 Some License { id: "Apache-2.0", url: "https://spdx.org/licenses/Apache-2.0.html" }
Unknown ID and name unknown unknown { name: "unknown" }
Invalid ID, custom name nil / "" / unknown Some License { name: "Some License" }
Valid ID, invalid name Apache-2.0 nil / "" / unknown { id: "Apache-2.0", url: "https://spdx.org/licenses/Apache-2.0.html" }

Related issues

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Edited by Orin Naaman

Merge request reports

Loading