|
@@ -43,7 +43,7 @@ import picocli.CommandLine.Option;
|
|
@Command(name = "deploy", aliases = "d")
|
|
@Command(name = "deploy", aliases = "d")
|
|
public class DeployCommand extends AbstractCommand {
|
|
public class DeployCommand extends AbstractCommand {
|
|
private static final Logger LOG = LoggerFactory.getLogger(DeployCommand.class);
|
|
private static final Logger LOG = LoggerFactory.getLogger(DeployCommand.class);
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = {"--login-source-directory", "-lssrc"}, defaultValue = DEFAULT_LOGIN_SOURCE_DIR, description = "Login directory")
|
|
@Option(names = {"--login-source-directory", "-lssrc"}, defaultValue = DEFAULT_LOGIN_SOURCE_DIR, description = "Login directory")
|
|
private String loginSourceDirectory = DEFAULT_LOGIN_SOURCE_DIR;
|
|
private String loginSourceDirectory = DEFAULT_LOGIN_SOURCE_DIR;
|
|
@Option(names = {"--game-source-directory", "-gssrc"}, defaultValue = DEFAULT_GAME_SOURCE_DIR, description = "Game directory")
|
|
@Option(names = {"--game-source-directory", "-gssrc"}, defaultValue = DEFAULT_GAME_SOURCE_DIR, description = "Game directory")
|
|
@@ -73,15 +73,15 @@ public class DeployCommand extends AbstractCommand {
|
|
LOG.error("Unable to deploy components!", e);
|
|
LOG.error("Unable to deploy components!", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void processArtifact(String srcDirPath, String dstDirPathStr) throws Exception {
|
|
public void processArtifact(String srcDirPath, String dstDirPathStr) throws Exception {
|
|
- Files.list(Paths.get(srcDirPath, "target")).forEach(p->{
|
|
|
|
|
|
+ Files.list(Paths.get(srcDirPath, "target")).forEach(p -> {
|
|
if (!p.toString().endsWith(".zip")) {
|
|
if (!p.toString().endsWith(".zip")) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
LOG.info("Processing zip file {}", p.toString());
|
|
LOG.info("Processing zip file {}", p.toString());
|
|
-
|
|
|
|
|
|
+
|
|
try {
|
|
try {
|
|
processZip(p, Path.of(dstDirPathStr));
|
|
processZip(p, Path.of(dstDirPathStr));
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -99,7 +99,7 @@ public class DeployCommand extends AbstractCommand {
|
|
if (!Files.exists(dstDirPath)) {
|
|
if (!Files.exists(dstDirPath)) {
|
|
dstDirPath.toFile().mkdirs();
|
|
dstDirPath.toFile().mkdirs();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
for (Path p : zipFs.getRootDirectories()) {
|
|
for (Path p : zipFs.getRootDirectories()) {
|
|
processZipEntry(p, dstDirPath);
|
|
processZipEntry(p, dstDirPath);
|
|
}
|
|
}
|
|
@@ -109,7 +109,7 @@ public class DeployCommand extends AbstractCommand {
|
|
public void processZipEntry(Path zipFsPath, Path dstDirPath) throws Exception {
|
|
public void processZipEntry(Path zipFsPath, Path dstDirPath) throws Exception {
|
|
if (Files.isDirectory(zipFsPath)) {
|
|
if (Files.isDirectory(zipFsPath)) {
|
|
LOG.info("Process directory {}", zipFsPath.toString());
|
|
LOG.info("Process directory {}", zipFsPath.toString());
|
|
- Files.list(zipFsPath).forEach(p->{
|
|
|
|
|
|
+ Files.list(zipFsPath).forEach(p -> {
|
|
try {
|
|
try {
|
|
processZipEntry(p, dstDirPath);
|
|
processZipEntry(p, dstDirPath);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -118,20 +118,20 @@ public class DeployCommand extends AbstractCommand {
|
|
});
|
|
});
|
|
} else if (Files.isRegularFile(zipFsPath)) {
|
|
} else if (Files.isRegularFile(zipFsPath)) {
|
|
checkZipSlip(dstDirPath, zipFsPath);
|
|
checkZipSlip(dstDirPath, zipFsPath);
|
|
-
|
|
|
|
|
|
+
|
|
Path outFilePath = Paths.get(dstDirPath.toString(), zipFsPath.toString());
|
|
Path outFilePath = Paths.get(dstDirPath.toString(), zipFsPath.toString());
|
|
Path parentDirPath = outFilePath.getParent();
|
|
Path parentDirPath = outFilePath.getParent();
|
|
if (!Files.exists(parentDirPath)) {
|
|
if (!Files.exists(parentDirPath)) {
|
|
parentDirPath.toFile().mkdirs();
|
|
parentDirPath.toFile().mkdirs();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
Files.copy(zipFsPath, Paths.get(dstDirPath.toString(), zipFsPath.toString()), StandardCopyOption.REPLACE_EXISTING);
|
|
Files.copy(zipFsPath, Paths.get(dstDirPath.toString(), zipFsPath.toString()), StandardCopyOption.REPLACE_EXISTING);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static void checkZipSlip(Path dstDirPath, Path zipFsPath) throws Exception {
|
|
public static void checkZipSlip(Path dstDirPath, Path zipFsPath) throws Exception {
|
|
Path dstFilePath = Paths.get(dstDirPath.toString(), zipFsPath.toString());
|
|
Path dstFilePath = Paths.get(dstDirPath.toString(), zipFsPath.toString());
|
|
-
|
|
|
|
|
|
+
|
|
if (!dstFilePath.toAbsolutePath().startsWith(dstDirPath.toAbsolutePath())) {
|
|
if (!dstFilePath.toAbsolutePath().startsWith(dstDirPath.toAbsolutePath())) {
|
|
throw new Exception("ZipSlipAttack detected: " + zipFsPath.toString());
|
|
throw new Exception("ZipSlipAttack detected: " + zipFsPath.toString());
|
|
}
|
|
}
|