fix(gate): use timingSafeEqual to prevent timing attacks on password check - #52
Open
Sertug17 wants to merge 1 commit into
Open
fix(gate): use timingSafeEqual to prevent timing attacks on password check#52Sertug17 wants to merge 1 commit into
Sertug17 wants to merge 1 commit into
Conversation
…check The previous comparison used !== which short-circuits on the first mismatched character. An attacker measuring response latency across many requests can converge on the correct password one character at a time. Replace with node:crypto timingSafeEqual, which always takes constant time regardless of where the buffers differ. Length is checked first (not timing-sensitive) since timingSafeEqual requires equal-length buffers.
|
@Sertug17 is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
Collaborator
🟡 Heimdall Review Status
|
Author
|
Hi, I found this while reviewing the codebase. The Happy to add tests or adjust anything if needed. Thanks for taking a look! |
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.
Closes #51
What
Replace the plain
!==password comparison inapp/api/gate/route.tswithtimingSafeEqualfromnode:crypto.Why
!==short-circuits on the first mismatched character. An attacker measuring response latency across many/api/gaterequests can converge on the correct password one character at a time (linear instead of exponential search).timingSafeEqualalways runs in constant time regardless of where the buffers differ, closing that channel.Changes
timingSafeEqualfromnode:cryptoBufferbefore comparingtimingSafeEqual)if (provided !== password)with the safe comparisonTesting
No new tests the gate is a temporary mechanism and has no existing test coverage. The fix is a drop in replacement with identical behaviour for correct passwords and incorrect ones; only the timing characteristic changes.