Repository navigation
fix(validation): reject malformed purl external references - #919
Open
francisco-carneiro wants to merge 1 commit into
Open
francisco-carneiro wants to merge 1 commit into
francisco-carneiro wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This change addresses malformed Package URL (PURL) external reference locators that are incorrectly accepted by the SPDX validator.
The existing
PURL_REGEXandre.matchbehavior 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
re.fullmatchexclusively to PURL references.Validation
The following checks passed locally:
End-to-end validation confirmed that:
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.