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

[results-processor] will overwrite files when extracting from a ZIP #4066

Open
gsnedders opened this issue Oct 18, 2024 · 0 comments
Open

[results-processor] will overwrite files when extracting from a ZIP #4066

gsnedders opened this issue Oct 18, 2024 · 0 comments

Comments

@gsnedders
Copy link
Member

In the following:

with zipfile.ZipFile(artifact, mode='r') as z:
for f in z.infolist():
if f.is_dir():
continue
basename = posixpath.basename(f.filename)
if fnmatch.fnmatchcase(basename, 'wpt_report*.json'):
path = z.extract(f, path=self._temp_dir)
self.results.append(path)
elif fnmatch.fnmatchcase(basename, 'wpt_screenshot*.txt'):
path = z.extract(f, path=self._temp_dir)
self.screenshots.append(path)

There's nothing stopping us from overwriting files that already exist when extracting, and it's hard to check for in advance given ZipFile.extract does some normalization of the path.

This would be bad if someone uploaded archive1.zip and archive2.zip, both containing wptreport.json and wptscreenshot.txt, which feels like a totally sensible thing to do.

We should probably just create a new temporary directory within self._temp_dir (via tempdir.mkdtemp(dir=self._temp_dir) for each archive file we're processing, and extract into that. This still isn't totally safe, but for there to be any risk you really need someone trying to be malicious.

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