5

Fority Scan は、次のスニペットで「パス操作」セキュリティの問題を報告しました

String filePath = getFilePath(fileLocation, fileName);
final File file = new File(filePath);
LOGGER.info("Saving report at : " + filePath);
BufferedWriter fileWriter = new BufferedWriter(new FileWriter(file));
fileWriter.write(fileContent);

そのため、fileLocation でブラックリストに登録された文字をチェックして例外をスローしていますが、Fortify は例外をスローしています。

try {
    String filePath = getFilePath(fileLocation, fileName);
    if (isSecurePath(filePath)) {
      final File file = new File(filePath);
      LOGGER.info("Saving report at : " + filePath);
      BufferedWriter  fileWriter = new BufferedWriter(new FileWriter(file));
      fileWriter.write(fileContent);
    } else {
      throw new Exception("Security Issue. File Path has blacklisted characters");
    }

} catch (final Exception e) {
    LOGGER.error("Unable to prepare mail attachment : ", e);
    message = "Mail cannot be send, Unable to prepare mail attachment";
}


private boolean isSecurePath(String filePath) {
    String[] blackListChars = {".."};
    return (StringUtils.indexOfAny(filePath, blackListChars)< 0);
}

スキャンレポートを無視する必要がありますか、それともこれに対する正しい修正は何ですか?

4

1 に答える 1