【发布时间】:2019-04-24 06:11:50
【问题描述】:
我正在使用新关键字创建文件的强化路径操作漏洞
我尝试在将路径传递给 File 对象之前对其进行清理,但问题仍然存在。 也试过这个链接: https://www.securecoding.cert.org/confluence/display/java/FIO00-J.+Do+not+operate+on+files+in+shared+directories
public static String sanitizePath(String sUnsanitized) throws URISyntaxException, EncodingException {
String sSanitized = SAPI.encoder().canonicalize(sUnsanitized);
return sSanitized;
}
//// the main method code snippet /////
String sSanitizedPath = Utils.sanitizePath(file.getOriginalFilename());
-- fortify scan detects problem here ..in below line --
File filePath = new File(AppInitializer.UPLOAD_LOCATION, sSanitizedPath);
String canonicalPath = filePath.getCanonicalPath();
FileOutputStream fileOutputStream = new FileOutputStream(canonicalPath);
在 santizePath 之后,我认为扫描不会被挑选,漏洞但是,它确实如此。
【问题讨论】:
-
我尝试了 new File(path.normalize().toString()) 但这也不起作用。事实上它又为漏洞提出了 1 个标志