David Ko commited on
Commit
d1b4a04
Β·
1 Parent(s): dfdf7e7

Use SameSite=None for session/remember cookies (iframe compatibility on Spaces)

Browse files
Files changed (1) hide show
  1. api.py +10 -3
api.py CHANGED
@@ -33,9 +33,16 @@ from chromadb.utils import embedding_functions
33
  app = Flask(__name__, static_folder='static')
34
  app.secret_key = 'your_secret_key_here' # μ„Έμ…˜ μ•”ν˜Έν™”λ₯Ό μœ„ν•œ λΉ„λ°€ ν‚€
35
  app.config['CORS_HEADERS'] = 'Content-Type'
36
- app.config['REMEMBER_COOKIE_DURATION'] = timedelta(days=30) # μΏ ν‚€ 지속 μ‹œκ°„
37
- app.config['REMEMBER_COOKIE_SECURE'] = False # 개발 ν™˜κ²½μ—μ„œλŠ” False, ν”„λ‘œλ•μ…˜μ—μ„œλŠ” True둜 μ„€μ •
 
38
  app.config['REMEMBER_COOKIE_HTTPONLY'] = True
 
 
 
 
 
 
39
  CORS(app) # Enable CORS for all routes
40
 
41
  # μ‹œν¬λ¦Ώ ν‚€ μ„€μ • (μ„Έμ…˜ μ•”ν˜Έν™”μ— μ‚¬μš©)
@@ -1183,7 +1190,7 @@ def login():
1183
  print(f"Redirecting to: {next_page}")
1184
  return redirect(next_page)
1185
  print("Redirecting to index.html")
1186
- return redirect('/index.html')
1187
  else:
1188
  error = 'Invalid username or password'
1189
  print(f"Login failed: {error}")
 
33
  app = Flask(__name__, static_folder='static')
34
  app.secret_key = 'your_secret_key_here' # μ„Έμ…˜ μ•”ν˜Έν™”λ₯Ό μœ„ν•œ λΉ„λ°€ ν‚€
35
  app.config['CORS_HEADERS'] = 'Content-Type'
36
+ # Remember cookie (Flask-Login)
37
+ app.config['REMEMBER_COOKIE_DURATION'] = timedelta(days=30)
38
+ app.config['REMEMBER_COOKIE_SECURE'] = True # Spaces uses HTTPS
39
  app.config['REMEMBER_COOKIE_HTTPONLY'] = True
40
+ app.config['REMEMBER_COOKIE_SAMESITE'] = 'None'
41
+ # Session cookie (Flask-Session)
42
+ app.config['SESSION_COOKIE_SECURE'] = True # HTTPS
43
+ app.config['SESSION_COOKIE_HTTPONLY'] = True
44
+ app.config['SESSION_COOKIE_SAMESITE'] = 'None'
45
+ app.config['SESSION_COOKIE_PATH'] = '/'
46
  CORS(app) # Enable CORS for all routes
47
 
48
  # μ‹œν¬λ¦Ώ ν‚€ μ„€μ • (μ„Έμ…˜ μ•”ν˜Έν™”μ— μ‚¬μš©)
 
1190
  print(f"Redirecting to: {next_page}")
1191
  return redirect(next_page)
1192
  print("Redirecting to index.html")
1193
+ return redirect(url_for('serve_index_html'))
1194
  else:
1195
  error = 'Invalid username or password'
1196
  print(f"Login failed: {error}")