我有一个端点从客户端接收字符串,如下所示:
@GET
@Path("/{x}")
public Response doSomething(@PathParam("x") String x) {
String y = myService.process(x);
return Response.status(OK).entity(y).build();
}
Checkmarx 抱怨这个元素的值然后“在没有经过适当清理或验证的情况下流经代码,并最终在方法 doSomething 中显示给用户”
然后我尝试了这个:
@GET
@Path("/{x}")
public Response doSomething(@PathParam("x") String x) {
if (StringUtils.trimToNull(x) == null || x.length() > 100) {
throw new RuntimeException();
}
x = x.replace("'", "").replace("`", "").replace("\\", "").replace("\"", "")
String y = myService.process(x);
y = y.replace("'", "").replace("`", "").replace("\\", "").replace("\"", "")
return Response.status(OK).entity(y).build();
}
但它仍然认为这是一个高严重性漏洞。
如何正确清理或验证以通过 Checkmarx 扫描?
html工具 https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/util/HtmlUtils.html from spring-web
完成了工作:
HtmlUtils.htmlEscape(x)
Maven 依赖:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.7.RELEASE</version>
</dependency>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)