mirror of
https://github.com/esphome/esphome.git
synced 2026-02-20 16:35:37 -07:00
[dashboard] Use constant-time comparison for username check
Use hmac.compare_digest() for the username comparison to match the existing constant-time password comparison. This prevents username enumeration via timing analysis.
This commit is contained in:
@@ -84,11 +84,12 @@ class DashboardSettings:
|
||||
def check_password(self, username: str, password: str) -> bool:
|
||||
if not self.using_auth:
|
||||
return True
|
||||
if username != self.username:
|
||||
return False
|
||||
|
||||
# Compare password in constant running time (to prevent timing attacks)
|
||||
return hmac.compare_digest(self.password_hash, password_hash(password))
|
||||
# Compare both in constant running time (to prevent timing attacks)
|
||||
username_matches = hmac.compare_digest(username, self.username)
|
||||
password_matches = hmac.compare_digest(
|
||||
self.password_hash, password_hash(password)
|
||||
)
|
||||
return username_matches and password_matches
|
||||
|
||||
def rel_path(self, *args: Any) -> Path:
|
||||
"""Return a path relative to the ESPHome config folder."""
|
||||
|
||||
Reference in New Issue
Block a user