add SESSION_COOKIE_PARTITIONED config
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 6f2014d · Browse files · 5 files·+34 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- co-authored-by: Jose Cespedes <josecespedes@ibm.com>
Diff stats
5 files+34 added−0 removed
- tests:+3 added−0 removed
- other:+31 added−0 removed
Provenance
- Commit
9efc1eb- Tree
a098f5e- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
6f2014d
5 files changed+34 added−0 removed
modified:docs/config.rst+17 added
171 unmodified lines172 sense.173 174 Default: ``False``175 176+.. py:data:: SESSION_COOKIE_PARTITIONED177+178+ Browsers will send cookies based on the top-level document's domain, rather179+ than only the domain of the document setting the cookie. This prevents third180+ party cookies set in iframes from "leaking" between separate sites.181+182+ Browsers are beginning to disallow non-partitioned third party cookies, so183+ you need to mark your cookies partitioned if you expect them to work in such184+ embedded situations.185+186+ Enabling this implicitly enables :data:`SESSION_COOKIE_SECURE` as well, as187+ it is only valid when served over HTTPS.188+189+ Default: ``False``190+191+ .. versionadded:: 3.1192+193 .. py:data:: SESSION_COOKIE_SAMESITE194 195 Restrict how cookies are sent with requests from external sites. Can196 be set to ``'Lax'`` (recommended) or ``'Strict'``.600 unmodified linesmodified:src/flask/app.py+1 added
187 unmodified lines188 "SESSION_COOKIE_DOMAIN": None,189 "SESSION_COOKIE_PATH": None,190 "SESSION_COOKIE_HTTPONLY": True,191 "SESSION_COOKIE_SECURE": False,192+ "SESSION_COOKIE_PARTITIONED": False,193 "SESSION_COOKIE_SAMESITE": None,194 "SESSION_REFRESH_EACH_REQUEST": True,195 "MAX_CONTENT_LENGTH": None,196 "MAX_FORM_MEMORY_SIZE": 500_000,1324 unmodified linesmodified:src/flask/sessions.py+11 added
222 unmodified lines223 the :data:`SESSION_COOKIE_SAMESITE` setting.224 """225 return app.config["SESSION_COOKIE_SAMESITE"] # type: ignore[no-any-return]226 227+ def get_cookie_partitioned(self, app: Flask) -> bool:228+ """Returns True if the cookie should be partitioned. By default, uses229+ the value of :data:`SESSION_COOKIE_PARTITIONED`.230+231+ .. versionadded:: 3.1232+ """233+ return app.config["SESSION_COOKIE_PARTITIONED"] # type: ignore[no-any-return]234+235 def get_expiration_time(self, app: Flask, session: SessionMixin) -> datetime | None:236 """A helper method that returns an expiration date for the session237 or ``None`` if the session is linked to the browser session. The238 default implementation returns now + the permanent session106 unmodified lines345 name = self.get_cookie_name(app)346 domain = self.get_cookie_domain(app)347 path = self.get_cookie_path(app)348 secure = self.get_cookie_secure(app)349+ partitioned = self.get_cookie_partitioned(app)350 samesite = self.get_cookie_samesite(app)351 httponly = self.get_cookie_httponly(app)352 353 # Add a "Vary: Cookie" header if the session was accessed at all.8 unmodified lines362 name,363 domain=domain,364 path=path,365 secure=secure,366+ partitioned=partitioned,367 samesite=samesite,368 httponly=httponly,369 )370 response.vary.add("Cookie")12 unmodified lines383 httponly=httponly,384 domain=domain,385 path=path,386 secure=secure,387+ partitioned=partitioned,388 samesite=samesite,389 )390 response.vary.add("Cookie")modified:tests/test_basic.py+3 added
291 unmodified lines292 APPLICATION_ROOT="/test",293 SESSION_COOKIE_DOMAIN=".example.com",294 SESSION_COOKIE_HTTPONLY=False,295 SESSION_COOKIE_SECURE=True,296+ SESSION_COOKIE_PARTITIONED=True,297 SESSION_COOKIE_SAMESITE="Lax",298 SESSION_COOKIE_PATH="/",299 )300 14 unmodified lines315 assert "path=/" in cookie316 assert "secure" in cookie317 assert "httponly" not in cookie318 assert "samesite" in cookie319+ assert "partitioned" in cookie320 321 rv = client.get("/clear", "http://www.example.com:8080/test/")322 cookie = rv.headers["set-cookie"].lower()323 assert "session=;" in cookie1 unmodified line325 assert "domain=example.com" in cookie or "domain=.example.com" in cookie326 assert "path=/" in cookie327 assert "secure" in cookie328 assert "samesite" in cookie329+ assert "partitioned" in cookie330 331 332 def test_session_using_samesite_attribute(app, client):333 @app.route("/")1539 unmodified linesmodified:CHANGES.rst+2 added
13 unmodified lines14 - ``Request.max_content_length`` can be customized per-request instead of only15 through the ``MAX_CONTENT_LENGTH`` config. Added16 ``MAX_FORM_MEMORY_SIZE`` and ``MAX_FORM_PARTS`` config. Added documentation17 about resource limits to the security page. :issue:`5625`18+- Add support for the ``Partitioned`` cookie attribute (CHIPS), with the19+ ``SESSION_COOKIE_PARTITIONED`` config. :issue`5472`20 21 22 Version 3.0.323 -------------1563 unmodified lines