Browse Source

fix: V-001 security vulnerability

Automated security fix generated by OrbisAI Security
pull/15558/head
orbisai0security 2 weeks ago
parent
commit
1e6e4e7f58
  1. 7
      docs_src/security/tutorial005_an_py310.py
  2. 7
      docs_src/security/tutorial005_py310.py

7
docs_src/security/tutorial005_an_py310.py

@ -1,3 +1,4 @@
import os
from datetime import datetime, timedelta, timezone
from typing import Annotated
@ -14,7 +15,7 @@ from pydantic import BaseModel, ValidationError
# to get a string like this run:
# openssl rand -hex 32
SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
SECRET_KEY = os.environ.get("SECRET_KEY", "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7")
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 30
@ -118,7 +119,9 @@ async def get_current_user(
headers={"WWW-Authenticate": authenticate_value},
)
try:
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
payload = jwt.decode(
token, SECRET_KEY, algorithms=[ALGORITHM], options={"require": ["exp"]}
)
username = payload.get("sub")
if username is None:
raise credentials_exception

7
docs_src/security/tutorial005_py310.py

@ -1,3 +1,4 @@
import os
from datetime import datetime, timedelta, timezone
import jwt
@ -13,7 +14,7 @@ from pydantic import BaseModel, ValidationError
# to get a string like this run:
# openssl rand -hex 32
SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
SECRET_KEY = os.environ.get("SECRET_KEY", "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7")
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 30
@ -117,7 +118,9 @@ async def get_current_user(
headers={"WWW-Authenticate": authenticate_value},
)
try:
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
payload = jwt.decode(
token, SECRET_KEY, algorithms=[ALGORITHM], options={"require": ["exp"]}
)
username: str = payload.get("sub")
if username is None:
raise credentials_exception

Loading…
Cancel
Save