Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSRF cookie 没有设置secure=true #2721

Closed
innoyinghe opened this issue Jun 22, 2018 · 10 comments
Closed

CSRF cookie 没有设置secure=true #2721

innoyinghe opened this issue Jun 22, 2018 · 10 comments

Comments

@innoyinghe
Copy link

innoyinghe commented Jun 22, 2018

https 模式下,CSRF cookie 没有设置secure=true

  • Node Version: v8.9
  • Egg Version: 2.2.1
  • Plugin Name:
  • Plugin Version:
  • Platform: redhat openshit
  • Mini Showcase Repository:
@egg-bot
Copy link

egg-bot commented Jun 22, 2018

Translation of this issue:


CSRF cookie is not set to secure=true

CSRF cookie is not set to secure=true in https mode

  • Node Version:
  • Egg Version:
  • Plugin Name:
  • Plugin Version:
  • Platform:
  • Mini Showcase Repository:

@egg-bot
Copy link

egg-bot commented Jun 22, 2018

Hello @innoyinghe. Please provide a reproducible example by creating a github repo.

Issues labeled by Need Reproduce will be closed if no activities in 7 days.

@BaffinLee
Copy link
Contributor

egg-security 设置 CSRF token 时看起来确实没有指定 secure 参数

https://github.com/eggjs/egg-security/blob/bef87dc8930f3ae9deb2583a368798916f5f7ba6/app/extend/context.js#L98-L104

这样的话,secure 参数取决于默认值

koacookies 使用 cookies 库实现

所以 secure 参数的默认逻辑如下:

image

@CHEN-DONG
Copy link

@BaffinLee 那在egg里 怎么配置koa 的 cookies的参数呢

@whxaxes
Copy link
Member

whxaxes commented Jun 25, 2018

@CHEN-DONG csrf 是使用 koa 的 cookies 模块设置的,secure 是自动根据当前协议是否 https 来做设置的,目前不支持配置 csrf 的 secure 配置。

@innoyinghe
Copy link
Author

目前很多项目都是基于云的,https都是在F5或者nginx上面配置的,这种情况koa无法直接根据https来判断。我需要设置app.proxy=true ?

@dead-horse
Copy link
Member

@whxaxes
Copy link
Member

whxaxes commented Jun 25, 2018

你在 nginx 上配置一下 X-Forwarded-Proto 就行了,会自动将协议信息传给应用的

@BaffinLee
Copy link
Contributor

@CHEN-DONG 你是用 nginx 代理的话,在配置里加一个 proxy_set_header X-Forwarded-Proto $scheme;

@innoyinghe
Copy link
Author

我配置完 proxy=true , 目前可以用了。非常感谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants