我们在 Rails 3.2.13 应用程序中使用omniauth 和facebook 登录。它在 session_controller 中有相当标准的样板代码来管理用户会话。它使用 CookieStore 进行会话。这是会话控制器:
class SessionsController < ApplicationController
skip_authorization_check
def new
redirect_to '/auth/facebook'
end
def create
auth = request.env["omniauth.auth"]
user = User.where(:provider => auth['provider'],
:uid => auth['uid'].to_s).first || User.create_with_omniauth(auth)
# Reset the session after successful login, per
# 2.8 Session Fixation – Countermeasures:
# http://guides.rubyonrails.org/security.html#session-fixation-countermeasures
reset_session
session[:user_id] = user.id
user.add_role :admin if User.count == 1 # make the first user an admin
if user.email.blank?
redirect_to edit_user_path(user), :alert => "Please enter your email address."
else
redirect_to root_url, :notice => 'Signed in!'
end
end
def destroy
reset_session
redirect_to root_url, :notice => 'Signed out!'
end
def failure
redirect_to root_url, :alert => "Authentication error: #{params[:message].humanize}"
end
end
前几天,我们团队的一名成员正在测试我们的生产版本并去登录应用程序。当她浏览到该应用程序时,她发现她已经以另一个从未使用过该计算机或实际上从未进入过我们大楼的用户身份登录。根据她的经历和我们随后的分析,该应用似乎为她提供了该用户的会话 cookie。经过大量研究,我不明白这是怎么发生的,即 rack/rails 框架可能会将会话 cookie 提供给错误的用户。有没有人见过或听说过这种情况?关于如何调试或在何处放置日志以更深入地了解可能出现的问题的任何建议?