因为前端 axios 请求 Rails api 登录时(登录标识使用 cookie),响应头提示 This Set-Cookie was blocked because it had the "SameSite=Lax" attribute but come from a cross-site response whith was not the response to a top-level navigation
。
google 得出的结论是要把 "SameSite=Lax" 改为 "SameSite=None" ,但是我试了几个方法都不管用:
在 config/application.rb
里边添加一行 config.action_dispatch.cookies_same_site_protection = :none
,结果无效
在 config/initializers/session_store.rb
里边设置 same_site: :none
结果运行时报错,提示
ArgumentError (Invalid SameSite value: :none):
rack (2.0.8) lib/rack/utils.rb:260:in `add_cookie_to_header'
actionpack (6.0.1) lib/action_dispatch/middleware/cookies.rb:439:in `block in make_set_cookie_header'
actionpack (6.0.1) lib/action_dispatch/middleware/cookies.rb:437:in `each'
actionpack (6.0.1) lib/action_dispatch/middleware/cookies.rb:437:in `inject'
actionpack (6.0.1) lib/action_dispatch/middleware/cookies.rb:437:in `make_set_cookie_header'
actionpack (6.0.1) lib/action_dispatch/middleware/cookies.rb:423:in `write'
actionpack (6.0.1) lib/action_dispatch/middleware/cookies.rb:653:in `call'
想请教下应该怎样设置 Same-Site
登录的 api 是用 grape api
写的,rails
使用 docker 部署,使用 nginx 做转发,session_store 使用的是 cache_store,但是我改为 cookie_store 也没有用
环境: