Flask –具有相同名称的多个会话Cookie [英] Flask – multiple session cookies with the same name

查看:58
本文介绍了Flask –具有相同名称的多个会话Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Flask应用程序中发现了一个非常奇怪的问题.我发现在某些情况下可以使用相同的名称创建多个会话cookie.我附上一张有关它的图片.它不是特定于浏览器的.

I have found a very strange problem in my Flask application. I discovered that in some circumstances multiple session cookies could be created with the same name. I attached a picture about it. It is not browser specific.

这本身很奇怪,但是当我尝试使用 CSRF验证表单时,真正的问题来了令牌.不幸的是,Flask选择了错误的会话cookie,并且CSRF令牌的验证无法成功.甚至更奇怪的是,即使提交了多个表单,问题仍然存在.唯一的解决方案是删除cookie,这不是普通用户的选择.

It is strange itself, but the real problem comes when I try to validate a form with CSRF token. Unfortunately, Flask picks a wrong session cookie and the validation of the CSRF token cannot be successful. And even more strangely the problem persists even after multiple form submits. The only solution is deleting the cookies which is not an option for an average user.

是否有阻止Flask创建具有相同名称的cookie的选项?还是至少有一个选项可以从我的应用程序中获取所有cookie的名称?在这种情况下,至少我可以删除具有相同名称的会话cookie.

Are there any options to prevent Flask to create cookies with the same name? Or at least is there an option for get all cookie names from my application? In this case at least I would able to delete session cookies with the same name.

推荐答案

没有代码,很难说出Flask在哪里生成多个同名的cookie,但是有可能让cookie寿命很长,请参阅烧瓶:如何删除Cookie?以解决此问题.

Without code, it is hard to tell where Flask generates multiple cookies with the same name, but it is possible that you let the cookie live to long, please see Flask: How to remove cookies? to deal with this issue.

如果我对您的理解正确,则另一个主要问题是[我的评论]:

If I understand you correctly, another main issue is [comment by me]:

Flask选择了错误的会话cookie(具有相同名称的多个会话cookie)

Flask picks a wrong session cookie [of multiple ones with the same name]

从多个具有相同名称的Cookie中选择错误的Cookie并非特定于Flask,而是有关客户端/浏览器使用的逻辑的信息,请参见例如如何处理多个具有相同名称的cookie?

Picking the wrong cookie from multiple ones with the same name is not Flask-specific, but rather about the logic used by client/ browser, see e.g. How to handle multiple cookies with the same name?

这篇关于Flask –具有相同名称的多个会话Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆