Skip to content

compare X-Sttc-Token in constant time - #250

Open
bibonix wants to merge 1 commit into
sttc:masterfrom
bibonix:fix-248-timing-safe-token-compare
Open

compare X-Sttc-Token in constant time#250
bibonix wants to merge 1 commit into
sttc:masterfrom
bibonix:fix-248-timing-safe-token-compare

Conversation

@bibonix

@bibonix bibonix commented Jun 17, 2026

Copy link
Copy Markdown

PsHeader.auth checked the supplied X-Sttc-Token header against the stored user token with String#equals, which short-circuits at the first mismatching character and lets a network attacker recover the secret byte by byte by measuring response latency. The token is the only credential a non-cookie client presents, so the timing leak compromises every counter, lock, and quota of the affected account.

After this change the comparison runs through MessageDigest.isEqual over the UTF-8 bytes of both strings, so the wall-clock cost of the check no longer depends on where the mismatch falls. Header-based authentication continues to reject mismatched tokens with HTTP 401 and to admit matching ones with the same Identity.Simple it produced before.

Locally I ran mvn --batch-mode install -Pqulice -Dmaven.test.skip=true (BUILD SUCCESS) and mvn --batch-mode test -Dtest=TkAppAuthTest (3 tests passed, 0 failed). The wider mvn test run hits pre-existing errors in RsPageTest, TkCountersTest, TkErrorTest, TkHomeTest, TkLocksTest, and the Dy*ITCase integration tests, all of which fail identically on master before this branch.

Closes #248

PsHeader.auth used String#equals to check the supplied token against
the stored user token. String#equals short-circuits on the first
mismatching character, so the response latency of the auth path
leaks the token byte by byte to a network attacker. Replace the
comparison with MessageDigest.isEqual over UTF-8 bytes so the check
runs in time proportional to the longer input regardless of where
the mismatch falls.

Closes sttc#248
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.

PsHeader.auth compares X-Sttc-Token with String#equals, leaking the token byte by byte via response timing

2 participants