Lukasz Lenart created WW-5855:
---------------------------------

             Summary: Compare the transaction token with a constant-time 
comparison in TokenHelper.validToken
                 Key: WW-5855
                 URL: https://issues.apache.org/jira/browse/WW-5855
             Project: Struts 2
          Issue Type: Improvement
          Components: Core
    Affects Versions: 7.4.0, 6.12.0
            Reporter: Lukasz Lenart


{{TokenHelper.validToken}} compares the submitted token with the session token 
using {{token.equals(sessionToken)}}. {{String.equals}} returns as soon as a 
character differs, so its running time depends on the length of the common 
prefix. The token is a 165-bit {{SecureRandom}} value rendered in base 36, 
stored per session, and the token interceptor is documented as a guard against 
duplicate submissions; the comparison itself is correct. Making it 
constant-time removes the timing dependency at no cost.

h2. Where

{{core/src/main/java/org/apache/struts2/util/TokenHelper.java}}, 
{{validToken()}}, the {{if (!token.equals(sessionToken))}} check. Same on 
{{main}} and {{support/struts-6-x-x}}.

h2. Change

Compare the UTF-8 bytes of both values with 
{{java.security.MessageDigest.isEqual(byte[], byte[])}}, which runs in time 
independent of the content for equal-length inputs; a {{null}} session token 
keeps the current "invalid token" result. Behaviour is otherwise unchanged: on 
a mismatch the session token stays in place, on a match it is removed. Add a 
{{TokenHelperTest}} case for a token that differs only in the last character 
and for a {{null}} session token.

h2. Source

Reported publicly on the Full Disclosure list, 2026-10-31: 
https://seclists.org/fulldisclosure/2026/Nov/6



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to