github-actions[bot] commited on
Commit
66cfdc7
·
1 Parent(s): f5b927a

Sync backend files from GitHub c72593b

Browse files

Deployed-From: c72593b6f98884707856c32fd592db2f84874210

Files changed (1) hide show
  1. main.py +5 -4
main.py CHANGED
@@ -676,12 +676,13 @@ def unscoped(ws: str, key: str) -> Optional[str]:
676
  def get_index(request: Request):
677
  response = FileResponse(resource_path("index.html"))
678
  if not is_workspace_id(request.cookies.get(WORKSPACE_COOKIE)):
679
- # HF's proxy terminates TLS, so trust X-Forwarded-Proto. Over HTTPS the cookie is
680
- # SameSite=None so it also works inside the huggingface.co Space iframe.
681
- https = request.headers.get("x-forwarded-proto", request.url.scheme) == "https"
 
682
  response.set_cookie(
683
  WORKSPACE_COOKIE, uuid.uuid4().hex, max_age=365 * 24 * 3600, httponly=True,
684
- secure=https, samesite="none" if https else "lax",
685
  )
686
  return response
687
 
 
676
  def get_index(request: Request):
677
  response = FileResponse(resource_path("index.html"))
678
  if not is_workspace_id(request.cookies.get(WORKSPACE_COOKIE)):
679
+ # Deployed, the site is always HTTPS (HF's proxy terminates TLS and doesn't say so),
680
+ # and SameSite=None lets the cookie work inside the huggingface.co Space iframe.
681
+ # Local http dev keeps a plain Lax cookie.
682
+ secure = request.url.hostname not in ("localhost", "127.0.0.1")
683
  response.set_cookie(
684
  WORKSPACE_COOKIE, uuid.uuid4().hex, max_age=365 * 24 * 3600, httponly=True,
685
+ secure=secure, samesite="none" if secure else "lax",
686
  )
687
  return response
688