-
Notifications
You must be signed in to change notification settings - Fork 9
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
CTI snapshot unzip tool creation #319
base: main
Are you sure you want to change the base?
Conversation
ZipEntry entry; | ||
|
||
while ((entry = zipIn.getNextEntry()) != null) { | ||
File filePath = new File(destDirectory, entry.getName()); |
Check failure
Code scanning / CodeQL
Arbitrary file access during archive extraction ("Zip Slip") High
file system operation
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 4 hours ago
To fix the problem, we need to ensure that the output paths constructed from zip archive entries are validated to prevent writing files to unexpected locations. This can be achieved by normalizing the file path and checking that it starts with the destination directory.
- Normalize the file path using
toPath().normalize()
. - Check if the normalized path starts with the destination directory path using
startsWith()
. - If the check fails, throw an exception to prevent writing the file.
-
Copy modified lines R29-R32
@@ -28,3 +28,6 @@ | ||
while ((entry = zipIn.getNextEntry()) != null) { | ||
File filePath = new File(destDirectory, entry.getName()); | ||
File filePath = new File(destDirectory, entry.getName()).toPath().normalize().toFile(); | ||
if (!filePath.toPath().startsWith(new File(destDirectory).toPath().normalize())) { | ||
throw new IOException("Bad zip entry: " + entry.getName()); | ||
} | ||
|
Description
Creates unzip tool.
Issues Resolved
#312