Update auth validation code to hash incoming tokens
This commit is contained in:
@@ -2,6 +2,7 @@ from fastapi import Depends, HTTPException, status
|
|||||||
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
||||||
|
|
||||||
from mft.database import get_db
|
from mft.database import get_db
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
|
||||||
security = HTTPBearer()
|
security = HTTPBearer()
|
||||||
@@ -23,6 +24,7 @@ def verify_token(
|
|||||||
HTTPException: If token is invalid or disabled
|
HTTPException: If token is invalid or disabled
|
||||||
"""
|
"""
|
||||||
token = credentials.credentials
|
token = credentials.credentials
|
||||||
|
token_hash = hashlib.sha256(token.encode()).hexdigest()
|
||||||
|
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
@@ -32,7 +34,7 @@ def verify_token(
|
|||||||
FROM auth
|
FROM auth
|
||||||
WHERE token = ?
|
WHERE token = ?
|
||||||
""",
|
""",
|
||||||
(token,),
|
(token_hash,),
|
||||||
).fetchone()
|
).fetchone()
|
||||||
|
|
||||||
if result is None or not result["enabled"]:
|
if result is None or not result["enabled"]:
|
||||||
|
|||||||
Reference in New Issue
Block a user