以下に示すように、クライアントから文字列を受け取るエンドポイントがあります。
@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 スキャンに合格するために適切にサニタイズまたは検証するにはどうすればよいですか?