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
Parse purls cautiously in getDeniedChanges #753
Conversation
1e3e4d6
to
abc088e
Compare
abc088e
to
2034bab
Compare
7a330f2
to
45a8276
Compare
45a8276
to
1dd418b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few clarifying comments, but overall LGTM 👍 Thanks for the help on this one and sorry for the release headaches. It should be have been a smell when we had to hack packageurl-js to fit our use case.
The build is breaking, but it looks like it's because it's pulling from the main
branch and still using the packageurl-js so we should be good to merge here?
@@ -59,7 +59,7 @@ inputs: | |||
description: A comma-separated list of package URLs to deny (e.g. "pkg:npm/express, pkg:pypi/pycrypto"). If version specified, only deny matching packages and version; else, deny all regardless of version. | |||
required: false | |||
deny-groups: | |||
description: A comma-separated list of package URLs for group(s)/namespace(s) to deny (e.g. "pkg:npm/express, pkg:pypi/pycrypto") | |||
description: A comma-separated list of package URLs for group(s)/namespace(s) to deny (e.g. "pkg:npm/express/, pkg:pypi/pycrypto/"). Please note that the group name must be followed by a `/`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
That's right, yeah. |
Closes #752
Bottom line: the problems in the linked issue appear to be caused by the fact that we've been playing fast and loose with package-urls in a few different ways:
deny-groups
, we try to accept package-urls with a namespace but no name, but those kinds of package-urls are invalid according to the spec. In order to get around that, we sort of abuse thepackageurl-js
library.package_url
member from the comparison API. However, it appears that this isn't always populated. Specifically, when a dependency has a version range like^1.2.3
, there's no way to format it into a package-url, so we just don't. These missingpackage_url
s have been causing runtime exceptions.pkg:npm/@ns/pkg@1.0.0
even though it's technically invalid. This is helpful for our users, many of whom probably don't know the minutiae of the package-url spec. Thepackageurl-js
library does not make this affordance.What I've done in this PR is write a very simple, permissive parser for package-urls that fits our purposes more closely than
packageurl-js
does. It allows us to parse partial purls, reports errors without throwing them, and tolerates special characters as long as the whole purl can still be unambiguously parsed.In addition, I've made the following changes/improvements:
deny-groups
that requires a namespace to be present. We used to tell users to use a purl fragment likepkg:npm/express
to block theexpress
namespace, butpkg:npm/express
is a complete and valid purl that specifies theexpress
package. Instead, the format should bepkg:npm/express/
, where the trailing/
indicates thatexpress
is a namespace and not a package name.deny-groups
requires a namespace.package_url
for a dependency, get the namespace from the package name.In my test repositories reproducing the error reports we've gotten from users, these changes have successfully fixed the problems.