mirror of https://github.com/halo-dev/halo
Fix directory traversal vulnerability
parent
5a5e84158f
commit
d59877a9ce
|
@ -296,7 +296,7 @@ public class FileUtils {
|
|||
Assert.notNull(parentPath, "Parent path must not be null");
|
||||
Assert.notNull(pathToCheck, "Path to check must not be null");
|
||||
|
||||
if (pathToCheck.startsWith(parentPath.normalize())) {
|
||||
if (pathToCheck.normalize().startsWith(parentPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package run.halo.app.utils;
|
|||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import run.halo.app.exception.ForbiddenException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
@ -68,4 +69,14 @@ public class DirectoryAttackTest {
|
|||
System.out.println("Name count: " + path.getNameCount());
|
||||
System.out.println("Normalized path: " + path.normalize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traversalTestWhenSuccess() {
|
||||
FileUtils.checkDirectoryTraversal("/etc/", "/etc/halo/halo/../test");
|
||||
}
|
||||
|
||||
@Test(expected = ForbiddenException.class)
|
||||
public void traversalTestWhenFailure() {
|
||||
FileUtils.checkDirectoryTraversal("/etc/", "/etc/../tmp");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue