Skip to content
Myr

include samesite and secure when removing session cookie (#3726)

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

authored by Mathurshan Vimalesvaran · committed by GitHub · parent 7a444c5 · Browse files · 3 files+20 added−3 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+20 added−3 removed

  • tests:+13 added−0 removed
  • other:+7 added−3 removed

3 files+20 added−3 removed

modified:src/flask/sessions.py+5 added-3 removed
349 unmodified lines
350 def save_session(self, app, session, response):351 name = self.get_cookie_name(app)352 domain = self.get_cookie_domain(app)353 path = self.get_cookie_path(app)354 secure = self.get_cookie_secure(app)355 samesite = self.get_cookie_samesite(app)356357 # If the session is modified to be empty, remove the cookie.358 # If the session is empty, return without setting the cookie.359 if not session:360 if session.modified:359 response.delete_cookie(name, domain=domain, path=path)361 response.delete_cookie(362 name, domain=domain, path=path, secure=secure, samesite=samesite363 )364365 return366367 # Add a "Vary: Cookie" header if the session was accessed at all.
3 unmodified lines
371 if not self.should_set_cookie(app, session):372 return373374 httponly = self.get_cookie_httponly(app)371 secure = self.get_cookie_secure(app)372 samesite = self.get_cookie_samesite(app)375 expires = self.get_expiration_time(app, session)376 val = self.get_signing_serializer(app).dumps(dict(session))377 response.set_cookie(378 name,
8 unmodified lines
modified:tests/test_basic.py+13 added
320 unmodified lines
321 assert "secure" in cookie322 assert "httponly" not in cookie323 assert "samesite" in cookie324325 @app.route("/clear")326 def clear():327 flask.session.pop("testing", None)328 return "Goodbye World"329330 rv = client.get("/clear", "http://www.example.com:8080/test/")331 cookie = rv.headers["set-cookie"].lower()332 assert "session=;" in cookie333 assert "domain=.example.com" in cookie334 assert "path=/" in cookie335 assert "secure" in cookie336 assert "samesite" in cookie337338339def test_session_using_samesite_attribute(app, client):340 @app.route("/")341 def index():342 flask.session["testing"] = 42
1668 unmodified lines
modified:CHANGES.rst+2 added
40 unmodified lines
41 ``Blueprint`` classes. ``Blueprint`` information is stored in42 attributes just like ``Flask``, rather than opaque lambda functions.43 This is intended to improve consistency and maintainability.44 :issue:`3215`45- Include ``samesite`` and ``secure`` options when removing the46 session cookie. :pr:`3726`474849Version 1.1.x50-------------
1020 unmodified lines