cdxgen: [validation] Invalid externalReferences URLs may be present in the SBOM

With DependencyTrack 4.11 validating SBOM with schema validation at upload, I’ve discovered that some SBOM may have invalid externalReferences. For example:

"externalReferences": [
  {
    "type": "vcs",
    "url": "git@gitlab.com:behat-chrome/chrome-mink-driver.git"
  }
],

coming from composer dmore/chrome-mink-driver package.

Indeed, an externalReference should be a iri-reference or a #/definitions/bomLink according to the JsonSchema.

The problem is that git@gitlab.com:behat-chrome/chrome-mink-driver.git is neither a #/definitions/bomLink nor an iri-reference (that should be of the form scheme://... according to the RFC).

If we can “convert” git@gitlab.com:behat-chrome/chrome-mink-driver.git to https://gitlab.com/behat-chrome/chrome-mink-driver.git it would be nice, but if not, we’d better drop the reference than write an invalid one.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 38 (16 by maintainers)

Most upvoted comments

This is not the only issues. I have seen BOMs that contain whitespace around the URL inside the reference, like

"externalReferences": [
  {
    "type": "vcs",
    "url": "     git@gitlab.com:behat-chrome/chrome-mink-driver.git      "
  }
]

Or failed replacements like

"externalReferences": [
  {
    "type": "vcs",
    "url": "${repository.url}"
  }
]

I’m re-closing this issue

It’s fixed in json-schema-validator@1.4.2 that is used in cyclonedx-core-java@9.0.4 that is used in dependency-track@4.11.4

I’ve started to work on it by enabling strict JSON Schema validation on this PR: https://github.com/CycloneDX/cdxgen/pull/1128

Hey in my case as well it is no longer getting stuck Thanks @prabhu

Look good, thanks! @prabhu

cdxgen generates SBOMs by analyzing files. During that analysis, it extracts information from files such as package.json, pom.xml, composer.json, … In those information, there is an external reference URLs corresponding to the URL of the corresponding dependency. CycloneDX format (the specification for SBOM) forces those external references to be an “iri-reference” (to simplify, an URL). The problem is that the external reference extracted from package.json, pom.xml, composer.json, … is sometimes NOT an iri-reference (such as git@…). Before this PR, the generated SBOM was sometimes invalid according to the CycloneDX specification. Now, it logs a warning message for every external reference URL that is not a valid iri-reference and excludes that external reference from the generated SBOM to prevent it to be invalid.

So, I see 3 “solutions”:

  1. fix the reference in the corresponding package: here, change git@github.com:micrometer-metrics/micrometer.git to something like https://github.com/micrometer-metrics/micrometer, but it requires some contribution to the micrometer-metrics/micrometer source code
  2. add a feature in cdxgen to “convert” invalid reference to a valid one: it’s “easy” for git@github.com:micrometer-metrics/micrometer.git, but how would you convert ${repository.url} or any other incorrect value?
  3. ignore those warnings

I’ve created an issue on json-schema-validator that is used by DependencyTrack. In my opinion, “http://” should be considered as valid as it is allowed by the RFC (if I understand it well), event though it’s not a very useful value. So the fix should be on DependencyTrack/json-schema-validator side and not on cdxgen/validate-iri.

I had this issue a well and had it in Java – unfortunately not Maven but Gradle. Seems to work perfectly though!

@prabhu sorry no java over here.

@prabhu, thanks a lot for the fix. It works perfectly.

@setchy and all, @timmyteo has kindly volunteered to look into this. Please work with him to get this tested and released.

I think we may need to trim the url, and then ideally use the same regex DTrack is using to validate [IRI RFC 3987](https://datatracker.ietf.org/doc/html/rfc3987

We’ve had instances like the following being rejected

  • url: UNKNOWN
  • url: git@github.com:follow-redirects/follow-redirects.git
{
            "publisher": "UNKNOWN",
            "group": "",
            "name": "yum-metadata-parser",
            "version": "1.1.4",
            "description": "A fast YUM meta-data parser",
            "purl": "pkg:pypi/yum-metadata-parser@1.1.4",
            "externalReferences": [
                {
                    "type": "website",
                    "url": "UNKNOWN"
                }
            ],
   }
   
   {
   "author": "Ruben Verborgh <ruben@verborgh.org> (https://ruben.verborgh.org/)",
            "group": "",
            "name": "follow-redirects",
            "version": "1.15.6",
            "description": "HTTP and HTTPS modules that follow redirects.",
            "licenses": [
                {
                    "license": {
                        "id": "MIT",
                        "url": "https://opensource.org/licenses/MIT"
                    }
                }
            ],
            "purl": "pkg:npm/follow-redirects@1.15.6",
            "externalReferences": [
                {
                    "type": "vcs",
                    "url": "https://github.com/follow-redirects/follow-redirects"
                },
                {
                    "type": "vcs",
                    "url": "git@github.com:follow-redirects/follow-redirects.git"
                }
            ],
}