我正在处理源代码中的一些覆盖问题。我在这里使用 代码如下,
filePath = properties.getProperty("DO.LIB.LOC");
String fileName = (String) request.getParameter("read");
filePath += "/" + fileName;
downloadResultSet.flushFile(filePath, response,
fileName.substring(fileName.lastIndexOf(".") + 1));
In my coveiry scanned tool found an error like "CID 38762 (#1 of 2): Filesystem path, filename, or URI manipulation (PATH_MANIPULATION) 2. sink: Constructing a path or URI using the tainted value filePath. This may allow an attacker to access, modify, or test the existence of critical or sensitive files. The value is used unsafely in bytecode, which cannot be displayed."
外部属性文件中定义的文件路径和文件名取自 请求。
我在不同的java文件中使用相同的代码进行文件上传、删除 ,下载功能。我怎样才能避免这些漏洞 从我的代码中。任何人都可以帮我解决这个问题吗?
最佳答案
您应该使用 Path 类型而不是 String (https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Path.html)
它看起来像这样:
Path path = Paths.get(properties.getProperty("DO.LIB.LOC"));
path = path.resolve(Paths.get(request.getParameter("read")));
关于java - java 中文件系统路径、文件名或 URI 操作的 Coverity 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44321371/