Skip to content
Myr

Respect the domain for the session cookie. This fixes #79

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 56796f0 · Browse files · 2 files+19 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+19 added−2 removed

  • tests:+14 added−0 removed
  • other:+5 added−2 removed

2 files+19 added−2 removed

modified:flask/app.py+5 added-2 removed
418 unmodified lines
419 :class:`~werkzeug.contrib.securecookie.SecureCookie`420 object)421 :param response: an instance of :attr:`response_class`422 """423 expires = None423 expires = domain = None424 if session.permanent:425 expires = datetime.utcnow() + self.permanent_session_lifetime426 if self.config['SERVER_NAME'] is not None:427 domain = '.' + self.config['SERVER_NAME']428 session.save_cookie(response, self.session_cookie_name,427 expires=expires, httponly=True)429 expires=expires, httponly=True,430 domain=domain)431432 def register_module(self, module, **options):433 """Registers a module with this application. The keyword argument434 of this function are the same as the ones for the constructor of the
382 unmodified lines
modified:tests/flask_tests.py+14 added
170 unmodified lines
171 c = app.test_client()172 assert c.post('/set', data={'value': '42'}).data == 'value set'173 assert c.get('/get').data == '42'174175 def test_session_using_server_name(self):176 app = flask.Flask(__name__)177 app.config.update(178 SECRET_KEY='foo',179 SERVER_NAME='example.com'180 )181 @app.route('/')182 def index():183 flask.session['testing'] = 42184 return 'Hello World'185 rv = app.test_client().get('/', 'http://example.com/')186 assert 'domain=.example.com' in rv.headers['set-cookie'].lower()187 assert 'httponly' in rv.headers['set-cookie'].lower()188189 def test_missing_session(self):190 app = flask.Flask(__name__)191 def expect_exception(f, *args, **kwargs):192 try:
756 unmodified lines