Spaces:
Running
Running
sunheycho
commited on
Commit
Β·
e8e0147
1
Parent(s):
f999852
Fix Safari login redirect issue
Browse files- Changed SameSite cookie policy from 'None' to 'Lax' for Safari compatibility
- Added dynamic HTTPS detection for secure cookie configuration
- Improved session handling across different browsers
- Safari now properly redirects to index page after login
api.py
CHANGED
@@ -109,16 +109,33 @@ app.secret_key = secret_key # μΈμ
μνΈνλ₯Ό μν λΉλ° ν€
|
|
109 |
app.config['CORS_HEADERS'] = 'Content-Type'
|
110 |
# Remember cookie (Flask-Login) β minimize duration to prevent auto re-login
|
111 |
app.config['REMEMBER_COOKIE_DURATION'] = timedelta(seconds=1)
|
112 |
-
|
|
|
|
|
113 |
app.config['REMEMBER_COOKIE_HTTPONLY'] = True
|
114 |
-
app.config['REMEMBER_COOKIE_SAMESITE'] = 'None
|
115 |
-
# Session cookie (Flask-Session) -
|
116 |
-
app.config['SESSION_COOKIE_SECURE'] =
|
117 |
app.config['SESSION_COOKIE_HTTPONLY'] = True
|
118 |
-
app.config['SESSION_COOKIE_SAMESITE'] = '
|
119 |
app.config['SESSION_COOKIE_PATH'] = '/'
|
120 |
CORS(app, supports_credentials=True) # Enable CORS for all routes with credentials
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
# μν¬λ¦Ώ ν€ μ€μ (μΈμ
μνΈνμ μ¬μ©)
|
123 |
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'vision_llm_agent_secret_key')
|
124 |
app.config['SESSION_TYPE'] = 'filesystem'
|
|
|
109 |
app.config['CORS_HEADERS'] = 'Content-Type'
|
110 |
# Remember cookie (Flask-Login) β minimize duration to prevent auto re-login
|
111 |
app.config['REMEMBER_COOKIE_DURATION'] = timedelta(seconds=1)
|
112 |
+
# Safari compatibility: Use Lax instead of None for better Safari support
|
113 |
+
# Secure cookies only for HTTPS (will be set dynamically in production)
|
114 |
+
app.config['REMEMBER_COOKIE_SECURE'] = False # Will be overridden in production
|
115 |
app.config['REMEMBER_COOKIE_HTTPONLY'] = True
|
116 |
+
app.config['REMEMBER_COOKIE_SAMESITE'] = 'Lax' # Changed from None to Lax for Safari compatibility
|
117 |
+
# Session cookie (Flask-Session) - Safari compatible settings
|
118 |
+
app.config['SESSION_COOKIE_SECURE'] = False # Will be overridden in production
|
119 |
app.config['SESSION_COOKIE_HTTPONLY'] = True
|
120 |
+
app.config['SESSION_COOKIE_SAMESITE'] = 'Lax' # Changed from None to Lax for Safari compatibility
|
121 |
app.config['SESSION_COOKIE_PATH'] = '/'
|
122 |
CORS(app, supports_credentials=True) # Enable CORS for all routes with credentials
|
123 |
|
124 |
+
# Dynamic HTTPS detection and cookie security settings
|
125 |
+
@app.before_request
|
126 |
+
def configure_cookies_for_https():
|
127 |
+
"""Dynamically configure cookie security based on HTTPS detection"""
|
128 |
+
is_https = (
|
129 |
+
request.is_secure or
|
130 |
+
request.headers.get('X-Forwarded-Proto') == 'https' or
|
131 |
+
request.headers.get('X-Forwarded-Ssl') == 'on' or
|
132 |
+
os.environ.get('HTTPS', '').lower() == 'true'
|
133 |
+
)
|
134 |
+
|
135 |
+
if is_https:
|
136 |
+
app.config['SESSION_COOKIE_SECURE'] = True
|
137 |
+
app.config['REMEMBER_COOKIE_SECURE'] = True
|
138 |
+
|
139 |
# μν¬λ¦Ώ ν€ μ€μ (μΈμ
μνΈνμ μ¬μ©)
|
140 |
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'vision_llm_agent_secret_key')
|
141 |
app.config['SESSION_TYPE'] = 'filesystem'
|