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

Make filename check more strict #14027

Merged
merged 6 commits into from
Jun 26, 2023
Merged

Conversation

di
Copy link
Member

@di di commented Jun 26, 2023

This ensures that the filenames of uploaded files only have the actual project name where the project name should be. Previously, this allowed filenames that started with the project name, so a file no-way-{version}.tar.gz could be uploaded to the no project, effectively making the filename unusable for the no-way project due to our policy on filename reuse.

Towards #7811, but doesn't totally fix it.

@di di requested a review from a team as a code owner June 26, 2023 21:06
@di di enabled auto-merge (squash) June 26, 2023 21:09
Copy link
Member

@miketheman miketheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typos suggested for fixin' and a couple of non-blocking questions.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# hypens, so we can split on the last hypen to get the project name.
# hyphens, so we can split on the last hyphen to get the project name.

@@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: ‏this is using the deprecated pkg_resources package - should we take the time now to replace, or do you want for forge ahead and let this get bundled into #13991 (or another)?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.


db_request.POST = MultiDict(
{
"metadata_version": "1.2",
"name": project.name,
"version": release.version,
"filetype": "sdist",
"md5_digest": "nope!",
"md5_digest": _TAR_GZ_PKG_MD5,
Copy link
Member

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.

Copy link
Member Author

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.

@di di merged commit 49217ed into pypi:main Jun 26, 2023
@di di deleted the make-filename-check-more-strict branch June 26, 2023 21:16
th3coop pushed a commit to ActiveState/warehouse that referenced this pull request Jun 27, 2023
* Add a failing test

* Make the test fail all the way to DID NOT RAISE

* Refactor the test a bit

* Add another failing test case

* More test cases

* Ensure filenames only have the project name

No more, no less. Previously this allowed filenames that started with
the project name.
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

Successfully merging this pull request may close these issues.

2 participants