'checkmarx validation XSS

The application's validateComment embeds untrusted data in the generated output with commentDto, at line 474 of web-api\src\main\java\ru\sbrf....\SomeClass.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 request, which is read by the putClientDocuments method at line 33 of web-api\src\main\java\ru\sbrf....\controller\SomeRestController.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.

    private void validateComment(Comment commentDto) {
    commentDto.setText(StringEscapeUtils.escapeHtml(StringEscapeUtils.escapeJavaScript(commentDto.getText())));
    commentDto.setSender(StringEscapeUtils.escapeHtml(StringEscapeUtils.escapeJavaScript(commentDto.getSender())));
    if (commentDto.getCommentId() == null || !StringUtils.hasLength(commentDto.getText()) ||
            commentDto.getIsClient() == null || commentDto.getCreateDate() == null) {
        throw new ValidationException("Комментарий заполнен не корректно");
    }
    if (LocalDateTime.now().isBefore(commentDto.getCreateDate())) {
        throw new ValidationException("Дата комментария указана позже текущей даты");
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source