Changed session cookie defaults to work better with google chrome
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 6bd0080 · Browse files · 3 files·+28 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+28 added−0 removed
- other:+28 added−0 removed
Provenance
- Commit
bfeee75- Tree
165ae3e- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
6bd0080
3 files changed+28 added−0 removed
modified:flask/testsuite/basic.py+16 added
188 unmodified lines189 rv = app.test_client().get('/', 'http://example.com:8080/')190 self.assert_('domain=.example.com' in rv.headers['set-cookie'].lower())191 self.assert_('httponly' in rv.headers['set-cookie'].lower())192 193+ def test_session_using_server_name_port_and_path(self):194+ app = flask.Flask(__name__)195+ app.config.update(196+ SECRET_KEY='foo',197+ SERVER_NAME='example.com:8080',198+ APPLICATION_ROOT='/foo'199+ )200+ @app.route('/')201+ def index():202+ flask.session['testing'] = 42203+ return 'Hello World'204+ rv = app.test_client().get('/', 'http://example.com:8080/foo')205+ self.assert_('domain=example.com' in rv.headers['set-cookie'].lower())206+ self.assert_('path=/foo' in rv.headers['set-cookie'].lower())207+ self.assert_('httponly' in rv.headers['set-cookie'].lower())208+209 def test_session_using_application_root(self):210 class PrefixPathMiddleware(object):211 def __init__(self, app, prefix):212 self.app = app1044 unmodified linesmodified:flask/sessions.py+10 added
191 unmodified lines192 return app.config['SESSION_COOKIE_DOMAIN']193 if app.config['SERVER_NAME'] is not None:194 # chop of the port which is usually not supported by browsers195 rv = '.' + app.config['SERVER_NAME'].rsplit(':', 1)[0]196+197 # Google chrome does not like cookies set to .localhost, so198 # we just go with no domain then. Flask documents anyways that199 # cross domain cookies need a fully qualified domain name200 if rv == '.localhost':201 rv = None202+203+ # If we infer the cookie domain from the server name we need204+ # to check if we are in a subpath. In that case we can't205+ # set a cross domain cookie.206+ if rv is not None:207+ path = self.get_cookie_path(app)208+ if path != '/':209+ rv = rv.lstrip('.')210+211 return rv212 213 def get_cookie_path(self, app):214 """Returns the path for which the cookie should be valid. The107 unmodified linesmodified:CHANGES+2 added
47 unmodified lines48 - Flask will no longer invoke the wrong error handlers if a proxy49 exception is passed through.50 - Added a workaround for chrome's cookies in localhost not working51 as intended with domain names.52+- Changed logic for picking defaults for cookie values from sessions53+ to work better with Google Chrome.54 55 Version 0.956 -----------57 365 unmodified lines