Amogh1221 commited on
Commit
757fc92
·
verified ·
1 Parent(s): df7cbd5

Update api/routes.py

Browse files
Files changed (1) hide show
  1. api/routes.py +8 -2
api/routes.py CHANGED
@@ -224,11 +224,17 @@ def get_session_messages(
224
  messages = patient_service.get_session_messages(session_id)
225
  return {"messages": messages}
226
 
 
 
 
 
227
  @router.get("/{full_path:path}", response_class=HTMLResponse)
228
  def catch_all(request: Request, full_path: str):
229
  """
230
  Catch-all route to support History API (clean URLs) in the frontend SPA.
231
- If the user navigates directly to /profiles or /dashboard, serve index.html
232
- so the frontend JS can handle the routing.
233
  """
 
 
234
  return templates.TemplateResponse(request, "index.html")
 
224
  messages = patient_service.get_session_messages(session_id)
225
  return {"messages": messages}
226
 
227
+ _BLOCKED_PATH_FRAGMENTS = {
228
+ ".streamlit", ".env", "secrets.toml", "config.toml", ".git", "wp-admin", ".well-known"
229
+ }
230
+
231
  @router.get("/{full_path:path}", response_class=HTMLResponse)
232
  def catch_all(request: Request, full_path: str):
233
  """
234
  Catch-all route to support History API (clean URLs) in the frontend SPA.
235
+ Returns 404 for known config/secret paths probed by bots (e.g. .streamlit/secrets.toml).
236
+ Otherwise serves index.html so the frontend JS handles SPA routing.
237
  """
238
+ if any(fragment in full_path for fragment in _BLOCKED_PATH_FRAGMENTS):
239
+ return Response(status_code=404)
240
  return templates.TemplateResponse(request, "index.html")