Skip to content

Commit 9389260

Browse files
committed
Avoid user-not-found timing attacks w/ dummy hash
Now that we have dropped passlib, this reimplements passlib's dummy verify feature to maintain the same security posture.
1 parent 33b6711 commit 9389260

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

st2auth_flat_file_backend/flat_file.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636

3737
LOG = logging.getLogger(__name__)
3838

39+
# dummy pw is "testpassword" (used when user not found to avoid timing attacks)
40+
DUMMY_HASH_DATA = "$2y$05$Vhvhbk0SYN3ncn9BSvXEHunzztBWfrwqOpX1D0GhrFvM1TcADpKoO"
41+
3942

4043
class HtpasswdFile(object):
4144
"""
@@ -103,7 +106,8 @@ def check_password(self, username, password):
103106
)
104107
return compare_hash(crypt.crypt(password, hash_data), hash_data)
105108
else:
106-
# User not found.
109+
# User not found. Do a dummy hash to avoid timing attacks.
110+
_ = bcrypt.checkpw(pw, bytes(DUMMY_HASH_DATA, encoding=encode_local))
107111
return None
108112

109113

0 commit comments

Comments
 (0)