Skip to content

Potential fix for code scanning alert no. 7: Cross-site scripting - #56

Closed
lgzarturo wants to merge 1 commit into
mainfrom
alert-autofix-7
Closed

Potential fix for code scanning alert no. 7: Cross-site scripting#56
lgzarturo wants to merge 1 commit into
mainfrom
alert-autofix-7

Conversation

@lgzarturo

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/lgzarturo/springboot-course/security/code-scanning/7

To fix the problem, the user-controlled message parameter must not be written directly to the HTTP response without encoding. The usual mitigation is to apply contextual output encoding (HTML escaping in this case) before including it in the response body.

The best minimal change, consistent with the rest of the file, is:

  • Use HtmlUtils.htmlEscape(message) to create a safe version of the input for inclusion in the response text.
  • Continue to send the original message to Sentry, since Sentry accepts arbitrary strings and this does not affect XSS in the HTTP response.
  • Update the returned string to use the escaped value instead of the raw message.

Concretely, in src/main/kotlin/com/lgzarturo/springbootcourse/sentry/adapters/rest/SentryController.kt, inside fun testMessage(...), introduce a new local variable, e.g. val safeMessage = HtmlUtils.htmlEscape(message), and change the return line to return "Message sent to Sentry: $safeMessage". No new imports are needed because HtmlUtils is already imported at line 15.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@lgzarturo
lgzarturo marked this pull request as ready for review April 7, 2026 02:15
@lgzarturo lgzarturo closed this Apr 7, 2026
@lgzarturo

Copy link
Copy Markdown
Owner Author

Coverage Report

Overall Project 64.55% -0.25%
Files changed 0%

File Coverage
SentryController.kt 1.28% -3.85%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant