Sanitize comment rendering in xxe.js - #8
Open
hcl-appscan-rapidfix[bot] wants to merge 3 commits into
Open
Conversation
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.
Pixee Scan: 1d7ceb7a-349b-4361-a889-1ac1bb34bc8e
Confidence: HIGH
Fix confidence is a rating derived from an internal benchmark and includes High, Medium, and Low confidence fixes. It comprises three weighted scores reflecting the safety, effectiveness and cleanliness of Pixee's code changes within a fix. View Details in Pixee.
Remediation
This change fixes finding d3af0015-9e3c-f111-8ef3-00224854fbc5.
Details
Sanitize comment rendering in xxe.js
Summary
Sanitize comment rendering in
xxe.js.Vulnerability Description
Cross-Site Scripting occurs when untrusted data is inserted into a web page without proper escaping or sanitization. An attacker can inject script or markup that executes in a victim’s browser, which can expose session data, alter page behavior, or perform actions on the user’s behalf. This is especially dangerous when the application renders data that originated from other users or from server responses.
Changes Made
The comment renderer in
src/main/resources/lessons/xxe/js/xxe.jsbuilt HTML by directly substituting server-returned fields into a template and appending the result to the page. That pattern was dangerous becauseresult[i].user,result[i].dateTime, andresult[i].textcould reach a DOM XSS sink without escaping. The fix added anescapeHtmlhelper that encodes the standard HTML metacharacters, and the renderer now passes each of those fields through that helper before inserting them into the template. This preserved the existing UI structure while making the comment output safe to render.Guidance Adherence
Source: Pixee Knowledge Base
Applied the following guidance from the remediation instructions:
escapeHtml()and uses it onresult[i].user,result[i].dateTime, andresult[i].textbefore interpolating them into thehtmltemplate, which prevents script/markup injection when the comment list is appended to the DOM.&,<,>,", and', covering the common HTML-breaking characters needed for this sink.$.get(...)->replace(...)->append(...)flow intact and applies encoding right before the HTML sink, which matches the guidance’s focus on safe output encoding rather than changing application behavior.No new external library was introduced, so no dependency manifest update was necessary.