Skip to content

Commit a6ad7d6

Browse files
committed
fix: ensure extracted files are within the target directory using real path validation
1 parent 2de9b63 commit a6ad7d6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/java/edu/kit/datamanager/ro_crate/reader/ReadZipStreamStrategy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ private void readCrate(InputStream stream) throws IOException {
120120
while ((localFileHeader = zipInputStream.getNextEntry()) != null) {
121121
String fileName = localFileHeader.getFileName();
122122
File extractedFile = new File(folder, fileName).getCanonicalFile();
123-
if (!extractedFile.toPath().startsWith(folder.getCanonicalPath())) {
123+
Path targetRoot = folder.toPath().toRealPath();
124+
if (!extractedFile.toPath().startsWith(targetRoot)) {
124125
throw new IOException("Entry is outside of target directory: " + fileName);
125126
}
126127
if (localFileHeader.isDirectory()) {

0 commit comments

Comments
 (0)