I have sample Spring boot controller code like followings:
@Slf4j
@RestController
public class PersonController {
private final PersonService PersonService;
public PersonController(PersonService PersonService) {
this.PersonService = PersonService;
}
@PostMapping(value = "/v1/Person", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public PersonResponseDto Person(@Valid @RequestBody PersonRequestDto PersonRequestDto,
@RequestHeader(value = "x-correlation-id", required = false) String correlationId) {
String something = HtmlUtils.htmlEscape(PersonRequestDto.getSomething());
PersonRequestDto newRequestDto = PersonRequestDto.builder()
.something(something)
.date(PersonRequestDto.getDate())
.build();
return PersonService.save(newRequestDto);
}
}
public class PersonRequestDto {
@NotBlank
private String something;
private LocalDate date;
}
Even I did a sanitized on a string field something
, the checkmarx still complains:
flows through the code without being properly sanitized or validated and is eventually displayed to the user in method doSomething
I don't know what's the point or how to sanitized the java LocalDate
type field and also for XSS requirement there is no need to sanitized field other than string.
Anyone knows how to write code to make checkmarx happy? I know this is frustrated to write some code just let some tool works.