Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the HttpOnly flag on a cookie in Ruby on Rails

The page Protecting Your Cookies: HttpOnly explains why making HttpOnly cookies is a good idea.

How do I set this property in Ruby on Rails?

like image 849
Laurie Young Avatar asked Sep 16 '08 13:09

Laurie Young


People also ask

How do I set HttpOnly for cookies?

Set HttpOnly cookie in PHPini_set("session. cookie_httponly", True); This is the most common way to set cookies in PHP, empty variables will hold their default value.

What is HttpOnly flag in cookie?

What is HttpOnly? According to the Microsoft Developer Network, HttpOnly is an additional flag included in a Set-Cookie HTTP response header. Using the HttpOnly flag when generating a cookie helps mitigate the risk of client side script accessing the protected cookie (if the browser supports it).

Can you modify HttpOnly cookie?

I've been told that putting httpOnly:true on the cookie prevents the browser from editing cookies, but I can still edit it on my local server. A HTTP only cookie prevents JavaScript from modifying cookies, not the browser.


1 Answers

Set the 'http_only' option in the hash used to set a cookie

e.g.

cookies["user_name"] = { :value => "david", :httponly => true }

or, in Rails 2:

e.g.

cookies["user_name"] = { :value => "david", :http_only => true }
like image 187
Laurie Young Avatar answered Sep 23 '22 23:09

Laurie Young