我正在尝试消除 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.
I tried:
private void writeOutput(String passwordRules, PrintWriter out) {
...
@FortifyNotPassword String rules = passwordRules;
out.print(rules);
...
}
...但这并不能消除误报。 (这违背了我不降低代码可读性的原则)。
我也用@FortifyNotPrivate尝试了上述方法,得到了相同的结果。
那么这样做的正确方法是什么?