Grepping SESSION_COOKIE_DOMAIN via the Flask Github repo shows that it is used like this :
def get_cookie_domain(self, app): """Helpful helper method that returns the cookie domain that should be used for the session cookie if session cookies are used. """ if app.config['SESSION_COOKIE_DOMAIN'] is not None: return app.config['SESSION_COOKIE_DOMAIN'] if app.config['SERVER_NAME'] is not None:
By doing the same with get_cookie_domain( , you see :
def save_session(self, app, session, response): domain = self.get_cookie_domain(app) path = self.get_cookie_path(app) ...
OK Now we only need to figure out which domain name to use. Digging out docs or code , you will see that save_session() is called in the context of the request. Therefore, you just need to import the request object from the flask module:
from flask import request
and use it inside save_session() to determine the domain name for cookies (for example, from the Host header), for example:
def save_session(self, app, session, response): domain = '.' + request.headers['Host'] path = self.get_cookie_path(app)
The only time you need to specify a cookie domain is when you send it back with the response object.
Also note that the Host header may be missing.
To link all this, you need to specify your version (subclass) of SecureCookieSessionInterface :
app = Flask(__name__) app.session_interface = MySessionInterface()
Additional doc links: