Skip to content
Myr

Merge pull request from GHSA-m2qf-hxjv-5gpq

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

set `Vary: Cookie` header consistently for session

authored by David Lord · committed by GitHub · parents 9532cba, 8705dd3 · Browse files · 2 files+29 added−4 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+29 added−4 removed

  • tests:+23 added−0 removed
  • other:+6 added−4 removed

2 files+29 added−4 removed

modified:src/flask/sessions.py+6 added-4 removed
327 unmodified lines
328 secure = self.get_cookie_secure(app)329 samesite = self.get_cookie_samesite(app)330 httponly = self.get_cookie_httponly(app)331332 # Add a "Vary: Cookie" header if the session was accessed at all.333 if session.accessed:334 response.vary.add("Cookie")335336 # If the session is modified to be empty, remove the cookie.337 # If the session is empty, return without setting the cookie.338 if not session:339 if session.modified:
4 unmodified lines
344 secure=secure,345 samesite=samesite,346 httponly=httponly,347 )348 response.vary.add("Cookie")349350 return351347 # Add a "Vary: Cookie" header if the session was accessed at all.348 if session.accessed:349 response.vary.add("Cookie")350352 if not self.should_set_cookie(app, session):353 return354355 expires = self.get_expiration_time(app, session)
7 unmodified lines
363 path=path,364 secure=secure,365 samesite=samesite,366 )367 response.vary.add("Cookie")
modified:tests/test_basic.py+23 added
499 unmodified lines
500 @app.route("/setdefault")501 def setdefault():502 return flask.session.setdefault("test", "default")503504 @app.route("/clear")505 def clear():506 flask.session.clear()507 return ""508509 @app.route("/vary-cookie-header-set")510 def vary_cookie_header_set():511 response = flask.Response()512 response.vary.add("Cookie")
24 unmodified lines
537 expect("/set")538 expect("/get")539 expect("/getitem")540 expect("/setdefault")541 expect("/clear")542 expect("/vary-cookie-header-set")543 expect("/vary-header-set", "Accept-Encoding, Accept-Language, Cookie")544 expect("/no-vary-header", None)545546547def test_session_refresh_vary(app, client):548 @app.get("/login")549 def login():550 flask.session["user_id"] = 1551 flask.session.permanent = True552 return ""553554 @app.get("/ignored")555 def ignored():556 return ""557558 rv = client.get("/login")559 assert rv.headers["Vary"] == "Cookie"560 rv = client.get("/ignored")561 assert rv.headers["Vary"] == "Cookie"562563564def test_flashes(app, req_ctx):565 assert not flask.session.modified566 flask.flash("Zap")567 flask.session.modified = False
1321 unmodified lines