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

CTI snapshot unzip tool creation #319

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

abbonno
Copy link
Member

@abbonno abbonno commented Mar 13, 2025

Description

Creates unzip tool.

Issues Resolved

#312

@abbonno abbonno requested a review from a team as a code owner March 13, 2025 11:47
@AlexRuiz7 AlexRuiz7 linked an issue Mar 13, 2025 that may be closed by this pull request
2 tasks
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

Unsanitized archive entry, which may contain '..', is used in a
file system operation
.

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.

  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 changeset 1
plugins/content-manager/src/main/java/com/wazuh/contentmanager/util/Unzip.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/plugins/content-manager/src/main/java/com/wazuh/contentmanager/util/Unzip.java b/plugins/content-manager/src/main/java/com/wazuh/contentmanager/util/Unzip.java
--- a/plugins/content-manager/src/main/java/com/wazuh/contentmanager/util/Unzip.java
+++ b/plugins/content-manager/src/main/java/com/wazuh/contentmanager/util/Unzip.java
@@ -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());
+                }
 
EOF
@@ -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());
}

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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.

CTI snapshot unzip
1 participant