简体   繁体   English

Flask 会话过期和 CSRF

[英]Flask session expiration and CSRF

I would like to have a Flask session where the session cookie expires after 2 weeks regardless of activity.我想要一个 Flask 会话,其中会话 cookie 在 2 周后过期,无论活动如何。

I can get this to work without CSRF by setting:通过设置,我可以让它在没有 CSRF 的情况下工作:

SESSION_REFRESH_EACH_REQUEST=False

but this doesn't work when I enable CSRF.但这在我启用 CSRF 时不起作用。

With CSRF, the CSRF token is updated in the session for each request which causes the session expiration to be reset.使用 CSRF,CSRF 令牌会在每个请求的会话中更新,这会导致会话过期被重置。

It seems that the only way to make the session expire after 2 weeks is to do it yourself (eg, store the login date in the session or user database and deleting the session when the login date is more than 2 weeks old).似乎使会话在 2 周后过期的唯一方法是自己做(例如,将登录日期存储在会话或用户数据库中,并在登录日期超过 2 周时删除会话)。

This seems like a common requirement so just curious if I am missing something?这似乎是一个常见的要求,所以只是好奇我是否遗漏了什么?

唯一的方法是将日期存储在某处,然后每天检查自存储日期以来是否已经 >= 2 周

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM