Browse Source

Set samesite and secure attributes of session cookie. Enable strong session protection.

Sibren Vasse 5 years ago
parent
commit
e7c3a127b8
2 changed files with 4 additions and 0 deletions
  1. 1 0
      app/extensions.py
  2. 3 0
      server.py

+ 1 - 0
app/extensions.py

@@ -5,4 +5,5 @@ from flask_sqlalchemy import SQLAlchemy
 
 
 db = SQLAlchemy()
 db = SQLAlchemy()
 login_manager = LoginManager()
 login_manager = LoginManager()
+login_manager.session_protection = "strong"
 migrate = Migrate(db=db)
 migrate = Migrate(db=db)

+ 3 - 0
server.py

@@ -83,6 +83,9 @@ def create_app() -> Flask:
 
 
     # to avoid conflict with other cookie
     # to avoid conflict with other cookie
     app.config["SESSION_COOKIE_NAME"] = "slapp"
     app.config["SESSION_COOKIE_NAME"] = "slapp"
+    if URL.startswith("https"):
+        app.config["SESSION_COOKIE_SECURE"] = True
+    app.config["SESSION_COOKIE_SAMESITE"] = "strict"
 
 
     init_extensions(app)
     init_extensions(app)
     register_blueprints(app)
     register_blueprints(app)