Skip to content
This repository was archived by the owner on Jun 7, 2022. It is now read-only.

Commit e631302

Browse files
derropGiantTreeLP
authored andcommitted
Protection against arbitrary file write during archive extraction
1 parent 60bb564 commit e631302

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

cloudnet-core/src/main/java/de/dytanic/cloudnetcore/web/api/v1/WebsiteDeployment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.io.*;
1717
import java.nio.charset.StandardCharsets;
18+
import java.nio.file.Paths;
1819
import java.util.ArrayList;
1920
import java.util.Arrays;
2021
import java.util.Collections;
@@ -136,6 +137,11 @@ public FullHttpResponse post(ChannelHandlerContext channelHandlerContext,
136137

137138
private void extractEntry(ZipFile zipFile, ZipEntry entry, String destDir) throws IOException {
138139
File file = new File(destDir, entry.getName());
140+
141+
if (!file.toPath().normalize().startsWith(Paths.get(destDir))) {
142+
return;
143+
}
144+
139145
final byte[] BUFFER = new byte[0xFFFF];
140146

141147
if (entry.isDirectory()) {

cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/network/packet/in/PacketInCreateTemplate.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ public void handleInput(Document data, PacketSender packetSender) {
199199

200200
private void extractEntry(ZipFile zipFile, ZipEntry entry, String destDir) throws IOException {
201201
File file = new File(destDir, entry.getName());
202+
203+
if (!file.toPath().normalize().startsWith(Paths.get(destDir))) {
204+
return;
205+
}
206+
202207
final byte[] BUFFER = new byte[0xFFFF];
203208

204209
if (entry.isDirectory()) {

cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/CloudGameServer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,11 @@ public Process getInstance() {
513513

514514
private void extractEntry(ZipFile zipFile, ZipEntry entry, String destDir) throws IOException {
515515
File file = new File(destDir, entry.getName());
516+
517+
if (!file.toPath().normalize().startsWith(Paths.get(destDir))) {
518+
return;
519+
}
520+
516521
final byte[] BUFFER = new byte[0xFFFF];
517522

518523
if (entry.isDirectory()) {

0 commit comments

Comments
 (0)