【问题标题】:How to fix Fortify Path Manipulation ( Input Validation and Representation , Data Flow ) vulnerability如何修复 Fortify Path Manipulation (Input Validation and Representation, Data Flow) 漏洞
【发布时间】: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 个标志

标签: java file path fortify


【解决方案1】:

这个“sUnsanitized”变量来自用户输入?也许这是你真正的问题。

永远不要相信用户输入,这是发展的第一条规则。

【讨论】:

  • 文件名来自用户输入,除了处理输入别无他法。
  • 您真的需要维护原始文件名吗?如果这是真的,好的。您只需要关心文件名本身。我可以给你发送一个 .cmd、.bat、.exe 之类的东西。如果你关心这个问题,你能把它标记为误报吗?
猜你喜欢
  • 2021-08-14
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
  • 2021-08-20
  • 2020-02-15
  • 2018-12-24
  • 2019-11-13
  • 2020-09-03
相关资源
最近更新 更多