开发者

Rails: is it safe to use this style of before_filter

I have simple app, but I'm caring about confidencial of users data. Is it safe 开发者_StackOverflow中文版to use this type of verifying?

before_filter :authenticate, :only => [:show, :edit, :update]
before_filter :correct_user, :only => [:show, :edit, :update]

def authenticate
  redirect_to(root_path) unless !current_user.nil?
end
def correct_user
  redirect_to(root_path) unless current_user == User.find(params[:id])
end


I would say that the filters are generally safe but I cant vouch for your login management and how you identify users. If someone manages to break the current_user method then there could be some issues, however if the authentication code is from Devise, Authlogic or a well maintained gem then you shouldn't have to worry about it.

Also you may want to look into managing your permissions with CanCan. Defining cases like this is easy and there is a central file that is used to manage all the permissions so you can keep your code flexible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜