Rails Gem 'omniauth-google-oauth2' 安全吗/request.env 是如何工作的?
Is The Rails Gem 'omniauth-google-oauth2' Secure / How Does request.env work?
我已经使用 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 上的官方 google 文档,但是我无法说服自己这种模式是安全的.
根据 google 文档,流程应该如下所示:
我的安全问题在于对 request.env 的工作原理没有很好的理解。
问题 1:用户可以设置 request.env 值(例如,使用 cURL 请求之类的东西)吗?
问题 2:如果是这样,是什么阻止恶意用户访问应用程序的 omniauth 回调端点并设置 request.env 的值以便他们可以冒充另一个用户?例如,在 github 上显示的示例中,控制器中的回调端点是:
class Users::OmniauthCallbacksController < Devise::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
end
end
问题 3:我的 rails 应用服务器(我使用的是 puma)似乎没有记录图中第 5 步的请求(交换令牌代码)。在 Chrome 中,我无法从用户的角度看到这一点,因为用户未参与该通信。我怎样才能 see/log/verify 通话正在进行中?
Question 1: Can a user set request.env values (for example, with
something like cURL requests)?
是的。 request.env
包含一堆东西,比如传入的 headers 和参数。但是用户不能将 request.env['omniauth.auth']
设置为它填充了服务器端请求提供者获取的值。
使用 env
和 request.env
传递值是从 Rack 中间件向下传递数据的一种非常标准的方式。这不是一个巨大的安全漏洞,因为用户输入仅限于参数和 headers.
Question 2: If so, what is stopping a malicious user from hitting an
app's omniauth callback endpoint and setting the values of request.env
so they can impersonate another user?
从用户那里接受的唯一输入是访问令牌、id 令牌和一次性代码。获取这些需要暴力攻击(对提供者)或中间人攻击。
Question 3: My rails app server (I'm using puma) doesn't seem to be
logging the request from step 5 in the diagram (exchanging code for
token). I can't see that from the user's perspective in Chrome because
the user isn't involved in that communication. How can I
see/log/verify that call is taking place?
日志中没有任何内容,因为调用是从您的 rails 服务器向提供商发出的。您可以使用 httplog 之类的工具进行调试,但实际上您应该进行涵盖 Omniauth 策略这些方面的测试。
我已经使用 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 上的官方 google 文档,但是我无法说服自己这种模式是安全的.
根据 google 文档,流程应该如下所示:
我的安全问题在于对 request.env 的工作原理没有很好的理解。
问题 1:用户可以设置 request.env 值(例如,使用 cURL 请求之类的东西)吗?
问题 2:如果是这样,是什么阻止恶意用户访问应用程序的 omniauth 回调端点并设置 request.env 的值以便他们可以冒充另一个用户?例如,在 github 上显示的示例中,控制器中的回调端点是:
class Users::OmniauthCallbacksController < Devise::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
end
end
问题 3:我的 rails 应用服务器(我使用的是 puma)似乎没有记录图中第 5 步的请求(交换令牌代码)。在 Chrome 中,我无法从用户的角度看到这一点,因为用户未参与该通信。我怎样才能 see/log/verify 通话正在进行中?
Question 1: Can a user set request.env values (for example, with something like cURL requests)?
是的。 request.env
包含一堆东西,比如传入的 headers 和参数。但是用户不能将 request.env['omniauth.auth']
设置为它填充了服务器端请求提供者获取的值。
使用 env
和 request.env
传递值是从 Rack 中间件向下传递数据的一种非常标准的方式。这不是一个巨大的安全漏洞,因为用户输入仅限于参数和 headers.
Question 2: If so, what is stopping a malicious user from hitting an app's omniauth callback endpoint and setting the values of request.env so they can impersonate another user?
从用户那里接受的唯一输入是访问令牌、id 令牌和一次性代码。获取这些需要暴力攻击(对提供者)或中间人攻击。
Question 3: My rails app server (I'm using puma) doesn't seem to be logging the request from step 5 in the diagram (exchanging code for token). I can't see that from the user's perspective in Chrome because the user isn't involved in that communication. How can I see/log/verify that call is taking place?
日志中没有任何内容,因为调用是从您的 rails 服务器向提供商发出的。您可以使用 httplog 之类的工具进行调试,但实际上您应该进行涵盖 Omniauth 策略这些方面的测试。