checkmarx:Files.readAllBytes 和 Files.readAllLines 的存储绝对路径遍历

问题描述 投票:0回答:1

我在 Java 代码中捕获了 2 个操作的“存储绝对路径遍历”:

 byte[] buffer = Files.readAllBytes(dir);
                 Files.readAllLines(dir)   

参数目录创建如下:

 Path dir = Paths.get(Paths.get(base, parts).normalize().toString().replace(" ", "_"));

因此,我尝试通过规范化和替换空字符来清理路径创建,但这不起作用。

security checkmarx sast
1个回答
0
投票
  1. 使用 File.getCanonicalPath 方法解析 parts 参数中的任何符号链接、相对路径或冗余组件。
  2. 使用File.getAbsolutePath方法获取基参数的绝对路径。
© www.soinside.com 2019 - 2024. All rights reserved.