Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation fails for valid JSON BOMs #202

Open
nscuro opened this issue Feb 4, 2022 · 4 comments
Open

Validation fails for valid JSON BOMs #202

nscuro opened this issue Feb 4, 2022 · 4 comments

Comments

@nscuro
Copy link
Member

nscuro commented Feb 4, 2022

I'm using the CLI to ensure that cyclonedx-go and cyclonedx-gomod produce valid BOMs.

While implementing support for spec v1.4 in cyclonedx-go, I noticed that some JSON BOMs fail to validate without apparent reason.
The validation fails not only for the BOMs produced by the Go tooling, but also for the input test files from the specification repo.

When testing the offending files using other tools like https://www.jsonschemavalidator.net/ with the official schema, validation succeeds.

Steps to reproduce

# Clone specification repo
git clone https://github.com/CycloneDX/specification cdx-spec

# Validate all supposedly valid BOMs
for file in cdx-spec/tools/src/test/resources/1.4/valid-*.json; do echo "\n#### $file:" && cyclonedx validate --input-version v1_4 --input-file $file; done

This yields 3 failing validations:

#### tools/src/test/resources/1.4/valid-bom-1.4.json:
Validating JSON BOM...
Validation failed: 
#
BOM is not valid.

#### tools/src/test/resources/1.4/valid-release-notes-1.4.json:
Validating JSON BOM...
Validation failed: 
#
BOM is not valid.

#### tools/src/test/resources/1.4/valid-service-1.4.json:
Validating JSON BOM...
Validation failed: 
#
BOM is not valid.

The same happens when validating files within tools/src/test/resources/1.4/valid-*.json using --input-version v1_3, albeit only for valid-bom-1.3.json. I did not observe this behavior with XML BOMs.

@nscuro
Copy link
Member Author

nscuro commented Feb 4, 2022

Oh, I see this is a known issue... 😅

https://github.com/CycloneDX/cyclonedx-dotnet-library/blob/main/tests/CycloneDX.Core.Tests/Json/v1.4/ValidationTests.cs#L53-L54

The schemas do not differ in a way that could explain this.

$ diff cyclonedx-specification/schema/bom-1.4.schema.json cyclonedx-dotnet-library/src/CycloneDX.Core/Schemas/bom-1.4.schema.json 
614c614
<           "$ref": "spdx.schema.json",
---
>           "$ref": "file://spdx.schema.json",
1692c1692
<       "$ref": "jsf-0.82.schema.json#/definitions/signature",
---
>       "$ref": "file://jsf-0.82.schema.json#/definitions/signature",

Could this be an issue with the JSON schema library used?

@nscuro
Copy link
Member Author

nscuro commented Feb 4, 2022

I was able to debug this by lifting these restrictions of adding validation results to the output message.

Looks like the BOMs are indeed not valid and the JSON schema validator does its job as expected.
The test files are invalid, because the email fields within them do not contain valid email addresses...

The JSON schema validator used in cyclonedx-dotnet-library appears to be too strict WRT email addresses (idn-email):

File Relevant ValidationResult Offending Field Line
valid-bom-1.4.json #/components/0/pedigree/commits/0/author/email: Value does not match format 'idn-email' "email": ""
valid-release-notes-1.4.json #/services/0/provider/contact/0/email: Value does not match format 'idn-email' "email": "support@partner",
valid-service-1.4.json #/services/0/provider/contact/0/email: Value does not match format 'idn-email' "email": "support@partner",

In all other files, addresses are either valid (as in, have a TLD) or are simply not present at all. When adding a TLD, validation succeeds.

However, AFAICT, the RFCs behind idn-email do not require "dotted" domain names. A single host name should be fine as well, see for example https://datatracker.ietf.org/doc/html/rfc5321#section-2.3.5.

Is this a bug in the schema library then? Their implementation of idn-email validation is borrowed directly from Microsoft...

nscuro added a commit to CycloneDX/cyclonedx-go that referenced this issue Feb 4, 2022
see CycloneDX/cyclonedx-cli#202

Signed-off-by: nscuro <nscuro@protonmail.com>
nscuro added a commit to CycloneDX/cyclonedx-go that referenced this issue Feb 7, 2022
* ci: update cyclonedx-cli: `0.15.2` -> `0.22.0`

Signed-off-by: nscuro <nscuro@protonmail.com>

* test: fix cyclonedx-cli invocation

Signed-off-by: nscuro <nscuro@protonmail.com>

* test: rename testdata files to not include spec version

will allow us to spot differences after v1.4 update more easily

Signed-off-by: nscuro <nscuro@protonmail.com>

* test: add testdata input files for v1.4

Signed-off-by: nscuro <nscuro@protonmail.com>

* wip: implement v1.4 changes

adds release notes and vulnerabilities

Signed-off-by: nscuro <nscuro@protonmail.com>

* use `string` for timestamp fields; fix `response` field for json

Signed-off-by: nscuro <nscuro@protonmail.com>

* move new types to `cyclonedx.go`

Signed-off-by: nscuro <nscuro@protonmail.com>

* fix affected versions for json

Signed-off-by: nscuro <nscuro@protonmail.com>

* update snapshots for v1.4

Signed-off-by: nscuro <nscuro@protonmail.com>

* make json validator happy

see CycloneDX/cyclonedx-cli#202

Signed-off-by: nscuro <nscuro@protonmail.com>

* add jsf model

Signed-off-by: nscuro <nscuro@protonmail.com>

* Revert "add jsf model"

This reverts commit abee4cf.

JSF support will be implemented with #17

Signed-off-by: nscuro <nscuro@protonmail.com>

Closes #14
@haf-tech
Copy link

probably an other case

  • BOM generated
  • afterwards validate

and the generated BOM is not valid, without any modification

/cyclonedx add files --no-input --output-format json --output-file sbom.json --exclude /.git/**
Processing base path /workspace/source/src
Processing include pattern **/**
Processing exclude pattern /.git/**
Adding file .classpath
Adding file .project
Adding ...

/cyclonedx validate --input-file sbom.json --input-format json --input-version v1_4 --fail-on-errors
Validating JSON BOM...
Validation failed: Required properties [version] were not present
#/required
BOM is not valid.

@rseddon
Copy link

rseddon commented Jun 7, 2023

Another way to reproduce this is to use a BOM that has invalid licenses in it. This one did it for me, the validation fails with no message:

"licenses": [ { "license": { "id": "NOASSERTION", "url": "https://github.com/Humanizr/Humanizer/blob/main/LICENSE" } } ],

As a test, I changed to MIT and then the BOM validated.

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

No branches or pull requests

3 participants