Fix CSP style-src nonce policy and escape unsafe HTML output paths#1720
Open
metsw24-max wants to merge 1 commit into
Open
Fix CSP style-src nonce policy and escape unsafe HTML output paths#1720metsw24-max wants to merge 1 commit into
metsw24-max wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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