Skip to content

Avoid logging sensitive token values in TokenHelper#1738

Open
arunmanni-ai wants to merge 14 commits into
apache:mainfrom
arunmanni-ai:fix/redact-token-values-from-log-output
Open

Avoid logging sensitive token values in TokenHelper#1738
arunmanni-ai wants to merge 14 commits into
apache:mainfrom
arunmanni-ai:fix/redact-token-values-from-log-output

Conversation

@arunmanni-ai

Copy link
Copy Markdown

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 redacts the token values from the WARN message and moves operational detail to DEBUG level with sanitized input, consistent with how ParametersInterceptor already handles user-supplied values elsewhere in the codebase.

Changes

TokenHelper.java

  • WARN log no longer interpolates token values (new Object[0] replaces new Object[]{ token, sessionToken })
  • New DEBUG-level line logs only boolean presence (token != null, sessionToken != null), never the actual values
  • Token name is passed through normalizeSpace() before logging, matching the pattern in ParametersInterceptor (lines 221, 622)

6 i18n properties files

  • struts-messages.properties, _en, _da, _de, _pl, _pt — removed {0} and {1} format specifiers from struts.internal.invalid.token

What is NOT changed

  • Token generation, entropy, and session storage
  • The equals() comparison and token-removal-on-success logic
  • User-facing error messages (struts.messages.invalid.token — separate key, untouched)
  • Return values from validToken() and interceptor result codes
  • No existing tests assert on log output content

@lukaszlenart

Copy link
Copy Markdown
Member

Please create a JIRA ticket to cover this change, thank you :)

Comment thread core/src/main/java/org/apache/struts2/util/TokenHelper.java Outdated
Comment thread core/src/main/java/org/apache/struts2/util/TokenHelper.java Outdated
@arunmanni-ai

Copy link
Copy Markdown
Author

Working on getting ASF JIRA access — will link the ticket once my account is approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants