You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by ja...@apache.org on 2026/07/01 23:15:02 UTC
(grails-core) 01/01: Mask exception request parameters case-insensitively
This is an automated email from the ASF dual-hosted git repository.
jamesfredley pushed a commit to branch fix/exception-masking-case-insensitive
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit ec75dfced3192f204128b250cf41d3b333f66f4e
Author: James Fredley <ja...@users.noreply.github.com>
AuthorDate: Wed Jul 1 19:13:38 2026 -0400
Mask exception request parameters case-insensitively
Match excluded request parameter names without regard to case when Grails
logs exception request parameters, and document the matching behavior in
the logging guide and configuration metadata.
Assisted-by: Hephaestus:openai/gpt-5.5
---
...maskingRequestParametersFromStacktraceLogs.adoc | 1 +
.../META-INF/spring-configuration-metadata.json | 2 +-
.../grails/web/errors/GrailsExceptionResolver.java | 14 +++++++++-
.../web/errors/GrailsExceptionResolverSpec.groovy | 31 ++++++++++++++++++++++
4 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/grails-doc/src/en/guide/conf/config/logging/maskingRequestParametersFromStacktraceLogs.adoc b/grails-doc/src/en/guide/conf/config/logging/maskingRequestParametersFromStacktraceLogs.adoc
index 50efe74156..b43f3bf595 100644
--- a/grails-doc/src/en/guide/conf/config/logging/maskingRequestParametersFromStacktraceLogs.adoc
+++ b/grails-doc/src/en/guide/conf/config/logging/maskingRequestParametersFromStacktraceLogs.adoc
@@ -19,6 +19,7 @@ under the License.
When Grails logs a stacktrace, the log message may include the names and values of all of the request parameters for the current request.
To mask out the values of secure request parameters, specify the parameter names in the `grails.exceptionresolver.params.exclude` config property:
+Parameter names are matched case-insensitively.
[source, yaml]
.grails-app/conf/application.yml
diff --git a/grails-web-core/src/main/resources/META-INF/spring-configuration-metadata.json b/grails-web-core/src/main/resources/META-INF/spring-configuration-metadata.json
index 1dd9840914..bb7e1a10c4 100644
--- a/grails-web-core/src/main/resources/META-INF/spring-configuration-metadata.json
+++ b/grails-web-core/src/main/resources/META-INF/spring-configuration-metadata.json
@@ -115,7 +115,7 @@
{
"name": "grails.exceptionresolver.params.exclude",
"type": "java.util.List<java.lang.String>",
- "description": "List of parameter names to mask (replace with [*****]) in exception stack traces, typically used for password and creditCard.",
+ "description": "List of parameter names to mask (replace with [*****]) in exception stack traces, typically used for password and creditCard. Parameter names are matched case-insensitively.",
"defaultValue": []
},
{
diff --git a/grails-web-mvc/src/main/groovy/org/grails/web/errors/GrailsExceptionResolver.java b/grails-web-mvc/src/main/groovy/org/grails/web/errors/GrailsExceptionResolver.java
index feb7dc6fb2..896db30bf4 100644
--- a/grails-web-mvc/src/main/groovy/org/grails/web/errors/GrailsExceptionResolver.java
+++ b/grails-web-mvc/src/main/groovy/org/grails/web/errors/GrailsExceptionResolver.java
@@ -409,7 +409,7 @@ public class GrailsExceptionResolver extends SimpleMappingExceptionResolver impl
for (i = 0; i < values.length; i++) {
sb.append(LINE_SEPARATOR).append(param).append(": ");
- if (blackList.contains(param)) {
+ if (isExcludedRequestParameter(param, blackList)) {
sb.append("***");
} else {
sb.append(values[i]);
@@ -429,6 +429,18 @@ public class GrailsExceptionResolver extends SimpleMappingExceptionResolver impl
return sb.toString();
}
+ protected boolean isExcludedRequestParameter(String parameterName, List<String> excludedParameterNames) {
+ if (parameterName == null || excludedParameterNames == null) {
+ return false;
+ }
+ for (String excludedParameterName : excludedParameterNames) {
+ if (parameterName.equalsIgnoreCase(excludedParameterName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
protected void createStackFilterer() {
try {
Class filtererClass = grailsApplication.getConfig().getProperty(Settings.SETTING_LOGGING_STACKTRACE_FILTER_CLASS, Class.class, DefaultStackTraceFilterer.class);
diff --git a/grails-web-mvc/src/test/groovy/org/grails/web/errors/GrailsExceptionResolverSpec.groovy b/grails-web-mvc/src/test/groovy/org/grails/web/errors/GrailsExceptionResolverSpec.groovy
index 384c382a7a..48a8ef5ad1 100644
--- a/grails-web-mvc/src/test/groovy/org/grails/web/errors/GrailsExceptionResolverSpec.groovy
+++ b/grails-web-mvc/src/test/groovy/org/grails/web/errors/GrailsExceptionResolverSpec.groovy
@@ -245,6 +245,37 @@ class GrailsExceptionResolverSpec extends Specification {
msg.contains('(ip: 203.0.113.7)')
}
+ void "getRequestLogMessage masks excluded request parameters case-insensitively"() {
+ given:
+ def config = Mock(Config)
+ config.getProperty('grails.exceptionresolver.logRequestParameters', Boolean, _) >> true
+ config.getProperty('grails.exceptionresolver.params.exclude', List, _) >> ['password', 'token']
+ config.getProperty('grails.exceptionresolver.logAuditor', Boolean, false) >> false
+ config.getProperty('grails.exceptionresolver.logRemoteAddr', Boolean, false) >> false
+ config.getProperty('grails.exceptionresolver.logFullStackTraceOnFilter', Boolean, true) >> false
+ config.getProperty('grails.exceptionresolver.logFullStackTrace', Boolean, false) >> false
+ def grailsApp = Mock(GrailsApplication)
+ grailsApp.getConfig() >> config
+ def resolver = new GrailsExceptionResolver()
+ resolver.grailsApplication = grailsApp
+ def request = new MockHttpServletRequest('POST', '/login')
+ request.addParameter('Password', 'secret')
+ request.addParameter('apiToken', 'visible')
+ request.addParameter('TOKEN', 'abc123')
+ request.addParameter('username', 'sherlock')
+
+ when:
+ def msg = resolver.getRequestLogMessage('RuntimeException', request, 'boom')
+
+ then:
+ msg.contains('Password: ***')
+ msg.contains('TOKEN: ***')
+ msg.contains('username: sherlock')
+ msg.contains('apiToken: visible')
+ !msg.contains('Password: secret')
+ !msg.contains('TOKEN: abc123')
+ }
+
void "AuditorAwareLookup returns empty when no application context is provided"() {
given:
def lookup = new AuditorAwareLookup(null)