Spaces:
Sleeping
Sleeping
GitHub Actions commited on
Commit ·
7b8fda4
1
Parent(s): 09751b8
deploy: sync from GitHub d8d396e34cf4c78eeefb27a01656a263b54ee41e
Browse files
app.py
CHANGED
|
@@ -35,7 +35,14 @@ else:
|
|
| 35 |
print(f"INFO: FLASK_SECRET_KEY is set (length={len(_secret_key)})")
|
| 36 |
app.secret_key = _secret_key
|
| 37 |
|
| 38 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
# comment out these lines if you want to see full logs
|
| 40 |
log = logging.getLogger('werkzeug')
|
| 41 |
log.setLevel(logging.ERROR)
|
|
|
|
| 35 |
print(f"INFO: FLASK_SECRET_KEY is set (length={len(_secret_key)})")
|
| 36 |
app.secret_key = _secret_key
|
| 37 |
|
| 38 |
+
# HF Spaces serves over HTTPS via a reverse proxy and may embed the app in an iframe.
|
| 39 |
+
# SameSite=None;Secure is required so cookies are sent in cross-site/iframe POST requests.
|
| 40 |
+
# HF sets SPACE_HOST env var; fall back to checking SPACE_ID or SPACE_AUTHOR_NAME.
|
| 41 |
+
_on_https = any(os.environ.get(v) for v in ('SPACE_HOST', 'SPACE_ID', 'SPACE_AUTHOR_NAME'))
|
| 42 |
+
app.config['SESSION_COOKIE_SECURE'] = _on_https
|
| 43 |
+
app.config['SESSION_COOKIE_SAMESITE'] = 'None' if _on_https else 'Lax'
|
| 44 |
+
app.config['SESSION_COOKIE_HTTPONLY'] = True
|
| 45 |
+
print(f"INFO: SESSION_COOKIE_SECURE={_on_https}, SAMESITE={'None' if _on_https else 'Lax'}")
|
| 46 |
# comment out these lines if you want to see full logs
|
| 47 |
log = logging.getLogger('werkzeug')
|
| 48 |
log.setLevel(logging.ERROR)
|