moazx commited on
Commit
0f194af
·
1 Parent(s): ddc9c77

Update .gitignore to include frontend and Lung Cancer Guidelines directories. Enhance CORS middleware configuration to allow origins from environment variables, with defaults for local development. Modify session cookie settings to require secure flag for SameSite=None, improving security for cross-site requests.

Browse files
Files changed (3) hide show
  1. .gitignore +4 -2
  2. api/middleware.py +14 -1
  3. api/routers/auth.py +2 -2
.gitignore CHANGED
@@ -144,6 +144,7 @@ ENV/
144
  env.bak/
145
  venv.bak/
146
 
 
147
  # Spyder project settings
148
  .spyderproject
149
  .spyproject
@@ -206,5 +207,6 @@ marimo/_static/
206
  marimo/_lsp/
207
  __marimo__/
208
 
209
- # Frontend
210
- # frontend/
 
 
144
  env.bak/
145
  venv.bak/
146
 
147
+
148
  # Spyder project settings
149
  .spyderproject
150
  .spyproject
 
207
  marimo/_lsp/
208
  __marimo__/
209
 
210
+
211
+ Lung Cancer Guidelines/
212
+ frontend/
api/middleware.py CHANGED
@@ -139,9 +139,22 @@ class AuthenticationMiddleware(BaseHTTPMiddleware):
139
 
140
  def get_cors_middleware_config():
141
  """Get CORS middleware configuration"""
 
 
 
 
 
 
 
 
 
 
 
 
142
  return {
143
- "allow_origins": ["*"], # Configure appropriately for production
144
  "allow_credentials": True,
145
  "allow_methods": ["*"],
146
  "allow_headers": ["*"],
 
147
  }
 
139
 
140
  def get_cors_middleware_config():
141
  """Get CORS middleware configuration"""
142
+ import os
143
+
144
+ # Get allowed origins from environment or use defaults
145
+ allowed_origins = os.getenv("ALLOWED_ORIGINS", "").split(",")
146
+ if not allowed_origins or allowed_origins == [""]:
147
+ # Default to allowing Hugging Face Space and localhost
148
+ allowed_origins = [
149
+ "https://moazx-api.hf.space",
150
+ "http://localhost:8000",
151
+ "http://127.0.0.1:8000"
152
+ ]
153
+
154
  return {
155
+ "allow_origins": allowed_origins,
156
  "allow_credentials": True,
157
  "allow_methods": ["*"],
158
  "allow_headers": ["*"],
159
+ "expose_headers": ["*"],
160
  }
api/routers/auth.py CHANGED
@@ -112,8 +112,8 @@ async def login(
112
  value=token,
113
  httponly=True,
114
  max_age=SESSION_MAX_AGE,
115
- samesite="lax",
116
- secure=False # Set to True in production with HTTPS
117
  )
118
 
119
  logger.info(f"Successful login for user: {username}")
 
112
  value=token,
113
  httponly=True,
114
  max_age=SESSION_MAX_AGE,
115
+ samesite="none",
116
+ secure=True # Required for SameSite=None
117
  )
118
 
119
  logger.info(f"Successful login for user: {username}")