XSS from disabled Jakarta Faces output escaping

Jakarta Faces output escaping is disabled.

Description

In Jakarta Faces 4.1, h:outputText, h:outputFormat, and h:outputLabel escape special characters by default when displaying text in the HTML body. If a component renders user input with escape="false", the browser can interpret it as markup.

Potential impact

Scripts running in the page may read sensitive data or act with the user’s privileges. The page’s content or link destinations may also change.

Remediation

  • For ordinary text, pass the model’s string directly to the component. Omit escape or set escape="true" so the component escapes it on output.
  • If user-authored rich HTML is necessary, render only content sanitized on the server with a minimal allow-list policy, such as a maintained OWASP Java HTML Sanitizer. Review the policy and data flow wherever escape="false" is used; a function named sanitize is not proof of safety.
  • Use CSP alongside output encoding or HTML sanitization.

Examples

Before

html
<ui:composition xmlns:ui="jakarta.faces.facelets"
                xmlns:h="jakarta.faces.html">
  <h:outputText value="#{profile.biography}" escape="false" />
</ui:composition>

After

html
<ui:composition xmlns:ui="jakarta.faces.facelets"
                xmlns:h="jakarta.faces.html">
  <h:outputText value="#{profile.biography}" />
</ui:composition>

With escape omitted, h:outputText displays the user’s biography as HTML text.

References