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

Commit ec22e98

Browse files
authored
guard 3rd party package installation path (#2687)
* check 3rd party package installation path * fix partial traversal * add validation funcion
1 parent 504c734 commit ec22e98

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

frontend/server/src/main/java/org/pytorch/serve/wlm/ModelManager.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.concurrent.ExecutionException;
2121
import java.util.concurrent.Executors;
2222
import java.util.concurrent.ScheduledExecutorService;
23+
import org.apache.commons.io.FileUtils;
2324
import org.pytorch.serve.archive.DownloadArchiveException;
2425
import org.pytorch.serve.archive.model.Manifest;
2526
import org.pytorch.serve.archive.model.ModelArchive;
@@ -238,7 +239,14 @@ private void setupModelDependencies(Model model)
238239
null);
239240

240241
ProcessBuilder processBuilder = new ProcessBuilder(commandParts);
241-
processBuilder.directory(model.getModelDir().getAbsoluteFile());
242+
if (isValidDependencyPath(dependencyPath)) {
243+
processBuilder.directory(dependencyPath);
244+
} else {
245+
throw new ModelException(
246+
"Invalid 3rd party package installation path "
247+
+ dependencyPath.getCanonicalPath());
248+
}
249+
242250
Map<String, String> environment = processBuilder.environment();
243251
for (String envVar : envp) {
244252
String[] parts = envVar.split("=", 2);
@@ -274,6 +282,16 @@ private void setupModelDependencies(Model model)
274282
}
275283
}
276284

285+
private boolean isValidDependencyPath(File dependencyPath) {
286+
if (dependencyPath
287+
.toPath()
288+
.normalize()
289+
.startsWith(FileUtils.getTempDirectory().toPath().normalize())) {
290+
return true;
291+
}
292+
return false;
293+
}
294+
277295
private Model createModel(
278296
ModelArchive archive,
279297
int batchSize,

0 commit comments

Comments
 (0)