fix: decode_session must validate RS256 tokens (not just HS256)
This commit is contained in:
+22
-5
@@ -111,11 +111,28 @@ def _check_rate_limit(
|
||||
# ── Auth dependency functions ─────────────────────────────────────────────────
|
||||
|
||||
def _decode_session(token: str) -> User | None:
|
||||
"""Decode JWT and return the live User, or None if invalid/suspended."""
|
||||
try:
|
||||
payload = decode_token(token, jwt_secret)
|
||||
except _jwt.PyJWTError:
|
||||
return None
|
||||
"""Decode JWT (RS256 or HS256) and return the live User, or None if invalid/suspended."""
|
||||
payload = None
|
||||
|
||||
if oidc_private_key_pem:
|
||||
try:
|
||||
from cryptography.hazmat.primitives.serialization import load_pem_private_key
|
||||
priv = load_pem_private_key(oidc_private_key_pem.encode(), password=None)
|
||||
payload = _jwt.decode(
|
||||
token,
|
||||
priv.public_key(),
|
||||
algorithms=["RS256"],
|
||||
options={"verify_aud": False},
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if payload is None:
|
||||
try:
|
||||
payload = decode_token(token, jwt_secret)
|
||||
except _jwt.PyJWTError:
|
||||
return None
|
||||
|
||||
handle = payload.get("sub")
|
||||
if not handle:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user