如何修复“路径操纵漏洞"在某些 Java 代码中? [英] How to fix "Path Manipulation Vulnerability" in some Java Code?
本文介绍了如何修复“路径操纵漏洞"在某些 Java 代码中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下简单的 java 代码获取 Fortify Path Manipulation 错误.请帮我解决这个问题.我挣扎了很长时间.
The below simple java code getting Fortify Path Manipulation error. Please help me to resolve this. I am struggling from long time.
public class Test {
public static void main(String[] args) {
File file=new File(args[0]);
}
}
推荐答案
使用前尝试规范化 URL
Try to normalize the URL before using it
https://docs.oracle.com/javase/7/docs/api/java/net/URI.html#normalize()
Path path = Paths.get("/foo/../bar/../baz").normalize();
或使用 org.apache.commons.io.FilenameUtils
Stirng path = FilenameUtils.normalize("/foo/../bar/../baz");
两者的结果都是 \baz
这篇关于如何修复“路径操纵漏洞"在某些 Java 代码中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文