fix: Use constant-time comparison for token lookup#106
Merged
jasonalmaturner merged 1 commit intomasterfrom Feb 19, 2026
Merged
fix: Use constant-time comparison for token lookup#106jasonalmaturner merged 1 commit intomasterfrom
jasonalmaturner merged 1 commit intomasterfrom
Conversation
Replace direct map key lookup with Plug.Crypto.secure_compare/2 to prevent timing attacks on token matching. The map lookup uses standard equality which can leak information about how many characters matched via response time differences. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
c57dd69 to
6303838
Compare
Contributor
Author
Test ResultsUnit testsAll 19 existing tests pass unchanged: Manual verification via
|
| Test | Status | Service |
|---|---|---|
| Valid token | nil (pass-through) |
:test_svc |
| Invalid token | 401 |
nil |
| No token | 401 |
nil |
Behaviorally identical to the previous map lookup implementation.
acompton
approved these changes
Feb 19, 2026
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.
Summary
Replace direct map key lookup (
token_map[val]) withPlug.Crypto.secure_compare/2to prevent timing attacks on token matching.Standard map lookup uses equality comparison that short-circuits on the first mismatched byte, which can leak information about how many prefix characters matched via response time differences.
secure_comparealways compares every byte in constant time.Changes
secure_lookup/2private function that iterates the token map usingPlug.Crypto.secure_compare/2token_map[val]withsecure_lookup(token_map, val)incall/2Plug.Cryptois already available via the existing:plugdependencyTest plan
🤖 Generated with Claude Code