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

Fix code scanning alert no. 39: Arbitrary file access during archive extraction ("Zip Slip") #1225

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

lfoppiano
Copy link
Collaborator

Fixes https://github.com/kermitt2/grobid/security/code-scanning/39

To fix the problem, we need to ensure that the file paths constructed from zip entries are validated to prevent writing files to unexpected locations. This can be achieved by normalizing the file paths and ensuring they start with the intended destination directory.

  1. Normalize the file path using toPath().normalize().
  2. Check if the normalized path starts with the destination directory path using startsWith().
  3. If the check fails, throw an exception to prevent writing the file.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…extraction ("Zip Slip")

Fix the possibility that someone would download a sneaky grobid home which will be used to write arbitrary files outside the designated temporary directory

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@lfoppiano lfoppiano marked this pull request as ready for review January 10, 2025 09:07
@coveralls
Copy link

Coverage Status

coverage: 40.824% (-0.005%) from 40.829%
when pulling 1c1df62 on alert-autofix-39
into 2ab61a6 on master.

@lfoppiano lfoppiano merged commit f6ac80f into master Jan 10, 2025
8 of 10 checks passed
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