Christian Kniep commited on
Commit
187ecdc
·
1 Parent(s): 32cff9c

'change session type'

Browse files
Files changed (3) hide show
  1. Dockerfile +1 -0
  2. requirements.txt +1 -0
  3. src/app.py +12 -0
Dockerfile CHANGED
@@ -12,6 +12,7 @@ COPY migrations/ migrations/
12
  COPY entrypoint.sh /app/entrypoint.sh
13
 
14
  RUN mkdir -p data
 
15
  RUN chmod +x /app/entrypoint.sh
16
 
17
  EXPOSE 7860
 
12
  COPY entrypoint.sh /app/entrypoint.sh
13
 
14
  RUN mkdir -p data
15
+ RUN mkdir -p data/flask_sessions
16
  RUN chmod +x /app/entrypoint.sh
17
 
18
  EXPOSE 7860
requirements.txt CHANGED
@@ -1,6 +1,7 @@
1
  # Core web framework
2
  Flask==3.0.0
3
  Flask-WTF==1.2.1
 
4
 
5
  # Authentication
6
  Authlib==1.2.1
 
1
  # Core web framework
2
  Flask==3.0.0
3
  Flask-WTF==1.2.1
4
+ Flask-Session==0.5.0
5
 
6
  # Authentication
7
  Authlib==1.2.1
src/app.py CHANGED
@@ -10,6 +10,7 @@ import time
10
  from datetime import timedelta
11
 
12
  from flask import Flask, jsonify, request, g
 
13
  from dotenv import load_dotenv
14
  from opentelemetry import trace
15
  from opentelemetry.trace import Status, StatusCode
@@ -65,6 +66,13 @@ def create_app():
65
  # Configuration
66
  app.config["SECRET_KEY"] = os.getenv("SECRET_KEY", "dev-secret-key-change-me")
67
 
 
 
 
 
 
 
 
68
  # Session cookie configuration
69
  # For HTTPS (HF Spaces): Set SESSION_COOKIE_SECURE=true
70
  secure_cookie = os.getenv("SESSION_COOKIE_SECURE", "False").lower() == "true"
@@ -117,6 +125,10 @@ def create_app():
117
  # Initialize database
118
  init_db()
119
 
 
 
 
 
120
  # Initialize OAuth
121
  auth_service.init_app(app)
122
 
 
10
  from datetime import timedelta
11
 
12
  from flask import Flask, jsonify, request, g
13
+ from flask_session import Session
14
  from dotenv import load_dotenv
15
  from opentelemetry import trace
16
  from opentelemetry.trace import Status, StatusCode
 
66
  # Configuration
67
  app.config["SECRET_KEY"] = os.getenv("SECRET_KEY", "dev-secret-key-change-me")
68
 
69
+ # CRITICAL: Use server-side sessions to avoid cookie size limits (4KB)
70
+ # OAuth state tokens make cookies exceed size limit, causing state to be lost
71
+ app.config["SESSION_TYPE"] = "filesystem" # Store sessions server-side
72
+ app.config["SESSION_FILE_DIR"] = "/app/data/flask_sessions" # Session storage directory
73
+ app.config["SESSION_PERMANENT"] = False # Default to non-permanent (override per-session)
74
+ app.config["SESSION_USE_SIGNER"] = True # Sign session cookie for security
75
+
76
  # Session cookie configuration
77
  # For HTTPS (HF Spaces): Set SESSION_COOKIE_SECURE=true
78
  secure_cookie = os.getenv("SESSION_COOKIE_SECURE", "False").lower() == "true"
 
125
  # Initialize database
126
  init_db()
127
 
128
+ # Initialize Flask-Session (must be BEFORE OAuth init)
129
+ # This stores sessions server-side to avoid 4KB cookie size limit
130
+ Session(app)
131
+
132
  # Initialize OAuth
133
  auth_service.init_app(app)
134