检测到csrf攻击:Omniauth和Google的“检测到 CSRF”

关于检测到csrf攻击的问题,在could not authenticate you from googleoauth2 because csrf de中经常遇到, 我得到这个

我得到这个

OmniAuth::Strategies::OAuth2::CallbackError at / auth / google / callback csrf_detected | 检测到 CSRF

我的代码:

require 'sinatra'
require "sinatra/json"
require "sinatra/config_file"
require 'omniauth-oauth2'
require 'omniauth-google-oauth2'
use Rack::Logger
config_file "config/app_config.yml"
use Rack::Session::Cookie, secret: '5fb7w345y3489f523y4h'
configure do
  enable :sessions
end
use OmniAuth::Builder do
  provider :google_oauth2, settings.google[:client_id], settings.google[:secret],
    {
      :scope => "userinfo.profile",
      :access_type => "offline",
      :prompt => "select_account consent",
      :name => "google"
    }
end
get '/list' do
  json get_list
end
get '/' do
  %Q|<a href='/auth/google'>Sign in with Google</a>|
end
get '/auth/:name/callback' do
  @auth = request.env['omniauth.auth']
  @auth.inspect
end

我的回调返回代码和状态。

11

/config/initializer/session_store.rb中定义的域与 google api 控制台中定义的 origin / redirect_uri 不同时,rails 会出现此问题。

MyApp::Application.config.session_store :cookie_store, key: '_app_session', domain: 'my_app.com'

删除域参数或在两侧使用相同的域修复了问题。

10

得到了同样的问题

(google_oauth2) 回调阶段已启动。
(google_oauth2) 身份验证失败!检测到 csrf:OmniAuth::Strategies::OAuth2::CallbackError,csrf_detected | 检测到 CSRF

上次 Omniauth-oauth2 更新引入了“状态”param 有一个必填字段。

有些人建议使用 provider_ignores_state:true,但这是一个坏主意,因为它引入了 csrf 缺陷

猜猜我们将不得不降级到以前的版本,以保持 google_oauth2 工作。

https://github.com/intridea/omniauth-oauth2/issues/58上发出

10

如果您使用的是设计与 OmniAuth,你需要跳过额外的 omniauth.rb 初始化文件,只需添加 config.provider“关键”,“秘密”在你的初始化 / devise.rb,然后继续与您的实现。

0

您是否正在回击并重新尝试登录?我遇到了这个问题,这真的让我感到困惑,但这是因为我要回去重试。如果我再次输入地址,我不会得到这个问题

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(918)
网页office:如何在网页上集成MSOffice365Word文本编辑器
上一篇
Idc机房服务器机柜:IDC是什么意思(idm stands for)
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(72条)