fix(security): compare poorman's auth token in constant time#9736
Open
alhudz wants to merge 1 commit into
Open
fix(security): compare poorman's auth token in constant time#9736alhudz wants to merge 1 commit into
alhudz wants to merge 1 commit into
Conversation
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.
Description
hasPoormansAuthgatesAlterover gRPC (edgraph/server.go) and the/admin/*HTTP routes (dgraph/cmd/alpha/admin.go) by checking the--security tokenagainst the caller-suppliedauth-tokengRPC metadata /X-Dgraph-AuthTokenheader. Both checks use!=on strings, which short-circuits on the first differing byte, so the reply time tracks the length of the matching prefix and leaks the token a byte at a time to an unauthenticated caller.Switch both checks to
crypto/subtle.ConstantTimeCompare, the same primitive already used for the JWT audience check ingraphql/authorization/auth.go. Keeping the constant-time compare inside the twohasPoormansAuthhelpers covers every route behind the token without each handler repeating the guard.repro: a microbenchmark of the naive!=against a 61-byte token reads2.2 ns/opwhen the first byte differs versus3.7 ns/opwhen only the last byte differs (rising with the matching prefix);subtle.ConstantTimeComparestays flat at ~21 ns/opwherever the mismatch falls.Checklist
fix:,feat:,chore:,ci:, etc.