Skip to content
Myr

Chop of ports for session cookies. This fixes #253

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 4e47ea9 · Browse files · 2 files+16 added−1 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+16 added−1 removed

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

2 files+16 added−1 removed

modified:flask/app.py+2 added-1 removed
600 unmodified lines
601 expires = domain = None602 if session.permanent:603 expires = datetime.utcnow() + self.permanent_session_lifetime604 if self.config['SERVER_NAME'] is not None:605 # chop of the port which is usually not supported by browsers605 domain = '.' + self.config['SERVER_NAME']606 domain = '.' + self.config['SERVER_NAME'].rsplit(':', 1)[0]607 session.save_cookie(response, self.session_cookie_name,608 expires=expires, httponly=True, domain=domain)609610 def register_module(self, module, **options):
685 unmodified lines
modified:tests/flask_tests.py+14 added
304 unmodified lines
305 rv = app.test_client().get('/', 'http://example.com/')306 assert 'domain=.example.com' in rv.headers['set-cookie'].lower()307 assert 'httponly' in rv.headers['set-cookie'].lower()308309 def test_session_using_server_name_and_port(self):310 app = flask.Flask(__name__)311 app.config.update(312 SECRET_KEY='foo',313 SERVER_NAME='example.com:8080'314 )315 @app.route('/')316 def index():317 flask.session['testing'] = 42318 return 'Hello World'319 rv = app.test_client().get('/', 'http://example.com:8080/')320 assert 'domain=.example.com' in rv.headers['set-cookie'].lower()321 assert 'httponly' in rv.headers['set-cookie'].lower()322323 def test_missing_session(self):324 app = flask.Flask(__name__)325 def expect_exception(f, *args, **kwargs):326 try:
1473 unmodified lines