@@ -206,7 +206,36 @@ They can be set on other cookies too.
206206
207207 response.set_cookie('username', 'flask', secure=True, httponly=True)
208208
209- - https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies
209+ Specifying ``Expires `` or ``Max-Age `` options, will remove the cookie after
210+ the given time, or the current time plus the age, respectively. If neither
211+ option is set, the cookie will be removed when the browser is closed. ::
212+
213+ # cookie expires after 10 minutes
214+ response.set_cookie('snakes', '3', max_age=600)
215+
216+ For the session cookie, if ``session.permanent `` is set, then
217+ :data: `SESSION_COOKIE_LIFETIME ` is used to set the expiration. Flask's default
218+ cookie implementation validates that the cryptographic signature is not older
219+ than this value. Lowering this value may help mitigate replay attacks, where
220+ intercepted cookies can be sent at a later time.
221+
222+ app.config.update(
223+ PERMANENT_SESSION_LIFETIME=600
224+ )
225+
226+ @app.route('/login', methods=['POST'])
227+ def login():
228+ ...
229+ session.clear()
230+ session['user_id'] = user.id
231+ session.permanent = True
232+ ...
233+
234+ Use :class: `TimedSerializer ` to sign and validate other cookie values (or any
235+ values that need secure signatures).
236+
237+ - https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
238+ - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
210239
211240HTTP Public Key Pinning (HPKP)
212241~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments