Skip to content

Commit fa17db7

Browse files
tballisonCopilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent d2d8ad2 commit fa17db7

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

tika-core/src/main/java/org/apache/tika/io/FilenameUtils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,18 @@ public static Path resolveWithin(Path dir, String name) throws IOException {
300300
"'" + name + "' resolves to '" + resolved + "', which is outside of '" +
301301
normalizedDir + "'");
302302
}
303+
304+
// Defense in depth against symlink traversal (only possible if the paths exist).
305+
if (java.nio.file.Files.exists(resolved) && java.nio.file.Files.exists(normalizedDir)) {
306+
Path realDir = normalizedDir.toRealPath();
307+
Path realResolved = resolved.toRealPath();
308+
if (!realResolved.startsWith(realDir)) {
309+
throw new IOException(
310+
"'" + name + "' resolves to '" + realResolved + "', which is outside of '" +
311+
realDir + "'");
312+
}
313+
}
314+
303315
return resolved;
304316
}
305317

0 commit comments

Comments
 (0)