Skip to content
Myr

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

3 files+28 added−0 removed

modified:flask/testsuite/basic.py+16 added
188 unmodified lines
189 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())192193 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())208209 def test_session_using_application_root(self):210 class PrefixPathMiddleware(object):211 def __init__(self, app, prefix):212 self.app = app
1044 unmodified lines
modified:flask/sessions.py+10 added
191 unmodified lines
192 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]196197 # 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 = None202203 # 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('.')210211 return rv212213 def get_cookie_path(self, app):214 """Returns the path for which the cookie should be valid. The
107 unmodified lines
modified:CHANGES+2 added
47 unmodified lines
48- 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.5455Version 0.956-----------57
365 unmodified lines