WW-5635 Avoid logging sensitive token values in TokenHelper#1738
Conversation
Redact form and session token values from WARN-level log output in TokenHelper.validToken() and update corresponding i18n message properties. Detailed diagnostics moved to DEBUG level with sanitized input.
|
Please create a JIRA ticket to cover this change, thank you :) |
Updated warning message to include the form token in the log.
|
Working on getting ASF JIRA access — will link the ticket once my account is approved. |
|
JIRA ticket: https://issues.apache.org/jira/browse/WW-5635 |
|
Thanks for the hardening — the production behavior (dropping the session token from the WARN) is the right call, and logging full detail only under devMode is consistent with how One blocker though: Dispatcher dispatcher = Dispatcher.getInstance();
if (dispatcher != null && dispatcher.isDevMode()) {
LOG.warn("Token mismatch detail - token name [{}], form token [{}], session token [{}]",
normalizeSpace(tokenName), normalizeSpace(token), sessionToken);
}
Minor: the PR description says the extra line is DEBUG-level and logs only boolean presence, but the code logs full values at WARN under devMode. The code is fine given the devMode gate — just worth updating the description so it matches the intent. |
|
Updated — using Dispatcher.getInstance().isDevMode() with null guard as you suggested. PR description updated to reflect WARN-level logging under devMode. |
Summary
When
TokenHelper.validToken()detects a CSRF token mismatch, the WARN-level log message currently includes both the user-submitted form token and the server-side session token in cleartext. Since the session token is only removed on a successful match, the logged value remains a live credential — visible to anyone with access to application logs.This change keeps the form token in the WARN message (with
normalizeSpace()sanitization) and logs full token detail only when devMode is enabled viaDispatcher.getInstance().isDevMode(), consistent with howParametersInterceptoralready handles user-supplied values elsewhere in the codebase.Changes
TokenHelper.java
normalizeSpace()sanitization, session token is redactedDispatcherandnormalizeSpaceimports added6 i18n properties files
struts-messages.properties,_en,_da,_de,_pl,_pt— updatedstruts.internal.invalid.tokento use{0}(form token only), removed{1}(session token)What is NOT changed
equals()comparison and token-removal-on-success logicstruts.messages.invalid.token— separate key, untouched)validToken()and interceptor result codesJIRA: https://issues.apache.org/jira/browse/WW-5635