Skip to content

fix(validation): reject malformed purl external references - #919

Open
francisco-carneiro wants to merge 1 commit into
spdx:mainfrom
francisco-carneiro:sa-012-c02/purl-validation
Open

francisco-carneiro wants to merge 1 commit into
spdx:mainfrom
francisco-carneiro:sa-012-c02/purl-validation

Conversation

@francisco-carneiro

Copy link
Copy Markdown

Description

This change addresses malformed Package URL (PURL) external reference locators that are incorrectly accepted by the SPDX validator.

The existing PURL_REGEX and re.match behavior allow malformed locators, including unencoded spaces, missing package names, numeric package types, and trailing newlines.

As described in #916, this can result in successful JSON-to-Tag-Value conversion producing a document that the same tool subsequently fails to parse.

Changes

  • Tighten the structural validation of PURL external references.
  • Reject empty package names and namespace segments.
  • Reject empty qualifier keys and values.
  • Reject unencoded whitespace and trailing newlines.
  • Apply re.fullmatch exclusively to PURL references.
  • Preserve the existing validation behavior of non-PURL external reference types.
  • Add regression and boundary tests.

Validation

The following checks passed locally:

  • Targeted validation tests: 63 passed.
  • Full local test suite: 1,040 passed, 4 skipped.
  • Eight newly added test cases demonstrated failures against the original implementation.
  • Black, isort, and flake8 checks passed.
  • Compatibility testing across nine external reference types.

End-to-end validation confirmed that:

  • Malformed JSON SBOM input containing invalid PURL locators is rejected before a Tag-Value output file is written.
  • Valid JSON SBOM input is converted successfully, and the resulting Tag-Value document can be parsed.

Scope and limitations

This is an incremental structural validation improvement, not a complete implementation of the ECMA-427 ABNF or a universal PURL validator.

Type-specific PURL validation rules remain outside the scope of this change.

Some permissive PURL parsers normalize malformed or non-canonical input. This change deliberately rejects the specific malformed forms covered by the regression tests.

The official upstream CI matrix has not yet been completed.

Issue reference

Fixes #916.

Attribution

Thanks to @trackoor for the detailed issue report, reproduction steps, and root cause analysis.

Acknowledgment is also given to the UCSB Programming Languages and Software Engineering research group, as credited in the original issue.

AI assistance

AI-assisted tools were used during analysis, implementation, testing, and documentation.

The purl validator used a greedy regex and re.match, accepting raw
spaces, missing names, numeric types, trailing newlines, empty namespace
segments, and empty qualifier keys/values. Tighten the structural
validation and apply re.fullmatch only to purl references, so non-purl
reference validation is unchanged. Add regression and boundary tests.

This is an incremental structural improvement, not a full ECMA-427 ABNF
implementation; type-specific purl rules remain out of scope.

Fixes spdx#916

Signed-off-by: Francisco Carlos Sant'Ana Carneiro <contato@jrtech.help>

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.

external_package_ref_validator: PURL_REGEX and re.match accept malformed purl locators (spaces, missing name, invalid type, trailing newline)

1 participant