Fix CSP style-src nonce policy and escape unsafe HTML output paths#1720
Fix CSP style-src nonce policy and escape unsafe HTML output paths#1720metsw24-max wants to merge 1 commit into
Conversation
|
Thanks for the contribution and for clearly separating the three changes — that made review much easier. I went through each item against current A general process note: when something is believed to be an exploitable framework vulnerability, please don't open a public PR for it — send it to Fix 1 —
|
This PR fixes three framework-side output safety issues related to CSP policy generation and HTML escaping.
All existing tests pass after the changes.
Fix 1: radiomap.ftl attribute escaping
Problem
radiomap.ftlused:${attributes.name?no_esc}without pre-sanitizing
"characters.Unlike other form templates, this bypassed FreeMarker auto-escaping entirely and allowed a double quote to break out of the HTML attribute context.
Fix
Escape only double quotes before
?no_esc:${attributes.name?replace('"', '"')?no_esc}Single quotes are intentionally preserved because Struts OGNL map syntax may legitimately contain them:
Files changed:
template/simple/radiomap.ftltemplate/html5/radiomap.ftlFix 2: CSP policy missing
style-srcProblem
The framework propagates CSP nonces to generated
<link>and<script>tags, but the default CSP policy only defined:No
style-srcdirective existed, meaning style nonces were not enforced by browsers.Fix
Added:
STYLE_SRCconstant toCspSettingsstyle-src 'nonce-...' ...directive generation inDefaultCspSettingsAlso updated CSP interceptor tests to validate the new policy format.
Files changed:
CspSettings.javaDefaultCspSettings.javaCspInterceptorTest.javaFix 3: unescaped redirect body output
Problem
ServletRedirectResultwrote the raw redirect URL directly into the HTML response body when using non-302 status codes:Since
finalLocationmay contain OGNL-evaluated values, framework-controlled HTML output should always be escaped before rendering.Fix
Escape the response body output using Apache Commons Text:
The
Locationresponse header itself remains unchanged.Files changed:
ServletRedirectResult.java