将CloudFlare用作代理可以防止cookie存储在浏览器中

发布于 2025-01-22 21:41:49 字数 989 浏览 3 评论 0原文

我将附加图像以说明我想做的事情:

”在此处输入图像说明“

注意:上图应“重定向到https”

序言,以下是技术堆栈

  • dns:Godaddy
  • 代理:Cloudflare
  • 客户端:Heroku Server上托管的React应用:Heroku
  • Server:Blask API在Heroku上托管在Heroku上,

至少至少流向我的理解是:

  1. 用户进入domain.com在浏览器中,godaddy将所有流量转发到Cloudflare,以便将网站牢固地查看,
  2. 然后将Cloudflare牢固地转发,然后将流量转发到
  3. 一旦加载客户端,加载客户端,它向服务器请求接收CSRF令牌。 CSRF令牌是由flask-wtf中的方法生成的。在服务器和响应中创建了一个会话,CSRF令牌附加到标题

这里,这里有奇怪的

因为客户在客户端接收到的响应从未有过CSRF令牌我想在浏览器上设置了浏览器,并在浏览器上设置了cookie,我认为响应会在响应击中客户端之前对Cloudflare进行。结果,CSRF令牌从未收到。不知道为什么是这种情况。但是经过一些研究,我发现Cloudflare默认情况下会这样做。

似乎要使用Cloudflare工人,但这似乎只有在使用其DNS时才可用。理想情况下,我想坚持Godaddy。

我想知道是否有人会经历过这种情况并找到了不同的解决方案。

I'll attach an image to illustrate what I'm looking to do:

enter image description here

Note: The above photo should say "Redirect to HTTPS"

To preface, this is the following is the technology stack

  • DNS: GoDaddy
  • Proxy: Cloudflare
  • Client: React app hosted on Heroku
  • Server: Flask API hosted on Heroku

The flow at least to my understanding is this:

  1. User enters in domain.com in browser and GoDaddy forwards all traffic to Cloudflare so that the site is viewed securely
  2. Cloudflare then forwards the traffic to where the client is hosted
  3. Once client is loaded, it makes a request to the server to receive a CSRF token. The CSRF token is generated by a method within flask-wtf. A session is created in the server and in the response, the CSRF token is attached to the header

Here things gets weird

Since the response received on the client never had the CSRF token attached to the header and no cookie was set on the browser, I would assume that the response goes to Cloudflare before the response hits the client. As a result, the CSRF token is never received. Not sure why this is the case.. But after a bit of research, I've discovered that Cloudflare does this by default.

It seems that a work around would be to use Cloudflare Workers, but that seems only available if their DNS is being used. Ideally, I would like to stick with GoDaddy.

I was wondering if anyone else experienced this and found a different solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文