2011-08-22 29 views
0

我有一個簡單的應用程序,但我關心用戶數據的confidencial。 使用這種類型的驗證安全嗎?Rails:使用這種風格的before_filter是否安全

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 

回答

1

我會說過濾器通常是安全的,但我不能擔保您的登錄管理以及如何識別用戶。如果有人設法打破current_user方法,那麼可能會出現一些問題,但是如果驗證代碼來自Devise,Authlogic或維護良好的Gem,那麼您不必擔心。

另外,您也可以考慮使用CanCan來管理您的權限。定義這種情況非常簡單,並且有一箇中央文件用於管理所有權限,以便您可以保持代碼的靈活性。

+0

謝謝!我有來自Railscasts'270的認證方法(http://railscasts.com/episodes/270-authentication-in-rails-3-1)。我希望,這不是一個壞的解決方案:) –

+0

當然,這不是一個不好的解決方案。如果你有興趣,我會建議你看康康。它由Ryan Bates寫的是Railscasts的同一個人。 –

相關問題