You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by GitBox <gi...@apache.org> on 2022/11/29 14:47:03 UTC
[GitHub] [brooklyn-server] ahgittin commented on a diff in pull request #1372: Prevent zip slip
ahgittin commented on code in PR #1372:
URL: https://github.com/apache/brooklyn-server/pull/1372#discussion_r1034851794
##########
core/src/main/java/org/apache/brooklyn/util/core/file/ArchiveUtils.java:
##########
@@ -363,21 +363,38 @@ public static String readFullyString(File sourceFile) {
}
public static void extractZip(final ZipFile zip, final String targetFolder) {
- new File(targetFolder).mkdir();
+ File targetPath = new File(targetFolder);
+ targetPath.mkdir();
Enumeration<? extends ZipEntry> zipFileEntries = zip.entries();
while (zipFileEntries.hasMoreElements()) {
- ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
- File destFile = new File(targetFolder, entry.getName());
+ ZipEntry entry = zipFileEntries.nextElement();
+ String originalName = entry.getName();
+ File destFile = new File(targetPath, originalName);
+ // validate input path
+ try {
+ String canonicalDestinationDirPath = null;
+ // enforce the file uses the appropriate file separator for the controller SO
+ String sanitizedName = originalName
+ .replace("\\", File.separator)
+ .replace("/", File.separator);
+ File sanitizedDestFile = new File(targetPath, sanitizedName);
+ canonicalDestinationDirPath = targetPath.getCanonicalPath();
Review Comment:
i thought `getCanonicalPath()` didn't work unless the path existed. but a quick test reveals i was wrong. looks good.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org