-
Notifications
You must be signed in to change notification settings - Fork 980
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
Make filename check more strict #14027
Changes from all commits
c160729
6bcacc1
e6d540e
a0179ee
31b17ad
fda7678
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1208,10 +1208,20 @@ def file_upload(request): | |||||
# Ensure the filename doesn't contain any characters that are too 🌶️spicy🥵 | ||||||
_validate_filename(filename) | ||||||
|
||||||
# Extract the project name from the filename and normalize it. | ||||||
filename_prefix = pkg_resources.safe_name( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: this is using the deprecated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'd like it to get bunded into the fix for #7811, this is sort of orthogonal. |
||||||
# For wheels, the project name is normalized and won't contain hyphens, so | ||||||
# we can split on the first hyphen. | ||||||
filename.partition("-")[0] | ||||||
if filename.endswith(".whl") | ||||||
# For source releases, we know that the version should not contain any | ||||||
# hypens, so we can split on the last hypen to get the project name. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
else filename.rpartition("-")[0] | ||||||
).lower() | ||||||
|
||||||
# Make sure that our filename matches the project that it is being uploaded | ||||||
# to. | ||||||
prefix = pkg_resources.safe_name(project.name).lower() | ||||||
if not pkg_resources.safe_name(filename).lower().startswith(prefix): | ||||||
if (prefix := pkg_resources.safe_name(project.name).lower()) != filename_prefix: | ||||||
raise _exc_with_message( | ||||||
HTTPBadRequest, | ||||||
f"Start filename for {project.name!r} with {prefix!r}.", | ||||||
|
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.
question: now that we're paramtrizing .whl files in the test case, does the same TAR_GZ behavior name apply to those files as well? Or is this 100% a testing-only behavior and we're unlikely to hit a whl-specific condition on prod? I suspect it's fine, but wanted to ask.
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.
The file contents don't really matter here as long as the hashes match, but I agree this could be a little confusing to future travelers.