Skip to content

security: fix auth timing attack#345

Open
hongkongkiwi wants to merge 3 commits intoexpressvpn:mainfrom
hongkongkiwi:security-auth-timing-attack
Open

security: fix auth timing attack#345
hongkongkiwi wants to merge 3 commits intoexpressvpn:mainfrom
hongkongkiwi:security-auth-timing-attack

Conversation

@hongkongkiwi
Copy link

Summary

Prevent username enumeration via timing attack by always calling password verification with a fake hash when user is not found.

Changes

  • Modified authorize_user_password() in auth.rs to always verify password even when user not found
  • Added static fake hash constant for timing attack prevention
  • Added username validation function is_valid_username()
  • Changed verbose log messages to generic 'Authentication failed'

Security Impact

Fixes username enumeration vulnerability where attackers could distinguish valid from invalid usernames based on response timing.

Tests Added

  • Username validation tests (empty, too long, invalid characters, unicode, etc.)

hongkongkiwi and others added 3 commits January 27, 2026 16:05
Prevent username enumeration via timing attack by always calling password
verification with a fake hash when user is not found.

Also use generic 'Authentication failed' log message to prevent username
enumeration via log messages.

Co-authored-by: Claude <noreply@anthropic.com>
- Remove duplicate "a" test case for min_length
- Fix max_length_50 and too_long_51 strings to be exactly 50 and 51 chars
- Change "Invalid username format" log to "Authentication failed" to avoid
  leaking validation rules to potential attackers

Co-Authored-By: Claude <noreply@anthropic.com>
- Use valid bcrypt hash for FAKE_HASH to ensure constant-time verification
  (was using invalid all-ff chars which could short-circuit verification)
- Add explicit user_exists check before granting auth to prevent granting
  access when user doesn't exist even if password verification passes

Co-Authored-By: Claude <noreply@anthropic.com>
@hongkongkiwi hongkongkiwi requested a review from a team as a code owner January 28, 2026 03:40
@hongkongkiwi hongkongkiwi changed the title Security auth timing attack security: fix auth timing attack Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant