fix(auth): use timing-safe token comparison for credential validation#323
Merged
Akshay473 merged 1 commit intoJun 9, 2026
Merged
Conversation
|
@TanCodeX is attempting to deploy a commit to the akshay473's projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
@Akshay473 please review and merge under gssoc'26. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Author
|
@Akshay473 Hi! Could you please update the label from |
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
This pull request fixes a security vulnerability related to timing-based side-channel attacks during authentication token validation.
Changes Made
Updated
Server/main.py(get_api_user) to replace direct string equality checks (==) withhmac.compare_digest()when validating:ADMIN_TOKENINVESTIGATOR_TOKENUpdated
Server/security.py(validate_analyze_api_key) to usehmac.compare_digest()when validatingDEFAULT_ANALYZE_API_KEY.Added the required
hmacimports in both files.Motivation
Direct string comparison using
==can introduce observable timing discrepancies because comparison may stop at the first mismatched character. An attacker could potentially leverage these timing differences to perform credential enumeration and gradually recover valid authentication tokens.Using
hmac.compare_digest()provides timing-safe comparisons, helping mitigate timing side-channel attacks (CWE-208: Observable Timing Discrepancy) and improving the security of token and API key validation.Fixes #316
Type of Change
Scope and Impact
This change is limited to authentication and API key validation logic:
Server/main.pyget_api_user()Server/security.pyvalidate_analyze_api_key()No API behavior, request formats, response formats, or authentication workflows were modified. The change only affects the internal comparison mechanism used during credential validation.
Validation & Testing
Verification Performed
hmac.ADMIN_TOKENauthentication continues to work as expected.INVESTIGATOR_TOKENauthentication continues to work as expected.hmac.compare_digest().Checklist
python -m py_compile)Screenshots / Visual Demonstrations
Not applicable. This is a backend security enhancement with no UI changes.
Related Issues
Closes #316
Proposed Architecture Changes
Files Modified
Server/main.pyhmacimport.==withhmac.compare_digest().Server/security.pyhmacimport.==withhmac.compare_digest().Architectural Impact
Type of Change
Testing Checklist
Local Verification
Responsiveness & Design Verification (For Frontend Changes)
Security Considerations
Visual Impact (Screenshots / GIFs / Videos)
Not applicable. No UI/UX changes were introduced.