use constant-time comparison for auth token validation#7730
Merged
jh-block merged 2 commits intoblock:mainfrom Mar 11, 2026
Merged
use constant-time comparison for auth token validation#7730jh-block merged 2 commits intoblock:mainfrom
jh-block merged 2 commits intoblock:mainfrom
Conversation
Signed-off-by: Extra Small <littleshuai.bot@gmail.com>
1ad2e2e to
08cc403
Compare
Collaborator
|
Doesn't the explicit length guard let an attacker know whether their key is the right length or not based on the timing? I don't think it makes the intent clearer and doing the full computation every time is rather the point of constant time comparison. Happy to merge if that is removed. |
Contributor
Author
|
Good point — the length check does leak that info through timing. Removed it in 99e1d11, ct_eq handles different lengths fine on its own. |
Signed-off-by: Extra Small <littleshuai.bot@gmail.com>
99e1d11 to
eea6a07
Compare
jh-block
approved these changes
Mar 11, 2026
Contributor
Author
|
Thanks for the quick review and merge @jh-block! |
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.
The auth middleware in
auth.rsuses==for comparing theX-Secret-Keyheader against the stored secret. Rust's default string comparison short-circuits on the first differing byte, which leaks timing information that could let an attacker recover the key incrementally.This swaps the comparison for
subtle::ConstantTimeEq::ct_eq, which always compares every byte regardless of where they differ.subtleis already in the dependency tree (pulled in transitively), so this just adds it as a direct dep forgoose-server.The explicit
key.len() == state.len()guard beforect_eqis technically redundant (ct_eq on unequal-length slices returns 0), but makes the intent clearer and avoids doing the full comparison when lengths obviously differ.Closes #7710