Skip to content
This repository was archived by the owner on Jul 28, 2023. It is now read-only.

Commit f2bd33e

Browse files
author
zhangzhx
committed
AWS Toolkit for Eclipse: v201805311643 Release.
1 parent 8717ded commit f2bd33e

File tree

8 files changed

+146
-2
lines changed

8 files changed

+146
-2
lines changed

CHANGELOG.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"current": [
3-
"* **Update Error Report dialog to include the Github issue link.**"
3+
"* **Update Error Report dialog to include the Github issue link.**",
4+
"* **Fix possible file-system security vulnerability in OpsWorks [ZipUtils](https://github.com/aws/aws-toolkit-eclipse/blob/36e996685b07ea16a4c073245cf52291453ddedb/bundles/com.amazonaws.eclipse.opsworks/src/com/amazonaws/eclipse/opsworks/deploy/util/ZipUtils.java#L58).**"
45
],
56
"v201801042359": [
67
"* **Merge Pull Request #93.**",

bundles/com.amazonaws.eclipse.opsworks/src/com/amazonaws/eclipse/opsworks/deploy/util/ZipUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ public static void unzipFileToDirectory(File zipFile, File targetDirectory) thro
5656

5757
String entryFileName = zipEntry.getName();
5858
File newFile = new File(targetDirectory, entryFileName);
59-
59+
if (!newFile.getCanonicalPath().startsWith(targetDirectory.getCanonicalPath())) {
60+
throw new RuntimeException(newFile.getAbsolutePath() + " is outside of targetDirectory: " + targetDirectory.getAbsolutePath());
61+
}
62+
6063
if (zipEntry.isDirectory()) {
6164
if ( !newFile.exists() ) {
6265
newFile.mkdirs();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>com.amazonaws.eclipse.opsworks.tests</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.m2e.core.maven2Builder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
31+
<nature>org.eclipse.pde.PluginNature</nature>
32+
<nature>org.eclipse.jdt.core.javanature</nature>
33+
</natures>
34+
</projectDescription>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: AWS OpsWorks Plugin Tests
4+
Bundle-SymbolicName: com.amazonaws.eclipse.opsworks.tests
5+
Bundle-Version: 1.0.0.qualifier
6+
Bundle-Vendor: AMAZONAWS
7+
Fragment-Host: com.amazonaws.eclipse.opsworks;bundle-version="1.0.0"
8+
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
9+
Require-Bundle: org.junit;bundle-version="4.11.0"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source.. = src/
2+
output.. = bin/
3+
bin.includes = META-INF/,\
4+
.
5+
src.includes = src/,\
6+
META-INF/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<artifactId>com.amazonaws.eclipse.opsworks.tests</artifactId>
6+
<version>1.0.0-SNAPSHOT</version>
7+
<packaging>eclipse-test-plugin</packaging>
8+
9+
<parent>
10+
<groupId>com.amazonaws.eclipse</groupId>
11+
<artifactId>com.amazonaws.eclipse.tests</artifactId>
12+
<version>1.0.0-SNAPSHOT</version>
13+
</parent>
14+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.amazonaws.eclipse.opsworks.deploy.util;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static com.amazonaws.eclipse.opsworks.deploy.util.ZipUtils.unzipFileToDirectory;
5+
6+
import java.io.ByteArrayInputStream;
7+
import java.io.File;
8+
import java.io.FileInputStream;
9+
import java.io.FileOutputStream;
10+
import java.io.IOException;
11+
import java.nio.charset.StandardCharsets;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
14+
import java.util.Map;
15+
import java.util.stream.Collectors;
16+
import java.util.zip.ZipEntry;
17+
import java.util.zip.ZipOutputStream;
18+
import org.apache.commons.io.IOUtils;
19+
import org.junit.Rule;
20+
import org.junit.Test;
21+
import org.junit.rules.TemporaryFolder;
22+
23+
public class ZipUtilsTest {
24+
25+
@Rule
26+
public TemporaryFolder folder = new TemporaryFolder();
27+
28+
@Test
29+
public void canUnpackAZipFileToDirectory() throws IOException {
30+
File zipFile = folder.newFile("file.zip");
31+
File target = folder.newFolder("target");
32+
ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipFile));
33+
34+
writeEntry(zipOutputStream, "foo/bar.txt", "hello foo-bar!");
35+
writeEntry(zipOutputStream, "baz.txt", "hello baz!");
36+
writeEntry(zipOutputStream, "foo/../root.txt", "hello root!");
37+
38+
zipOutputStream.close();
39+
40+
unzipFileToDirectory(zipFile, target);
41+
42+
Map<String, String> actual = Files.walk(target.toPath()).filter(p -> p.toFile().isFile()).collect(Collectors.toMap(p -> target.toPath().relativize(p).toString(), this::content));
43+
assertEquals("hello foo-bar!", actual.get("foo/bar.txt"));
44+
assertEquals("hello baz!", actual.get("baz.txt"));
45+
assertEquals("hello root!", actual.get("root.txt"));
46+
}
47+
48+
@Test(expected = RuntimeException.class)
49+
public void exceptionThrownIfRelativeFileAttemptsToLeaveParentDirectory() throws IOException {
50+
File zipFile = folder.newFile("file.zip");
51+
File target = folder.newFolder("target");
52+
ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipFile));
53+
54+
writeEntry(zipOutputStream, "foo/bar.txt", "hello foo-bar!");
55+
writeEntry(zipOutputStream, "../baz.txt", "hello baz!");
56+
57+
zipOutputStream.close();
58+
59+
unzipFileToDirectory(zipFile, target);
60+
}
61+
62+
private void writeEntry(ZipOutputStream zipOutputStream, String name, String content) throws IOException {
63+
zipOutputStream.putNextEntry(new ZipEntry(name));
64+
IOUtils.copy(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), zipOutputStream);
65+
zipOutputStream.closeEntry();
66+
}
67+
68+
private String content(Path p) {
69+
try {
70+
return IOUtils.toString(new FileInputStream(p.toFile()));
71+
} catch (IOException e) {
72+
throw new RuntimeException(e);
73+
}
74+
}
75+
76+
}

tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<module>com.amazonaws.eclipse.elasticbeanstalk.tests</module>
1717
<module>com.amazonaws.eclipse.lambda.tests</module>
1818
<module>com.amazonaws.eclipse.simpledb.tests</module>
19+
<module>com.amazonaws.eclipse.opsworks.tests</module>
1920
</modules>
2021

2122
<build>

0 commit comments

Comments
 (0)