Conversation
whatdoes3plus1equalsto
approved these changes
Dec 12, 2024
kivine99
approved these changes
Dec 12, 2024
|
|
||
| @GetMapping("/ping") | ||
| public String ping(Principal principal, @RequestParam(value = "reply", defaultValue = "pong") String reply) { | ||
| return reply + "\n" + principal.getName(); |
Check warning
Code scanning / CodeQL
Cross-site scripting
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI almost 2 years ago
To fix the cross-site scripting vulnerability, we need to ensure that the user-provided input (reply parameter) is properly sanitized or encoded before being included in the response. The best way to achieve this is by using a library that provides HTML encoding functionality to escape any potentially harmful characters.
We will use the StringEscapeUtils class from the Apache Commons Text library to encode the reply parameter. This will ensure that any special characters in the user input are properly escaped, preventing XSS attacks.
Suggested changeset
2
critterSpring/src/main/java/com/combatcritters/critterspring/CritterSpringApplication.java
| @@ -7,2 +7,3 @@ | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.apache.commons.text.StringEscapeUtils; | ||
|
|
||
| @@ -28,3 +29,4 @@ | ||
| public String ping(Principal principal, @RequestParam(value = "reply", defaultValue = "pong") String reply) { | ||
| return reply + "\n" + principal.getName(); | ||
| String encodedReply = StringEscapeUtils.escapeHtml4(reply); | ||
| return encodedReply + "\n" + principal.getName(); | ||
| } |
critterSpring/build.gradle
Outside changed files
| @@ -41,2 +41,3 @@ | ||
| dependencies { | ||
| implementation 'org.apache.commons:commons-text:1.12.0' | ||
| implementation project(':app') |
This fix introduces these dependencies
| Package | Version | Security advisories |
| org.apache.commons:commons-text (maven) | 1.12.0 | None |
Copilot is powered by AI and may make mistakes. Always verify output.
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.
Reverts #263