<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Edoe</id>
		<title>OWASP - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Edoe"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Edoe"/>
		<updated>2026-04-30T08:46:08Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=HttpOnly&amp;diff=41738</id>
		<title>HttpOnly</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=HttpOnly&amp;diff=41738"/>
				<updated>2008-10-01T14:32:33Z</updated>
		
		<summary type="html">&lt;p&gt;Edoe: short PHP chapter&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
The goal of this section is to introduce, discuss, and provide language specific mitigation techniques for HTTPOnly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3 style=color:#4682B4&amp;gt; &amp;lt;u&amp;gt; Who developed HTTPOnly? When? &amp;lt;/u&amp;gt; &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
According to a daily blog article by Jordan Wiens, “No cookie for you!,” HTTPOnly cookies were first implemented in 2002 by Microsoft Internet Explorer developers for Internet Explorer 6 SP1. [http://www.networkcomputing.com/blog/dailyblog/archives/2007/03/no_cookie_for_y.html Wiens],&lt;br /&gt;
[http://www.networkcomputing.com/blog/dailyblog/archives/2007/03/no_cookie_for_y.html]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3 style=color:#4682B4&amp;gt; &amp;lt;u&amp;gt; What is HTTPOnly? &amp;lt;/u&amp;gt; &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
According to the [http://msdn2.microsoft.com/en-us/library/ms533046.aspx 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).&lt;br /&gt;
&lt;br /&gt;
*The example below shows the syntax used within the '''HTTP response header''':&lt;br /&gt;
&lt;br /&gt;
 Set-Cookie: &amp;lt;name&amp;gt;=&amp;lt;value&amp;gt;[; &amp;lt;name&amp;gt;=&amp;lt;value&amp;gt;]&lt;br /&gt;
 [; expires=&amp;lt;date&amp;gt;][; domain=&amp;lt;domain_name&amp;gt;]&lt;br /&gt;
 [; path=&amp;lt;some_path&amp;gt;][; secure][; HTTPOnly]&lt;br /&gt;
&lt;br /&gt;
If the HTTPOnly flag (optional) is included in the HTTP response header, the cookie cannot be accessed through client side script (again if the browser supports this flag). As a result, even if a cross-site scripting '''(XSS)''' flaw exists, and a user accidentally accesses a link that exploits this flaw, the browser (primarily Internet Explorer) will not reveal the cookie to a third party.&lt;br /&gt;
&lt;br /&gt;
If a browser does not support HTTPOnly and a website attempts to set an HTTPOnly cookie, the HTTPOnly flag will be ignored by the browser, thus creating a traditional, script accessible cookie. As a result, the cookie (typically your session cookie) becomes vulnerable to theft of modification by malicious script. [http://msdn2.microsoft.com/en-us/library/ms533046.aspx Mitigating], [http://msdn2.microsoft.com/en-us/library/ms533046.aspx]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3 style=color:#4682B4&amp;gt; &amp;lt;u&amp;gt; Mitigating XSS using HTTPOnly &amp;lt;/u&amp;gt; &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
According to [http://msdn2.microsoft.com/en-us/library/ms972826.aspx Michael Howard], Senior Security Program Manager in the Secure Windows Initiative group at Microsoft, the majority of XSS attacks target theft of session cookies. A server could help mitigate this issue by setting the HTTPOnly flag on a cookie it creates, indicating the cookie should not be accessible on the client.&lt;br /&gt;
&lt;br /&gt;
If a browser that supports HTTPOnly detects a cookie containing the HTTPOnly flag, and client side script code attempts to read the cookie, the browser ''returns an empty string'' as the result. This causes the attack to fail by preventing the malicious (usually XSS) code from sending the data to an attacker's website. [http://msdn2.microsoft.com/en-us/library/ms972826.aspx Howard], [http://msdn2.microsoft.com/en-us/library/ms972826.aspx]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h5 style=color:#2E8B57&amp;gt; &amp;lt;u&amp;gt; Using Java to Set HTTPOnly &amp;lt;/u&amp;gt; &amp;lt;/h5&amp;gt; &lt;br /&gt;
&lt;br /&gt;
*'''Problem'''&lt;br /&gt;
**Most environments (e.g., Java EE) do not provide a mechanism to set the HTTPOnly flag.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
 response.setHeader(&amp;quot;Set-Cookie&amp;quot;, &lt;br /&gt;
                    &amp;quot;originalcookiename=originalvalue; &lt;br /&gt;
                    HTTPOnly=&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
'''Note''': This works OK for custom cookies, but the JSESSIONID is created and handled by the Java EE container, so you really cannot override the framework to add HTTPOnly to JSESSIONID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h5 style=color:#2E8B57&amp;gt; &amp;lt;u&amp;gt; Using .NET to Set HTTPOnly &amp;lt;/u&amp;gt; &amp;lt;/h5&amp;gt; &lt;br /&gt;
&lt;br /&gt;
*By ''default'', '''.NET 2.0''' sets the HTTPOnly attribute for&lt;br /&gt;
*#Session ID&lt;br /&gt;
*#Forms Authentication cookie&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In .NET 2.0, HTTPOnly can also be set via the HttpCookie object for all custom application cookies&lt;br /&gt;
*Via '''web.config''' in the system.web/httpCookies element&lt;br /&gt;
 &amp;lt;httpCookies httpOnlyCookies=&amp;quot;true&amp;quot; …&amp;gt; &lt;br /&gt;
&lt;br /&gt;
*Or '''programmatically'''&lt;br /&gt;
C# Code:&lt;br /&gt;
 HttpCookie myCookie = new HttpCookie(&amp;quot;myCookie&amp;quot;);&lt;br /&gt;
 myCookie.HttpOnly = true;&lt;br /&gt;
 Response.AppendCookie(myCookie);&lt;br /&gt;
&lt;br /&gt;
VB.NET Code:&lt;br /&gt;
 Dim myCookie As HttpCookie = new HttpCookie(&amp;quot;myCookie&amp;quot;)&lt;br /&gt;
 myCookie.HttpOnly = True&lt;br /&gt;
 Response.AppendCookie(myCookie)&lt;br /&gt;
&lt;br /&gt;
*However, in '''.NET 1.1''', you would have to do this ''manually'', e.g.,&lt;br /&gt;
 Response.Cookies[cookie].Path += &amp;quot;;HTTPOnly&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h5 style=color:#2E8B57&amp;gt; &amp;lt;u&amp;gt; Using PHP to set HttpOnly &amp;lt;/u&amp;gt; &amp;lt;/h5&amp;gt; &lt;br /&gt;
PHP supports setting the HttpOnly flag since version 5.2.0 (November 2006).&lt;br /&gt;
&lt;br /&gt;
The flag is set either permanently in php.ini through the parameter:&lt;br /&gt;
 session.cookie_httponly&lt;br /&gt;
or in and during a script via the function:&lt;br /&gt;
 session_set_cookie_params ( .., .., .., .., bool $httponly)&lt;br /&gt;
&lt;br /&gt;
* [http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-httponly PHP manual on ''HttpOnly'']&lt;br /&gt;
&lt;br /&gt;
== Browsers Supporting HTTPOnly ==&lt;br /&gt;
&lt;br /&gt;
Using WebGoat's HTTPOnly lesson, the following web browsers have been tested for HTTPOnly support. If the browsers enforces HTTPOnly, a client side script will be unable to read or write the session cookie. However, there is currently no prevention of reading or writing the session cookie via a XMLHTTPRequest. The results are listed below in '''table 1'''.&lt;br /&gt;
&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; width=&amp;quot;100%&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|+ '''Table 1:''' Browsers Supporting HTTPOnly&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;background:black; color:white&amp;quot; | '''Browser'''&lt;br /&gt;
! style=&amp;quot;background:black; color:white&amp;quot; | '''Version'''&lt;br /&gt;
! style=&amp;quot;background:black; color:white&amp;quot; | '''Prevents Reads'''&lt;br /&gt;
! style=&amp;quot;background:black; color:white&amp;quot; | '''Prevents Writes'''&lt;br /&gt;
! style=&amp;quot;background:black; color:white&amp;quot; | '''Prevents Read within XMLHTTPResponse*'''&lt;br /&gt;
|-&lt;br /&gt;
| Microsoft Internet Explorer&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 8 Beta 2&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
|-&lt;br /&gt;
| Microsoft Internet Explorer&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
|-&lt;br /&gt;
| Microsoft Internet Explorer&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 (SP1)&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
|-&lt;br /&gt;
| Mozilla Firefox&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2.0.0.6&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No (almost yes, see [https://bugzilla.mozilla.org/show_bug.cgi?id=380418#c14])&lt;br /&gt;
|-&lt;br /&gt;
| Netscape Navigator&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 9.0b3&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
|-&lt;br /&gt;
| Opera&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 9.23&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
|-&lt;br /&gt;
| Opera&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 9.50&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
|-&lt;br /&gt;
| Safari&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3.0&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
|-&lt;br /&gt;
| Google's Chrome&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Beta (initial public release)&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | No&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;*&amp;lt;/nowiki&amp;gt; An attacker could still read the session cookie in a response to an '''[http://ha.ckers.org/blog/20070719/firefox-implements-httponly-and-is-vulnerable-to-xmlhttprequest/ XmlHttpRequest]'''.&lt;br /&gt;
&lt;br /&gt;
== Using WebGoat to Test for HTTPOnly Support ==&lt;br /&gt;
&lt;br /&gt;
The goal of this section is to provide a step-by-step example of testing your browser for HTTPOnly support.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3 style=color:#4682B4&amp;gt; &amp;lt;u&amp;gt; Getting Started &amp;lt;/u&amp;gt; &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image:Click_link.JPG|thumb|175px|right|Figure 1 - Accessing WebGoat's HTTPOnly Test Lesson]]&lt;br /&gt;
&lt;br /&gt;
Assuming you have installed and launched WebGoat, begin by navigating to the '''‘HTTPOnly Test’ lesson''' located within the Cross-Site Scripting ('''XSS''') category. After loading the ‘HTTPOnly Test’ lesson, as shown in '''figure 1''', you are now able to begin testing web browsers supporting HTTPOnly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3 style=color:#4682B4&amp;gt; &amp;lt;u&amp;gt; Lesson Goal &amp;lt;/u&amp;gt; &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the ''HTTPOnly flag'' is set, then your browser should not allow a client-side script to access the session cookie. Unfortunately, since the attribute is relatively new, several browsers may neglect to handle the new attribute properly.&lt;br /&gt;
&lt;br /&gt;
The '''purpose''' of this lesson is to test whether your browser supports the '''HTTPOnly cookie flag'''. ''Note the value of the'' '''''unique2u cookie'''''. If your browser supports HTTPOnly, and you ''enable'' it for a cookie, a client-side script should NOT be able to read OR write to that cookie, but the browser can still send its value to the server. However, some browsers only prevent client side read access, but do not prevent write access.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3 style=color:#4682B4&amp;gt; &amp;lt;u&amp;gt; Testing Web Browsers for HTTPOnly Support &amp;lt;/u&amp;gt; &amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following test was performed on two browsers, '''Internet Explorer 7''' and '''Opera 9.22''', to demonstrate the results when the HTTPOnly flag is enforced properly. As you will see, IE7 properly enforces the HTTPOnly flag, whereas Opera does not properly enforce the HTTPOnly flag.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h5 style=color:#2E8B57&amp;gt; &amp;lt;u&amp;gt; Disabling HTTPOnly &amp;lt;/u&amp;gt; &amp;lt;/h5&amp;gt; &lt;br /&gt;
&lt;br /&gt;
 1) Select the option to '''turn HTTPOnly off''' as shown below in '''figure 2'''.&lt;br /&gt;
&lt;br /&gt;
[[Image:Fig2-Disabling_HTTPOnly.PNG|frame|center|Figure 2 - Disabling HTTPOnly]]&lt;br /&gt;
&lt;br /&gt;
 2) After turning HTTPOnly off, select the '''“Read Cookie”''' button. &lt;br /&gt;
*An alert dialog box will display on the screen notifying you that ''since HTTPOnly was not enabled'', the '''‘unique2u’ cookie''' was successfully read as shown below in '''figure 3'''.&lt;br /&gt;
&lt;br /&gt;
[[Image:Fig3-Read_HTTPOnly_Off.PNG|frame|center|Figure 3 - Cookie Successfully Read with HTTPOnly Off]]&lt;br /&gt;
&lt;br /&gt;
 3) With HTTPOnly remaining disabled, select the '''“Write Cookie” ''' button.&lt;br /&gt;
&lt;br /&gt;
*An alert dialog box will display on the screen notifying you that ''since HTTPOnly was not enabled'', the '''‘unique2u’ cookie''' was successfully modified on the client side as shown below in '''figure 4'''.&lt;br /&gt;
&lt;br /&gt;
[[Image:Fig4-Write_HTTPOnly_Off.PNG|frame|center|Figure 4 - Cookie Successfully Written with HTTPOnly Off]]&lt;br /&gt;
&lt;br /&gt;
*As you have seen thus far, '''browsing without HTTPOnly''' on is a potential '''''threat'''''. Next, we will '''enable HTTPOnly''' to demonstrate how this flag protects the cookie. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h5 style=color:#2E8B57&amp;gt; &amp;lt;u&amp;gt; Enabling HTTPOnly &amp;lt;/u&amp;gt; &amp;lt;/h5&amp;gt; &lt;br /&gt;
&lt;br /&gt;
 4) Select the ''radio button'' to enable HTTPOnly as shown below in '''figure 5'''.&lt;br /&gt;
&lt;br /&gt;
[[Image:Fig5-Turning_HTTPOnly_On.PNG|frame|center|Figure 5 - Enabling HTTPOnly]]&lt;br /&gt;
&lt;br /&gt;
 5) After enabling HTTPOnly, select the '''&amp;quot;Read Cookie&amp;quot;''' button.&lt;br /&gt;
&lt;br /&gt;
*If the browser enforces the HTTPOnly flag properly, an alert dialog box will display only the session ID rather than the contents of the '''‘unique2u’ cookie''' as shown below in '''figure 6'''. &lt;br /&gt;
&lt;br /&gt;
[[Image:Fig6-Cookie_Read_Protection.PNG|frame|center|Figure 6 - Enforced Cookie Read Protection]]&lt;br /&gt;
&lt;br /&gt;
*However, if the browser does not enforce the HTTPOnly flag properly, an alert dialog box will display both the '''‘unique2u’ cookie''' and session ID as shown below in '''figure 7'''.&lt;br /&gt;
&lt;br /&gt;
[[Image:Fig7-No_Cookie_Read_Protection.PNG|frame|center|Figure 7 - Unenforced Cookie Read Protection]]&lt;br /&gt;
&lt;br /&gt;
*Finally, we will test if the browser allows '''write access''' to the cookie with HTTPOnly enabled.&lt;br /&gt;
&lt;br /&gt;
 6) Select the '''&amp;quot;Write Cookie&amp;quot;''' button.&lt;br /&gt;
&lt;br /&gt;
*If the browser enforces the HTTPOnly flag properly, client side modification will be unsuccessful in writing to the '''‘unique2u’ cookie''' and an alert dialog box will display only containing the session ID as shown below in '''figure 8'''. &lt;br /&gt;
&lt;br /&gt;
[[Image:Fig6-Cookie_Read_Protection.PNG|frame|center|Figure 8 - Enforced Cookie Write Protection]]&lt;br /&gt;
&lt;br /&gt;
*However, if the browser does not enforce the write protection property of HTTPOnly flag for the '''‘unique2u’ cookie''', the cookie will be successfully modified to ''HACKED'' on the client side as shown below in '''figure 9'''.&lt;br /&gt;
&lt;br /&gt;
[[Image:Fig9-No_Cookie_Write_Protection.PNG|frame|center|Figure 9 - Unenforced Cookie Write Protection]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] Wiens, Jordan. [http://www.networkcomputing.com/blog/dailyblog/archives/2007/03/no_cookie_for_y.html No cookie for you!&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
[2] [http://msdn2.microsoft.com/en-us/library/ms533046.aspx Mitigating Cross-site Scripting with HTTP-Only Cookies]&lt;br /&gt;
&lt;br /&gt;
[3] Howard, Michael. [http://msdn2.microsoft.com/en-us/library/ms972826.aspx Some Bad News and Some Good News]&lt;/div&gt;</summary>
		<author><name>Edoe</name></author>	</entry>

	</feed>