【发布时间】:2022-01-07 15:18:37
【问题描述】:
我们正在使用 java 和 spring boot。我想从HttpServletRequest 中读取一些标头值。
String header = request.getHeader("SomeHeader");
但是我们的代码质量工具是这样抱怨的:
The application's testMethod embeds untrusted data in the generated output with SomeHeader, at line 265 of src\main\java\com\test\poc\controller\Test.java. This untrusted data is embedded straight into the output without proper sanitization or encoding, enabling an attacker to inject malicious code into the output.
The attacker would be able to alter the returned web page by simply providing modified data in the user input getHeader, which is read by the getCorrelationId method at line 265 of src\main\java\com\test\poc\controller\Test.java. This input then flows through the code straight to the output web page, without sanitization.
This can enable a Reflected Cross-Site Scripting (XSS) attack.
我已经使用 owasp 编码器依赖项搜索并尝试了以下代码,但仍然存在相同的问题。
String header = Encode.forJava(request.getHeader("SomeHeader"));
我的方法如下所示:
private String testMethod(HttpServletRequest request) {
String header = Encode.forJava(request.getHeader("SomeHeader"));
return header;
}
我将在另一个方法中调用上述方法,并想验证它是否为空
private void anotherMethod() {
String header = testMethod();
if (header != null) {
//do something
} else {
//do something
}
}
谁能指导一下如何解决这个问题?
【问题讨论】: