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

Incorrect cpe23Type validation? #796

Open
anthonyharrison opened this issue Feb 5, 2024 · 3 comments
Open

Incorrect cpe23Type validation? #796

anthonyharrison opened this issue Feb 5, 2024 · 3 comments
Labels

Comments

@anthonyharrison
Copy link

The validation of the cpe23Type does not support strings such as

cpe:2.3:a:ahmed_h.:spdx-tools:0.8.3.dev1+g8050fd9c:*:*:*:*:*:*:* The version string contains +

cpe:2.3:a:debian_gcc_maintainers:libstdc++6:12.2.0-9:*:*:*:*:*:*:* The product name contains +. The cpe definition states a product name can not contain spaces, slashes, or most special characters. An underscore should be used in place of whitespace characters. Is '+' considered a special character?

Note that the SPDX file is reported as valid when using the SPDX online tool validator.

Do we have inconsistency in validation between the Python and Java tools.

(Tested with latest version of the Python Tools)

@goneall
Copy link
Member

goneall commented Feb 5, 2024

The online tools are still using the Java implementation - so the validation may be different.

From a quick check, I don't think the verify method in the Java implementation verifies the locator strings for external references - which would be an issue for the Java library.

Note that the SPDX 2.3 spec for external references cpe23 type does provide a REGEX we can use.

@meretp
Copy link
Collaborator

meretp commented Mar 10, 2024

For the validation in the tools-python the regex from the spec is used. So I think this is rather an issue in the Java implementation.
From skipping through the documentation linked in the spec, I think that the "+" should be quoted like "+", for the example mentioned cpe:2.3:a:ahmed_h.:spdx-tools:0.8.3.dev1\+g8050fd9c:*:*:*:*:*:*:* would be valid according to the tools-python validation.

@maxhbr maxhbr added the bug label Jun 6, 2024
@billie-alsup
Copy link

The validation regex is incorrect and has an extra requirement to match \ just before the start of the character class (in two places):

CPE23TYPE_REGEX = (
    r'^cpe:2\.3:[aho\*\-](:(((\?*|\*?)([a-zA-Z0-9\-\._]|(\\[\\\*\?!"#$$%&\'\(\)\+,\/:;<=>@\[\]\^'
    r"`\{\|}~]))+(\?*|\*?))|[\*\-])){5}(:(([a-zA-Z]{2,3}(-([a-zA-Z]{2}|[0-9]{3}))?)|[\*\-]))(:(((\?*"
    r'|\*?)([a-zA-Z0-9\-\._]|(\\[\\\*\?!"#$$%&\'\(\)\+,\/:;<=>@\[\]\^`\{\|}~]))+(\?*|\*?))|[\*\-])){4}$'
)

Should be perhaps

CPE23TYPE_REGEX = (
    r'^cpe:2\.3:[aho\*\-](:(((\?*|\*?)([a-zA-Z0-9\-\._]|([\\\*\?!"#$$%&\'\(\)\+,\/:;<=>@\[\]\^'
    r"`\{\|}~]))+(\?*|\*?))|[\*\-])){5}(:(([a-zA-Z]{2,3}(-([a-zA-Z]{2}|[0-9]{3}))?)|[\*\-]))(:(((\?*"
    r'|\*?)([a-zA-Z0-9\-\._]|([\\\*\?!"#$$%&\'\(\)\+,\/:;<=>@\[\]\^`\{\|}~]))+(\?*|\*?))|[\*\-])){4}$'
)

However, I note that the requirement to match \ is present in the SPDX 2.2 specification. However, the example provided in the specification would not pass the given regex in the specification either. My own OpenEmbedded SPDX files also fail validation due to this issue, and is fixed by removing that extra leading \ before the character class.

cpe:2.3:a:*:sbsigntool:0.9.2-gitAUTOINC+f12484869c_b1f28e1722:*:*:*:*:*:*:*

The example in the specification, which is

cpe:2.3:o:canonical:ubuntu_linux:10.04::lts:*:*:*:*:*

still fails because the regex does not allow for an empty field. It passes if I put an asterisk in that field though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants