Skip to content
Myr

mention that session signature checks max age

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

add expiration to cookie security docs closes #2422

authored by David Lord · committed by David Lord · parent ed1f604 · Browse files · 2 files+36 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+36 added−4 removed

  • other:+36 added−4 removed

2 files+36 added−4 removed

modified:docs/config.rst+6 added-3 removed
165 unmodified lines
166 Default: ``False``167168.. py:data:: PERMANENT_SESSION_LIFETIME169170 If ``session.permanent`` is true, the cookie's max age will be set to this171 number of seconds. Can either be a :class:`datetime.timedelta` or an172 ``int``.170 If ``session.permanent`` is true, the cookie's expiration will be set this171 number of seconds in the future. Can either be a172 :class:`datetime.timedelta` or an ``int``.173174 Flask's default cookie implementation validates that the cryptographic175 signature is not older than this value.176177 Default: ``timedelta(days=31)`` (``2678400`` seconds)178179.. py:data:: SESSION_REFRESH_EACH_REQUEST180
411 unmodified lines
modified:docs/security.rst+30 added-1 removed
204 unmodified lines
205 )206207 response.set_cookie('username', 'flask', secure=True, httponly=True)208209- https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies209Specifying ``Expires`` or ``Max-Age`` options, will remove the cookie after210the given time, or the current time plus the age, respectively. If neither211option is set, the cookie will be removed when the browser is closed. ::212213 # cookie expires after 10 minutes214 response.set_cookie('snakes', '3', max_age=600)215216For the session cookie, if ``session.permanent`` is set, then217:data:`SESSION_COOKIE_LIFETIME` is used to set the expiration. Flask's default218cookie implementation validates that the cryptographic signature is not older219than this value. Lowering this value may help mitigate replay attacks, where220intercepted cookies can be sent at a later time.221222 app.config.update(223 PERMANENT_SESSION_LIFETIME=600224 )225226 @app.route('/login', methods=['POST'])227 def login():228 ...229 session.clear()230 session['user_id'] = user.id231 session.permanent = True232 ...233234Use :class:`TimedSerializer` to sign and validate other cookie values (or any235values that need secure signatures).236237- https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies238- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie239240HTTP Public Key Pinning (HPKP)241~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~242243This tells the browser to authenticate with the server using only the specific
7 unmodified lines