Trustwave SpiderLabs Security Advisory TWSL2015-012: XSS in Oracle Java Server Faces Published: 07/15/15 Version: 1.0 Vendor: Oracle (http://www.oracle.com/) Product: Java Server Faces Version affected: 10.3.6.0, 12.1.1.0, 12.1.2.0 and 12.1.3.0 Product description: JavaServerā„¢ Faces technology simplifies building user interfaces for JavaServer applications. Finding 1: Cross-Site Scripting in error handling Credit: Christiaan Esterhuizen and Maciej Grela of Trustwave CVE: CVE-2015-2623 A containing a Java exception is vulnerable to Cross-Site Scripting when an invalid string is passed as a form parameter that is expecting a number (integer of decimal). This causes a java.lang.NumberFormatException exception to trigger an error message which contains a non-escaped reflected value of the parameter. Example (some HTTP headers removed for brevity): Request: GET /home.xhtml?javax.faces.partial.ajax=true&javax.faces.source=mainForm%3AdetailsTabView%3AupdateBtn& [...] &mainForm%3AdetailsTabView%3ApaymentAmount_hinput=0.01"]]>& [...] &javax.faces.ViewState=759215216562573750%3A2432411821465489427 HTTP/1.1 Host: www.example.com Faces-Request: partial/ajax Response: HTTP/1.1 200 OK X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7) Server: GlassFish Server Open Source Edition 3.1.2.2 X-UA-Compatible: IE=edge X-Powered-By: JSF/2.0 Cache-Control: no-cache Content-Type: text/xml;charset=UTF-8 Content-Length: 297 Date: Fri, 10 Apr 2015 11:17:29 GMT class java.lang.NumberFormatException "]]> As can be seen in the response the value of the paymentAmount_hinput parameter is reflected without output escaping giving us the ability to run Javascript. This vulnerability was discovered on JSF 2.0, however an inspection of the source code for the JSF 2.2 framework (2.2.9 specifically as the most recent version from the 2.2 branch available at the time) revealed that the JSF 2.2 is potentially also vulnerable. Below are some of the relevant code snippets: javax.faces-2.2.9-sources/com/sun/faces/context/AjaxExceptionHandlerImpl.java: private void handlePartialResponseError(FacesContext context, Throwable t) { if (context.getResponseComplete()) { return; // don't write anything if the response is complete } try { ExternalContext extContext = context.getExternalContext(); extContext.setResponseContentType("text/xml"); extContext.addResponseHeader("Cache-Control", "no-cache"); PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter(); writer.startDocument(); writer.startError(t.getClass().toString()); String msg = ""; if (t.getCause() != null) { msg = t.getCause().getMessage(); writer.write(((msg != null) ? msg : "")); } else { msg = t.getMessage(); writer.write(((msg != null) ? msg : "")); } writer.endError(); writer.endDocument(); javax.faces-2.2.9-sources/javax/faces/context/PartialResponseWriter.java: public void startError(String errorName) throws IOException { endUpdateIfNecessary(); endChangesIfNecessary(); ResponseWriter writer = getWrapped(); writer.startElement("error", null); writer.startElement("error-name", null); writer.write(errorName); writer.endElement("error-name"); writer.startElement("error-message", null); writer.startCDATA(); } As far as the code reveals, the writer.write call used to produce the CDATA content inside the error-message tag is an indirect call to java.io.Writer without any output escaping, which makes the XSS work. Remediation Steps: Apply the Oracle July 2015 Critical Patch Update (CPU). Revision History: 04/15/15 - Vulnerability disclosed to vendor 07/14/15 - Fix released by vendor 07/15/15 - Advisory published References 1. http://www.oracle.com/technetwork/topics/security/cpujul2015verbose-2367947.html About Trustwave: Trustwave helps businesses fight cybercrime, protect data and reduce security risks. With cloud and managed security services, integrated technologies and a team of security experts, ethical hackers and researchers, Trustwave enables businesses to transform the way they manage their information security and compliance programs while safely embracing business imperatives including big data, BYOD and social media. More than 2.5 million businesses are enrolled in the Trustwave TrustKeeperĀ® cloud platform, through which Trustwave delivers automated, efficient and cost-effective data protection, risk management and threat intelligence. Trustwave is a privately held company, headquartered in Chicago, with customers in 96 countries. For more information about Trustwave, visit www.trustwave.com. About Trustwave SpiderLabs: SpiderLabs(R) is the advanced security team at Trustwave focused on application security, incident response, penetration testing, physical security and security research. The team has performed over a thousand incident investigations, thousands of penetration tests and hundreds of application security tests globally. In addition, the SpiderLabs Research team provides intelligence through bleeding-edge research and proof of concept tool development to enhance Trustwave's products and services. https://www.trustwave.com/spiderlabs Disclaimer: The information provided in this advisory is provided "as is" without warranty of any kind. Trustwave disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Trustwave or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Trustwave or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.