如何解决SonarQube问题:确保扩展此存档文件是安全的
我有从zip文件扩展文件的代码:
**private void checkZipFile(ZipInputStream zis) throws OnboardException {
ZipEntry zipEntry;
try {
int entries=0;
while ((zipEntry = zis.getNextEntry()) != null) {
entries++;
if(validateFileName(zipEntry.getName(),System.getProperty("user.dir")) || zipEntry.getSize()>0x6400000 || entries>5000 || zipEntry.getName().contains("..")) {
System.out.println("File is outside extraction target directory.");
}
}
}
private boolean validateFileName(String fileName,String dist) throws IOException {
File destDir = utils.createFile(dist);
String canonicalDestDirPath = destDir.getCanonicalPath();
System.out.println("1---------"+canonicalDestDirPath);
File destfile = utils.createFile(dist,fileName);
String canonicalDestFile = destfile.getCanonicalPath();
if (!canonicalDestFile.startsWith(canonicalDestDirPath + File.separator)) {
return true;
}
return false;
}**
在SonarQube报告中,我在此行遇到了关键安全热点:
while(((zipEntry = zis.getNextEntry())!= null)
我该如何解决?对我来说看起来很安全。
提前谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。