compare X-Sttc-Token in constant time - #250
Open
bibonix wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PsHeader.authchecked the suppliedX-Sttc-Tokenheader against the stored user token withString#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.isEqualover 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 sameIdentity.Simpleit produced before.Locally I ran
mvn --batch-mode install -Pqulice -Dmaven.test.skip=true(BUILD SUCCESS) andmvn --batch-mode test -Dtest=TkAppAuthTest(3 tests passed, 0 failed). The widermvn testrun hits pre-existing errors inRsPageTest,TkCountersTest,TkErrorTest,TkHomeTest,TkLocksTest, and theDy*ITCaseintegration tests, all of which fail identically onmasterbefore this branch.Closes #248