Skip to content
Snippets Groups Projects
Commit 638676c2 authored by Tim Neumann's avatar Tim Neumann
Browse files

fix(check_token): Fix timestamp check and add bad signature check

parent 5033e83a
No related branches found
No related tags found
2 merge requests!4fix(auth): Protect /storages and /tag endpoints,!3fix(auth): Protect /storages and /tag endpoints
......@@ -5,6 +5,7 @@ from fastapi import Depends, FastAPI, HTTPException, Request, UploadFile, status
from fastapi.middleware.cors import CORSMiddleware
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from itsdangerous.serializer import Serializer
from itsdangerous import BadSignature
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
from slowapi.util import get_remote_address
......@@ -48,7 +49,13 @@ def get_db():
def check_token(token: str):
if datetime.fromtimestamp(oauth2_tokener.loads(token)) < datetime.now():
try:
timestamp = oauth2_tokener.loads(token)
if datetime.fromtimestamp(timestamp) > datetime.now():
return # success
except BadSignature:
pass
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid authentication credentials",
......@@ -56,6 +63,7 @@ def check_token(token: str):
)
# Routes
@app.post("/item/prepare", response_model=schemas.Item)
@limiter.limit("2/minute")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment