You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Validating an SPDX 2.2 or 2.3 document accepts malformed purl external reference locators (including unencoded spaces, missing package names, numeric package types, and trailing newlines), which allows pyspdxtools to convert an invalid JSON SBOM into a Tag-Value .spdx file that pyspdxtools itself fails to parse.
Actual: pyspdxtools -i sbom.spdx.json -o sbom.spdx exits 0 with no validation errors and writes sbom.spdx, and reading sbom.spdx back exits 1 with:
ERROR:root:There have been issues while parsing the provided document:
Error while parsing Package: ["Couldn't split PackageExternalRef in category, reference_type and locator. Line: 18"]
Expected: pyspdxtools -i sbom.spdx.json -o sbom.spdx should fail validation (exit 1) before writing sbom.spdx and report all four malformed purl locators, per SPDX 2.3 Annex F.3.5 and Clause 7.21.1.
Versions
spdx-tools0.8.5 (PyPI) and main (cef432adee09dbff2eedf7e33e4aa8be7c11ccfd)
Python 3.11.2 on Linux x86_64
Root cause
In src/spdx_tools/spdx/validation/external_package_ref_validator.py, PURL_REGEX (^pkg:.+(\/.+)?\/.+(@.+)?(\?.+)?(#.+)?$) uses greedy .+ (making its four optional component groups vacuous and matching spaces, /, @, and invalid type characters), and validate_against_regex uses re.match instead of re.fullmatch (allowing a trailing \n before $).
Thank you for the detailed report and reproduction steps.
I have reproduced the issue and prepared a local patch addressing the malformed PURL locators, including regression tests and end-to-end validation.
The proposed change is limited to PURL validation, preserving the existing behavior of other external reference types.
Validation results:
63 targeted validation tests passed.
Full local test suite: 1,040 passed, 4 skipped.
Successful end-to-end verification of JSON-to-Tag-Value conversion and parsing.
This is an incremental structural validation improvement, rather than a complete ECMA-427 implementation.
AI-assisted tools were used during analysis, implementation, testing, and documentation.
I would be happy to contribute the patch through a pull request and welcome any maintainer guidance regarding the proposed approach or applicable contribution requirements.
Activity
francisco-carneiro commentedon Dec 2, 2026
Hi @trackoor,
Thank you for the detailed report and reproduction steps.
I have reproduced the issue and prepared a local patch addressing the malformed PURL locators, including regression tests and end-to-end validation.
The proposed change is limited to PURL validation, preserving the existing behavior of other external reference types.
Validation results:
This is an incremental structural validation improvement, rather than a complete ECMA-427 implementation.
AI-assisted tools were used during analysis, implementation, testing, and documentation.
I would be happy to contribute the patch through a pull request and welcome any maintainer guidance regarding the proposed approach or applicable contribution requirements.
Thank you!
fix(validation): reject malformed purl external references