【发布时间】:2015-08-12 07:13:28
【问题描述】:
我正在尝试消除 Java 应用程序的 HP Fortify 扫描中的误报。
此方法会导致“隐私违规”问题(PrintWriter 是一个 servlet 响应)
private void writeOutput(String passwordRules, PrintWriter out) {
...
out.print(passwordRules);
...
}
这是因为 Fortify 遵循命名约定,决定 passwordRules 包含私有数据。但我的passwordRules 不是私人数据——它包含诸如“最少 8 个字符”之类的内容。
我可以通过更改变量的名称来消除错误。但是原则上我不想为了源代码分析器的利益而损害我的代码的可读性。
我希望这能解决它:
private void writeOutput(@FortifyNotPassword String passwordRules, PrintWriter out) ...
但是,注释似乎不是针对该上下文编写的:
The annotation @FortifyNotPassword is disallowed for this location.
我试过了:
private void writeOutput(String passwordRules, PrintWriter out) {
...
@FortifyNotPassword String rules = passwordRules;
out.print(rules);
...
}
... 但这并不能消除误报。 (而且它损害了我不降低代码可读性的原则)。
我也用@FortifyNotPrivate 尝试了上述方法,结果相同。
那么正确的做法是什么?
【问题讨论】:
-
糟糕!错过了那一段。道歉。