Skip to content

Check the document SPDX ID in Verify for JSON, YAML and XML - #339

Open
tommyquak wants to merge 1 commit into
spdx:masterfrom
tommyquak:verify-document-spdxid
Open

tommyquak wants to merge 1 commit into
spdx:masterfrom
tommyquak:verify-document-spdxid

Conversation

@tommyquak

Copy link
Copy Markdown

Part of #316.

When a JSON, YAML or XML file is read, the Jackson store skips the document's SPDXID and always creates the document as SPDXRef-DOCUMENT, so SpdxDocument.verify() never sees the original value. A document with any other ID is reported as valid, although the spec requires SPDXRef-DOCUMENT [1]. Tag-value files already fail with "SPDX Document SPDXRef-NOTDOC is invalid. Document IDs must be SPDXRef-DOCUMENT".

As discussed in #316, this checks the ID in Verify itself: it reads the SPDXID from the file and reports the same message as tag-value. I added a test with a JSON, YAML and XML file whose document ID is SPDXRef-NOTDOC.

Tested with mvn verify, checkstyle:check and spotbugs:check on Java 17, and by running the built jar on the files from the issue: the document whose ID SPDXRef-a is also a package ID is now reported as invalid, and the example files are still valid.

Not covered here:

  • If a relationship refers to the wrong document ID, loading fails with "Missing SPDX element for ID ..." before Verify gets to this check, so that error is unchanged.
  • Duplicate IDs, which we agreed to leave for a follow-up.

[1] https://spdx.github.io/spdx-spec/v2.3/document-creation-information/#63-spdx-identifier-field

The Jackson store does not keep the document's SPDXID when it reads a
JSON, YAML or XML file and always creates the document as
SPDXRef-DOCUMENT, so the model's verify never sees the original value
and a document with any other ID was reported as valid. The spec
requires the document SPDXID to be SPDXRef-DOCUMENT [1].

Read the SPDXID from the file in Verify and report it with the same
message the tag-value parser already uses.

Part of Issue 316.

[1] https://spdx.github.io/spdx-spec/v2.3/document-creation-information/#63-spdx-identifier-field

Signed-off-by: Tommy Quak <tommy@u.nus.edu>

This branch has not been deployed

No deployments
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.

1 participant