task-162: 路径穿越输入矩阵(../、..\、绝对路径、%2e 编码、全角点、混合分隔符、空字节全部拒绝)+ 9 条测试

This commit is contained in:
2026-09-02 07:25:49 +08:00
parent 035ec9ac79
commit 0e4d680aef
2 changed files with 79 additions and 2 deletions
@@ -33,15 +33,21 @@ public final class PathSafetyGuard {
return childPath.startsWith(rootPath) && !childPath.equals(rootPath);
}
/** 路径名是否含穿越特征(../、绝对路径、盘符、反斜杠)。 */
/**
* 路径名是否含穿越特征(../、..\\、绝对路径、盘符、URL 编码点 %2e、
* 全角点 .、混合分隔符、空字节)。
*/
public static boolean isTraversal(String name) {
if (name == null || name.isBlank()) {
return true;
}
return name.contains("..")
|| name.contains("%2e") || name.contains("%2E")
|| name.contains("")
|| name.startsWith("/")
|| name.matches("^[A-Za-z]:.*")
|| name.contains("\\");
|| name.contains("\\")
|| name.contains("\0");
}
private static Path resolve(File file) {