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 validation of qualifier keys #56

Open
matt-phylum opened this issue Nov 8, 2023 · 0 comments
Open

Incorrect validation of qualifier keys #56

matt-phylum opened this issue Nov 8, 2023 · 0 comments

Comments

@matt-phylum
Copy link

The spec is a little redundant, but here are the important things it says about qualifier keys:

  • "must be composed only of ASCII letters and numbers, '.', '-' and '_' (period, dash and underscore)"
  • "cannot start with a number"
  • "case insensitive"

packageurl-js implements this using the expression /^[a-z]+$/i.test(key) || /[\.-_]/.test(key) (negated and simplified to make this easier to describe).

  • The regular expression (?i)^[a-z]+$ matches for any string which is entirely letters. We'll call this subexpression allLetters.
  • The regular expression [\.-_] matches any ASCII character value between '.' and '_', which includes '/', numbers, '=', etc but doesn't include '-'. This seems like it was meant to be [\.\-_], which matches the three characters that are called out in the spec. We'll call this corrected subexpression containsAllowedSpecial.

Substituting in those names, we get the expression allLetters || containsAllowedSpecial for determining if a qualifier key is valid. Even with the corrected regular expression, this does not match the spec. a1 is invalid because it contains a number, but it should be valid. _! is valid because it contains '_', but it should be invalid because '!' is not an allowed character.

I found this because with the incorrect regular expression, x- prefixed qualifiers are incorrectly considered to be invalid.

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

No branches or pull requests

1 participant