Skip to content

Make the XML-safe HTML encoder the default for grails.views.gsp.htmlcodec - #16460

Merged
jdaugherty merged 1 commit into
8.0.xfrom
fix/16459-xml-html-encoder-default
Oct 2, 2026
Merged

jdaugherty merged 1 commit into
8.0.xfrom
fix/16459-xml-html-encoder-default

Conversation

@matrei

@matrei matrei commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #16459.

When grails.views.gsp.htmlcodec is not set, HTMLCodec used the HTML4 encoder from before Grails 2.3. Every application template since 2.3 has set htmlcodec: xml, so only applications without the setting got it. This PR makes the XML-safe HTMLEncoder the default and keeps the HTML4 encoder as an explicit opt-in.

Changes

  • HTMLCodec uses HTMLEncoder by default. htmlcodec: html4 selects the HTML4 encoder. html also selects it, because an application that set html explicitly got the HTML4 encoder before. xml, xhtml and any other value select the default. Matching ignores case, as before.
  • Grails Forge (GrailsGsp) and the web profile skeleton no longer write htmlcodec: xml.
  • The description of grails.views.gsp.htmlcodec in the grails-gsp configuration metadata now describes the new default and html4.
  • Guide:
    • The HTMLCodec section in "Encoding and Decoding Objects" lists what the codec escapes and shows html4 as the opt-out. The out-of-date note saying apostrophes are not escaped is removed, since both encoders escape ' as '.
    • The recommended configuration in "Cross Site Scripting (XSS) Prevention" no longer includes htmlcodec: xml.
    • New section 81 in the Grails 8 upgrade guide, plus a matching note in the grails-8-upgrade skill.

The htmlcodec: xml lines in grails-test-examples and in the plugin application.yml files are left as they are. They select the same encoder as before.

Compatibility

Applications that set htmlcodec: xml are not affected. Applications without the setting now get the XML-safe output: non-ASCII letters are no longer written as named entities, and @, \ and ` are escaped. Tests that compare escaped markup exactly may need updating, as the two grails-fields specs in this PR did (pattern="\d+" is now rendered as pattern="\d+", which the browser decodes to the same value). Applications that serve pages in a non-UTF-8 charset and rely on the entities can set htmlcodec: html4.

Tests

  • HTMLCodecTests: the default with and without a GrailsApplication; the settings that select each encoder (xml, XML, xhtml, XHTML, xml-safe, empty and unknown values; html4, HTML4, html, HTML); setUseLegacyEncoder; and that both encoders report the HTML codec identifier. Each case checks @, \, `, U+2028 and a non-ASCII letter.
  • CodecsConfigurationSpec: a data-driven feature that resolves the HTML encoder through CodecLookup in a Spring context for an unset value, xml, xhtml and html4. The unset row fails without the change.
  • GrailsGspSpec (Forge): the generated configuration no longer contains grails.views.gsp.htmlcodec.
  • DefaultInputRenderingSpec and DefaultInputRenderingPersistentSpec (grails-fields): the expected pattern attribute is now the escaped value.

The test suites of the modules that render through the HTML codec pass, including grails-codecs, grails-gsp, the taglib, layout and SiteMesh 3 modules, grails-test-suite-uber/-web/-persistence, grails-fields, grails-scaffolding, the Spring Security plugins, grails-mail and grails-data-graphql. GrailsGspSpec in grails-forge also passes.

…odec

When grails.views.gsp.htmlcodec was not set, HTMLCodec used the HTML4
encoder from before Grails 2.3, although every application generated
since then has set htmlcodec: xml. Only applications without the
setting got the HTML4 encoder, which writes non-ASCII characters as
named entities and leaves @, the backslash, the backtick and U+2028/
U+2029 unescaped.

Use HTMLEncoder by default. The value html4 (or html, which selected
the HTML4 encoder before) opts back in to the HTML4 encoder; xml, xhtml
and any other value select the default.

The application generator and the web profile skeleton no longer write
htmlcodec: xml. The codecs and XSS prevention guide sections, the
configuration metadata, the Grails 8 upgrade guide and the upgrade
skill describe the new default.

Fixes #16459
@codecov

codecov Bot commented Oct 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.9270%. Comparing base (d13aa33) to head (aa0467c).

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##                8.0.x     #16460        +/-   ##
==================================================
- Coverage     58.9274%   58.9270%   -0.0004%     
- Complexity      24440      24443         +3     
==================================================
  Files            2174       2174                
  Lines          107366     107365         -1     
  Branches        19557      19557                
==================================================
- Hits            63268      63267         -1     
+ Misses          35235      35233         -2     
- Partials         8863       8865         +2     
Files with missing lines Coverage Δ
...in/groovy/org/grails/plugins/codecs/HTMLCodec.java 90.9091% <100.0000%> (+3.9526%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@testlens-app

testlens-app Bot commented Oct 1, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: aa0467c
▶️ Tests: 103826 executed
⚪️ Checks: 87/87 completed


Learn more about TestLens at testlens.app/docs.

@jdaugherty jdaugherty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really a bug fix, but a feature. I agree the default should probably be changed, but it is a behavior change. We didn't want to do an RC3, and we said we wouldn't do behavior changes for 8.0.0 I think I'm ultimately ok with it, but I'd like to see another person sign off on this to merge.

@jdaugherty
jdaugherty merged commit 87b6add into 8.0.x Oct 2, 2026
90 checks passed
@jdaugherty
jdaugherty deleted the fix/16459-xml-html-encoder-default branch October 2, 2026 13:12
antobinary added a commit to antobinary/bigbluebutton that referenced this pull request Oct 5, 2026
Apache Grails tagged 8.0.0 on 2026-10-04 and opened its release vote the
same day. Until the vote closes the artifacts are in the ASF staging
group only, so the TEMP staging-repository entries in build.gradle stay
and their comments are retargeted at 8.0.0; they come out once 8.0.0 is
on Maven Central.

Against RC2 the 8.0.0 BOM changes two things: asset-pipeline goes from
5.2.0-RC3 to 5.2.0 and SiteMesh from 3.3.0-RC3 to 3.3.0. Spring Boot
(4.1.1), Groovy (5.1.3) and the Gradle version Grails builds with
(9.8.0) are unchanged, so gradle.properties only moves grailsVersion and
the cloud.wondrify asset-pipeline plugin follows the BOM to 5.2.0. The
Tomcat 11.0.26 override stays: there is still no Spring Boot 4.1 release
newer than 4.1.1.

.gitlab-ci.yml moves to bbb-build:grails-8--2026-10-04-230216, which has
the same toolchain as the previous grails-8 image (JDK 21.0.12.1,
Go 1.27.0, Node 22.23.2) with the Grails 8.0.0 CLI.

Checked, nothing to do for what went into 8.0.0 after RC2: the default
dataSource bean (apache/grails-core#16458) is registered only with GORM
for Hibernate, which bbb-web does not ship; the XML-safe GSP html codec
default (apache/grails-core#16460) is what bbb-web already configures
explicitly, and it has no GSPs; the messageSource basename ordering
(apache/grails-core#14753) has nothing to act on, bbb-web looks up no
messages through it.

Verified with a package build in the new image, installed on a 4.0 dev
container: the WAR has the same 248 jars as the RC2 build, with the 44
grails-* jars at 8.0.0 and Spring Boot 4.1.1, Tomcat 11.0.26 and Groovy
5.1.3 unchanged. bbb-web started in 7.4 s with a clean log (no ERROR,
only the logback layout/encoder WARNs the stock build prints too) and
/bigbluebutton/api returned SUCCESS. A 5.3 MB PDF uploaded through the
client became the current presentation (bbb-web counted 117 pages),
and a join inside a cross-origin iframe still rendered the client. The
api + presentation Playwright suites gave 32 passed, 7 failed and 3
skipped on the 8.0.0 build, the same counts as the stock Grails 7.0.12
build on the same container, and the per-test results were identical:
no test differed, the same 7 tests fail on both builds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Make the XML-safe HTML encoder the default for grails.views.gsp.htmlcodec

3 participants