fix(core): WW-5623 HTML-encode form action in PostbackResult to prevent XSS#1653
fix(core): WW-5623 HTML-encode form action in PostbackResult to prevent XSS#1653tranquac wants to merge 2 commits intoapache:mainfrom
Conversation
PostbackResult.doExecute() embeds finalLocation into a <form action=""> attribute via raw string concatenation without HTML encoding. A double quote in the location breaks out of the attribute, enabling reflected XSS. The response Content-Type is text/html (line 103). This is an encoding inconsistency: form field names and values at lines 218-219 ARE properly URL-encoded via URLEncoder.encode(), but the form action attribute was not encoded at all. Add encodeHtml() to escape &, ", <, > in finalLocation before embedding it in the HTML form tag, consistent with the existing encoding approach for form field values in the same class.
|
Could you create a JIRA ticket first? |
|
I requested a Jira account! And i will create create a JIRA ticket soon! |
|
hello @lukaszlenart I created JIRA ticket for this issue: https://issues.apache.org/jira/projects/WW/issues/WW-5623?filter=allissues |
|
Please add a focused unit test for this change in |
|
Thanks for your feedback. I will quickly create a fullfill patch based on your comment. I will notify you when it's finished and create a new PR. |
Address review feedback from @lukaszlenart: - Replace custom encodeHtml() with StringEscapeUtils.escapeHtml4() for consistency with the rest of Struts core (DefaultActionProxy, Property, TextProviderHelper all use StringEscapeUtils) - Add 3 focused unit tests in PostbackResultTest: - testFormActionHtmlEscaping: XSS payload with attribute breakout - testFormActionEscapesAllHtmlSpecialChars: covers ", &, <, > - testFormActionCleanLocationUnchanged: regression for clean URLs
|
Hi @lukaszlenart, Thank you for the review feedback! I've pushed a follow-up commit addressing both points: Changes in this update1. Replaced custom Removed the custom helper method and switched to 2. Added 3 focused unit tests in
All 7 tests pass (4 existing + 3 new): Please let me know if there's anything else you'd like me to adjust. |
Summary
PostbackResult.doExecute() at line 107 embeds finalLocation into a form action attribute via raw string concatenation without HTML encoding. The response Content-Type is text/html (line 103). A double-quote character in the location breaks out of the attribute, enabling reflected XSS.
This is an encoding inconsistency: form field names and values at lines 218-219 ARE properly URL-encoded via URLEncoder.encode(), but the form action attribute was not encoded at all.
Changes
Impact
When a developer uses PostbackResult with an OGNL expression referencing a user-controllable property (a documented framework feature for dynamic routing), an attacker can inject arbitrary HTML attributes and elements via the form action attribute.
Test
A PoC application with 5 test scenarios verifies the vulnerability and fix. Browser-based testing with Playwright confirms the XSS alert fires before the fix.