-
Notifications
You must be signed in to change notification settings - Fork 78
Potential fix for code scanning alert no. 1: Arbitrary file access during archive extraction ("Zip Slip") #445
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
base: master
Are you sure you want to change the base?
Conversation
…ring archive extraction ("Zip Slip") Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@@ -80,7 +80,16 @@ | |||
if (log.isLoggable(Level.FINER)) { | |||
log.log(Level.FINER, "Jar entry: " + entry.getName()); | |||
} | |||
children.add(entry.getName()); | |||
String entryName = entry.getName(); |
Check failure
Code scanning / CodeQL
Arbitrary file access during archive extraction ("Zip Slip") High
file system operation
Unsanitized archive entry, which may contain '..', is used in a
file system operation
Unsanitized archive entry, which may contain '..', is used in a
file system operation
Unsanitized archive entry, which may contain '..', is used in a
file system operation
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 11 days ago
To fix the issue, we need to ensure that the entry.getName()
value is sanitized and validated before it is used in any file system operations or added to the children
list. Specifically:
- Use
File.getCanonicalFile()
to normalize the file path and ensure it does not escape the intended base directory. - Perform the validation check immediately after constructing the file path and before adding it to the
children
list or performing any other operations. - Log a warning and skip any entries that fail the validation.
The fix will involve modifying the code in the list
method to ensure that all file paths derived from entry.getName()
are properly validated.
-
Copy modified lines R92-R93
@@ -91,3 +91,4 @@ | ||
} | ||
children.add(entryName); | ||
// Add only the sanitized and validated entry name | ||
children.add(entryFile.getName()); | ||
} |
Potential fix for https://github.com/mybatis/migrations/security/code-scanning/1
To fix the issue, we need to validate the
entry.getName()
value to ensure it does not contain directory traversal sequences (../
) or absolute paths. This can be achieved by normalizing the constructed path and verifying that it remains within the intended base directory. Specifically:java.nio.file.Path
to construct and normalize the path.The fix will be applied in the
listResources
method (or equivalent logic) whereentry.getName()
is processed.Suggested fixes powered by Copilot Autofix. Review carefully before merging.