Potential fix for code scanning alert no. 7: Cross-site scripting - #56
Closed
lgzarturo wants to merge 1 commit into
Closed
Potential fix for code scanning alert no. 7: Cross-site scripting#56lgzarturo wants to merge 1 commit into
lgzarturo wants to merge 1 commit into
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
lgzarturo
marked this pull request as ready for review
April 7, 2026 02:15
Owner
Author
Coverage Report
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/lgzarturo/springboot-course/security/code-scanning/7
To fix the problem, the user-controlled
messageparameter 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:
HtmlUtils.htmlEscape(message)to create a safe version of the input for inclusion in the response text.messageto Sentry, since Sentry accepts arbitrary strings and this does not affect XSS in the HTTP response.message.Concretely, in
src/main/kotlin/com/lgzarturo/springbootcourse/sentry/adapters/rest/SentryController.kt, insidefun testMessage(...), introduce a new local variable, e.g.val safeMessage = HtmlUtils.htmlEscape(message), and change the return line toreturn "Message sent to Sentry: $safeMessage". No new imports are needed becauseHtmlUtilsis already imported at line 15.Suggested fixes powered by Copilot Autofix. Review carefully before merging.