Hamdy005 commited on
Commit
463e7aa
·
1 Parent(s): b37ddec

refactor: secure CORS origins and centralize user profile session exchange during authentication flow

Browse files
Files changed (1) hide show
  1. main.py +13 -1
main.py CHANGED
@@ -110,9 +110,21 @@ async def normalize_path(request, call_next):
110
  request.scope["path"] = path.replace("//", "/")
111
  return await call_next(request)
112
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  app.add_middleware(
114
  CORSMiddleware,
115
- allow_origins=settings.cors_allowed_origins or ["*"],
116
  allow_credentials=True,
117
  allow_methods=["*"],
118
  allow_headers=["*"],
 
110
  request.scope["path"] = path.replace("//", "/")
111
  return await call_next(request)
112
 
113
+
114
+ # When allow_credentials=True, browsers REJECT responses with "Access-Control-Allow-Origin: *"
115
+ # and refuse to store or send cookies. We must always use explicit origins.
116
+ _DEFAULT_ORIGINS = [
117
+ "https://www.studybuddyai.dev",
118
+ "https://studybuddyai.dev",
119
+ "https://hamdy005-study-buddy.hf.space",
120
+ "http://localhost:3000",
121
+ "http://localhost:3001",
122
+ ]
123
+ _cors_origins = settings.cors_allowed_origins if settings.cors_allowed_origins else _DEFAULT_ORIGINS
124
+
125
  app.add_middleware(
126
  CORSMiddleware,
127
+ allow_origins=_cors_origins,
128
  allow_credentials=True,
129
  allow_methods=["*"],
130
  allow_headers=["*"],