随机问题,但任何人都可以破解并在浏览器中为网站创建 session cookie 吗?
我问的原因是,我目前正致力于在 Rails 中创建回调。我的回调正在检查是否
before_action :employee_logged_in? [:edit, :update]
...
Private
def employee_logged_in?
if session[:current_employee_id].nil?
flash[:danger] = "Employee needs to be logged in"
redirect_to login_path
end
end
因此,如果有人能够创建 session cookie 并将其放置在浏览器上,那么从技术上讲,他们可以访问任何受限页面(在本例中为编辑和更新路由)
这是安全的还是我应该将 session cookie 存储在数据库中并针对数据库检查特定 session cookie?
最佳答案
cookie 存储使用摘要来防止篡改。如果用户更改了 current_employee_id
,则服务器将知道 session 已被编辑并且不会使用它。
来自 Ruby on Rails Security Guide
To prevent session hash tampering, a digest is calculated from the session with a server-side secret and inserted into the end of the cookie.
关于ruby-on-rails - 有人能够破解并创建 Rails session cookie 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36095329/