fix: 🔒 fix timing attack (thx azlux)
This commit is contained in:
parent
16e4120b24
commit
4ffbf79adc
@ -1,4 +1,5 @@
|
||||
from os import getenv
|
||||
from secrets import compare_digest
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import Depends, HTTPException, Request
|
||||
@ -29,7 +30,7 @@ async def check_auth(
|
||||
user_index = usernames.index(credentials.username)
|
||||
password = passwords[user_index]
|
||||
|
||||
if credentials.password != password:
|
||||
if not compare_digest(credentials.password.encode(), password.encode()):
|
||||
raise http_401()
|
||||
|
||||
return credentials
|
||||
|
Loading…
Reference in New Issue
Block a user