Skip to content

Commit

Permalink
Security: Make 'token' cookie HTTP-only
Browse files Browse the repository at this point in the history
This prevents malicious JavaScript code injected by a XSS attack from
reading your "Remember me" token, and getting long-term access to your
account.  Note that not all browsers honor :http_only, and of those
that do, some allow it to be bypassed using XmlHttpRequest.
  • Loading branch information
emk committed Dec 11, 2008
1 parent 5186bb4 commit f9d3c10
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion RAILS-2.2-TODO.txt
Expand Up @@ -15,8 +15,8 @@ We need to do a basic security audit.
X Can we restrict admin cookies to /admin ? No--need /accounts, too.
/ Make sure logging out clears all relevant cookies and tokens
/ Check for session fixation attacks
/ Make sure cookies are HTTP-only whenever possible
Expire sessions after a while?
Make sure cookies are HTTP-only whenever possible
Cross-site scripting
/ Turn on protect_against_forgery
Check all fields in comments
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/account_controller.rb
Expand Up @@ -15,7 +15,7 @@ def login
return unless request.post?
self.current_user = User.authenticate_for(site, params[:login], params[:password])
if logged_in?
cookies[:token] = { :value => current_user.reset_token!, :expires => Time.now.utc+2.weeks } if params[:remember_me] == "1"
cookies[:token] = { :value => current_user.reset_token!, :expires => Time.now.utc+2.weeks, :http_only => true } if params[:remember_me] == "1"
return redirect_back_or_default(default_url(self.current_user))
end
flash.now[:error] = "Could not log you in. Are you sure your Login name and Password are correct?"
Expand Down

0 comments on commit f9d3c10

Please sign in to comment.