[ 
https://issues.apache.org/jira/browse/WW-5639?focusedWorklogId=1057295&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1057295
 ]

ASF GitHub Bot logged work on WW-5639:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 26/Nov/26 17:24
            Start Date: 26/Nov/26 17:24
    Worklog Time Spent: 10m 
      Work Description: lukaszlenart opened a new pull request, #2176:
URL: https://github.com/apache/struts/pull/2176

   Fixes [WW-5639](https://issues.apache.org/jira/browse/WW-5639)
   
   ## Summary
   
   `<s:property>` and `<s:text>` hard-coded their escaping in a private 
`prepare()` that chained the selected escapers. This PR moves that escaping 
into a container bean that applications can replace, and fixes the one broken 
combination.
   
   - **Commit 1: plug point, no output change.** Adds a new `TagEscaper` 
interface (`String escape(EscapeConfig config, String value)`), selected by 
`struts.tag.escaper`, the same way `DateFormatter` is wired. `EscapeConfig` is 
an immutable value object with a builder. It holds `TagOrigin` 
(`PROPERTY`/`TEXT`) and the four raw flags, so a single bean can treat the two 
tags differently. The default `StrutsTagEscaper` chains the escapers exactly as 
before and exposes each step as a `protected` method. The existing tag escape 
tests pass unchanged.
   - **Commit 2: `escapeXml` replaces `escapeHtml`.** html + xml used to 
double-escape (`&amp;amp;`). Now XML escaping runs alone; it already covers `< 
> & " '`. No other output changes.
   
   Replacing the escaper:
   
   ```xml
   <bean type="org.apache.struts2.components.escape.TagEscaper" 
name="myEscaper" class="com.acme.MyEscaper"/>
   <constant name="struts.tag.escaper" value="myEscaper"/>
   ```
   
   To change only the HTML step, for example to let a jsoup safelist through, 
extend `StrutsTagEscaper` and override `escapeHtml(String)`.
   
   ## Why the escapers stay chained
   
   The ticket originally proposed applying only one escaper. Testing 
commons-text showed this would be wrong in both directions. `<s:property 
escapeJavaScript="true"/>` keeps the default `escapeHtml=true`, so it produces 
html + js:
   
   - Keeping HTML only drops JS escaping. `'` and `\` pass through 
`escapeHtml4` unchanged, so the value can break out of a JS string literal.
   - Keeping JS only drops HTML escaping. `\"` ends an `onclick="…"` attribute.
   
   So the chain stays. html + xml was the only combination that actually 
produced broken output.
   
   | Usage | Before / commit 1 | Commit 2 |
   |---|---|---|
   | property default | html | html |
   | property `escapeJavaScript=true` | html + js | html + js |
   | property `escapeXml=true` | html + xml (double-escaped) | xml |
   | property `escapeCsv=true` | html + csv | html + csv |
   | `escapeHtml=false` + any single flag | that escaper | that escaper |
   
   ## Notes for reviewers
   
   - `Property` and `Text` now need the `TagEscaper` injected; there is no null 
guard, the same as `Date` and `DateFormatter`. Every framework construction 
path (JSP, FreeMarker, Velocity) already calls `container.inject`. Third-party 
code that creates these components outside the container will get an NPE when 
the tag renders. This needs a migration line in the 7.6.0 Version Notes.
   - `core/src/site/resources/tags/{property,text}-attributes.html` are 
regenerated from the updated `@StrutsTagAttribute` descriptions.
   - Design and plan: 
`docs/superpowers/specs/2026-11-26-pluggable-tag-escaper-design.md`, 
`docs/superpowers/plans/2026-11-26-pluggable-tag-escaper.md`.
   
   ## Credit
   
   The pluggable escaper is a port of Greg Huber's patch attached to WW-5639 
(`ww-5639-struts.patch`, Struts 6). His two provider interfaces with four 
boolean arguments became one interface that takes `EscapeConfig`.
   
   ## Follow-ups
   
   - [WW-5876](https://issues.apache.org/jira/browse/WW-5876): an ordered 
`escapeMode="js,html"` attribute.
   - [WW-5877](https://issues.apache.org/jira/browse/WW-5877): route 
`<s:actionmessage>` and `<s:actionerror>` through `TagEscaper`.
   
   ## Test plan
   
   - [x] `./mvnw test -DskipAssembly -pl core`: 3828 tests, 0 failures
   - [x] `./mvnw test -DskipAssembly -pl plugins/velocity`: 22 tests, 0 
failures (run before the review fixes, which did not touch any velocity path)
   - [x] New tests: `EscapeConfigTest`, `StrutsTagEscaperTest` (every flag 
combination, null and empty values, subclass hook), `TextTest`, the 
`PropertyTest` cases including `x'; alert(1); //\ <b>` with 
`escapeJavaScript="true"`, and 
`StrutsBeanSelectionProviderTest#testTagEscaperIsSelectedByConstant`
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   




Issue Time Tracking
-------------------

            Worklog Id:     (was: 1057295)
    Remaining Estimate: 0h
            Time Spent: 10m

> <s:property> escape options should be mutually exclusive
> --------------------------------------------------------
>
>                 Key: WW-5639
>                 URL: https://issues.apache.org/jira/browse/WW-5639
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Core Tags
>            Reporter: Lukasz Lenart
>            Assignee: Lukasz Lenart
>            Priority: Major
>             Fix For: 7.6.0
>
>         Attachments: ww-5639-struts.patch
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> The {{<s:property>}} tag exposes four boolean escape attributes — 
> {{escapeHtml}}
> (default {{true}}), {{escapeJavaScript}}, {{escapeXml}} and {{escapeCsv}} 
> (default
> {{false}}). {{Property.prepare()}} applies them *cumulatively*, chaining one
> escaper after another. Chaining escapers that target different output contexts
> produces corrupt output:
> * {{escapeHtml=false escapeJavaScript=true}} on {{<b></b>}} yields 
> {{<b><\/b>}},
>   because {{escapeEcmaScript}} escapes {{/}} as {{\/}}. The closing tag is 
> broken
>   and the rendered layout is damaged. Allowing HTML markup ({{<b>}}, 
> {{<strong>}},
>   {{<em>}}) while also JavaScript-escaping is impossible — the two contexts
>   conflict by nature.
> * Leaving {{escapeHtml=true}} (the default) while also setting 
> {{escapeXml=true}}
>   or {{escapeCsv=true}} double-escapes entities ({{escapeHtml4}} turns {{&}} 
> into
>   {{&amp;}}, then {{escapeXml10}} escapes the {{&}} again).
> h3. Note on security
> {{escapeJavaScript}} ({{escapeEcmaScript}}) escapes only {{' " \ /}} and 
> control
> characters; it does *not* escape {{<}}, {{>}} or {{&}}, so it is not an
> HTML-safety mechanism. The real exposure is that {{escapeHtml=false}} emits 
> raw,
> unescaped HTML — an XSS risk unless the value is fully trusted.
> h3. Proposed fix
> Make the four escape options mutually exclusive. Apply exactly one escaper,
> selected by first-match precedence:
> {noformat}
> escapeHtml -> escapeJavaScript -> escapeXml -> escapeCsv
> {noformat}
> HTML has the highest precedence. Since {{escapeHtml}} defaults to {{true}}, 
> the
> default behavior (HTML escaping only) is unchanged, and the established 
> pattern of
> "set {{escapeHtml=false}} plus the one escaper you want" is preserved. The 
> only
> outputs that change are configurations that were already producing corrupt
> double-escaped results.
> h3. Additionally
> * When {{devMode}} is enabled and more than one escape flag is set, log a 
> warning
>   naming which escaper was applied and noting the options are mutually 
> exclusive.
> * Update the {{escapeHtml}} / {{escapeJavaScript}} {{@StrutsTagAttribute}}
>   descriptions and the class JavaDoc: {{escapeHtml=false}} emits raw HTML (XSS
>   risk unless the value is trusted); {{escapeJavaScript}} targets a JS
>   string-literal context, not HTML, and escapes {{/}} as {{\/}} so it cannot
>   coexist with surviving HTML markup.
> This is a behavior change and should ship in *7.3.x* (minor). The public docs 
> page
> at [https://struts.apache.org/tag-developers/property-tag] is updated 
> separately
> in the {{struts-site}} repo.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to