[Security] Remediate 2FA bypass with hashed recovery code (#2132)

* Fix Vuln (allow 2FA bypass with hashed recovery code)

Remove comparison of hashed recovery code from db with the user input.

* Formatting

* Remove Comment
This commit is contained in:
ghisch 2024-06-26 18:26:46 +02:00 committed by GitHub
parent 1ecc5eb89b
commit 4817dfdcaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2971,11 +2971,7 @@ class RecoveryCode(Base, ModelMixin):
@classmethod
def find_by_user_code(cls, user: User, code: str):
hashed_code = cls._hash_code(code)
# TODO: Only return hashed codes once there aren't unhashed codes in the db.
found_code = cls.get_by(user_id=user.id, code=hashed_code)
if found_code:
return found_code
return cls.get_by(user_id=user.id, code=code)
return cls.get_by(user_id=user.id, code=hashed_code)
@classmethod
def empty(cls, user):