Skip to content

Commit 5812084

Browse files
[fix] fix for code scanning alert no. 48: Uncontrolled data used in path expression (#23985)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent eb7a4f3 commit 5812084

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

pulsar-package-management/filesystem-storage/src/main/java/org/apache/pulsar/packages/management/storage/filesystem/FileSystemPackagesStorage.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ public class FileSystemPackagesStorage implements PackagesStorage {
5959
}
6060

6161
private File getPath(String path) throws IOException {
62-
if (path.contains("..")) {
62+
// Normalize the path to remove any redundant path elements
63+
File f = Paths.get(storagePath.toString(), path).normalize().toFile();
64+
65+
// Ensure the normalized path is still within the storagePath
66+
if (!f.getAbsolutePath().startsWith(storagePath.getAbsolutePath())) {
6367
throw new IOException("Invalid path: " + path);
6468
}
6569

66-
File f = Paths.get(storagePath.toString(), path).toFile();
6770
if (!f.getParentFile().exists()) {
6871
if (!f.getParentFile().mkdirs()) {
6972
throw new RuntimeException("Failed to create parent dirs for " + path);

0 commit comments

Comments
 (0)