File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77from app .schemas .user import UserInDB
88from fastapi import Depends , HTTPException , Request , status
99from fastapi .security import OAuth2PasswordBearer
10- from itsdangerous import URLSafeTimedSerializer
1110from passlib .context import CryptContext
1211
1312oauth2_scheme = OAuth2PasswordBearer (tokenUrl = "/api/v1/login" )
@@ -112,15 +111,14 @@ def validate_csrf_token(request: Request) -> str:
112111
113112 # Get CSRF token from header and cookie
114113 header_token = request .headers .get ("X-CSRF-Token" )
115- cookie_token = request .cookies .get ("csrf_token" )
116-
114+ cookie_token = request .cookies .get ("csrf_token" , "" )
115+
117116 if not header_token :
118117 raise HTTPException (
119118 status_code = status .HTTP_403_FORBIDDEN ,
120119 detail = "CSRF token missing"
121120 )
122121
123- # Validate using double-submit cookie pattern
124122 if not security_service .validate_csrf_token (header_token , cookie_token ):
125123 raise HTTPException (
126124 status_code = status .HTTP_403_FORBIDDEN ,
You can’t perform that action at this time.
0 commit comments