Skip to content
Myr

add SESSION_COOKIE_PARTITIONED config (#5499)

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

authored by David Lord · committed by GitHub · parents 6f2014d, 9efc1eb · 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.

Diff stats

5 files+34 added−0 removed

  • tests:+3 added−0 removed
  • other:+31 added−0 removed

5 files+34 added−0 removed

modified:docs/config.rst+17 added
171 unmodified lines
172 sense.173174 Default: ``False``175176.. py:data:: SESSION_COOKIE_PARTITIONED177178 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.181182 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.185186 Enabling this implicitly enables :data:`SESSION_COOKIE_SECURE` as well, as187 it is only valid when served over HTTPS.188189 Default: ``False``190191 .. versionadded:: 3.1192193.. py:data:: SESSION_COOKIE_SAMESITE194195 Restrict how cookies are sent with requests from external sites. Can196 be set to ``'Lax'`` (recommended) or ``'Strict'``.
600 unmodified lines
modified:src/flask/app.py+1 added
187 unmodified lines
188 "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 lines
modified:src/flask/sessions.py+11 added
222 unmodified lines
223 the :data:`SESSION_COOKIE_SAMESITE` setting.224 """225 return app.config["SESSION_COOKIE_SAMESITE"] # type: ignore[no-any-return]226227 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`.230231 .. versionadded:: 3.1232 """233 return app.config["SESSION_COOKIE_PARTITIONED"] # type: ignore[no-any-return]234235 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 session
106 unmodified lines
345 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)352353 # Add a "Vary: Cookie" header if the session was accessed at all.
8 unmodified lines
362 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 lines
383 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 lines
292 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 lines
315 assert "path=/" in cookie316 assert "secure" in cookie317 assert "httponly" not in cookie318 assert "samesite" in cookie319 assert "partitioned" in cookie320321 rv = client.get("/clear", "http://www.example.com:8080/test/")322 cookie = rv.headers["set-cookie"].lower()323 assert "session=;" in cookie
1 unmodified line
325 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 cookie330331332def test_session_using_samesite_attribute(app, client):333 @app.route("/")
1539 unmodified lines
modified:CHANGES.rst+2 added
13 unmodified lines
14- ``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`202122Version 3.0.323-------------
1563 unmodified lines