我已经使用https://github.com/zquestz/omniauth-google-oauth2上给出的示例模式在我的 rails/devise 应用程序中实现了“omniauth-google-oauth2”gem 。但是,我担心这种模式不安全。
我试图查看 git hub 上的源代码,以及https://developers.google.com/identity/sign-in/web/devconsole-project上的官方谷歌文档,但是我无法说服自己模式是安全的。
从谷歌文档,流程应该是这样的:
我的安全问题在于对 request.env 的工作原理没有深入了解。
问题 1:用户可以设置 request.env 值(例如,使用 cURL 请求之类的东西)吗?
问题 2:如果是这样,是什么阻止了恶意用户点击应用程序的omniauth 回调端点并设置 request.env 的值以便他们可以冒充另一个用户?例如,在 github 上显示的示例中,控制器中的回调端点是:
类用户::OmniauthCallbacksController < 设计::OmniauthCallbacksController
def google_oauth2
# You need to implement the method below in your model (e.g. app/models/user.rb) @user = User.from_omniauth(request.env["omniauth.auth"]) if @user.persisted? flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google" sign_in_and_redirect @user, :event => :authentication else session["devise.google_data"] = request.env["omniauth.auth"].except(:extra) #Removing extra as it can overflow some session stores redirect_to new_user_registration_url, alert: @user.errors.full_messages.join("\n") end
结尾
结尾
问题 3:我的 rails 应用程序服务器(我正在使用 puma)似乎没有记录图中第 5 步的请求(交换代码以获取令牌)。我在 Chrome 中无法从用户的角度看到这一点,因为用户没有参与该通信。我怎样才能看到/记录/验证呼叫正在发生?