Chop of ports for session cookies. This fixes #253
This commit is contained in:
parent
4e47ea9105
commit
ccd5ced70e
2 changed files with 16 additions and 1 deletions
|
|
@ -602,7 +602,8 @@ class Flask(_PackageBoundObject):
|
||||||
if session.permanent:
|
if session.permanent:
|
||||||
expires = datetime.utcnow() + self.permanent_session_lifetime
|
expires = datetime.utcnow() + self.permanent_session_lifetime
|
||||||
if self.config['SERVER_NAME'] is not None:
|
if self.config['SERVER_NAME'] is not None:
|
||||||
domain = '.' + self.config['SERVER_NAME']
|
# chop of the port which is usually not supported by browsers
|
||||||
|
domain = '.' + self.config['SERVER_NAME'].rsplit(':', 1)[0]
|
||||||
session.save_cookie(response, self.session_cookie_name,
|
session.save_cookie(response, self.session_cookie_name,
|
||||||
expires=expires, httponly=True, domain=domain)
|
expires=expires, httponly=True, domain=domain)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -306,6 +306,20 @@ class BasicFunctionalityTestCase(unittest.TestCase):
|
||||||
assert 'domain=.example.com' in rv.headers['set-cookie'].lower()
|
assert 'domain=.example.com' in rv.headers['set-cookie'].lower()
|
||||||
assert 'httponly' in rv.headers['set-cookie'].lower()
|
assert 'httponly' in rv.headers['set-cookie'].lower()
|
||||||
|
|
||||||
|
def test_session_using_server_name_and_port(self):
|
||||||
|
app = flask.Flask(__name__)
|
||||||
|
app.config.update(
|
||||||
|
SECRET_KEY='foo',
|
||||||
|
SERVER_NAME='example.com:8080'
|
||||||
|
)
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
flask.session['testing'] = 42
|
||||||
|
return 'Hello World'
|
||||||
|
rv = app.test_client().get('/', 'http://example.com:8080/')
|
||||||
|
assert 'domain=.example.com' in rv.headers['set-cookie'].lower()
|
||||||
|
assert 'httponly' in rv.headers['set-cookie'].lower()
|
||||||
|
|
||||||
def test_missing_session(self):
|
def test_missing_session(self):
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
def expect_exception(f, *args, **kwargs):
|
def expect_exception(f, *args, **kwargs):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue