DonkBoy Internet
Home of the famous
Information Archives.
"For the curious"
Cookies
Cookie
A small text file which is deposited on your hard drive by a web site you visit. This
file identifies your computer. It records your preferences and other data about your visit
to that site. When you return to the site, the site knows who you are. Cookies can thus be
used for longer term data collection.
Cookie, 3rd Party
These cookies are placed by ad networks and Internet marketing companies, not the site
you are visiting.
Cookies are messages written in your browser. The messages store information so that A site immediately recognizes you each time you visit. This permits them to personalize their site for each member, allow access to the secure parts of our site that individual members have registered for and provide members with up-to-date information about their own account.
Cookies are a general mechanism which server side connections (such as CGI scripts) can use to both store and retrieve information on the client side of the connection. The addition of a simple, persistent, client-side state significantly extends the capabilities of Web-based client/server applications.
A server, when returning an HTTP object to a client, may also send a piece of state information which the client will store. Included in that state object is a description of the range of URLs for which that state is valid. Any future HTTP requests made by the client which fall in that range will include a transmittal of the current value of the state object from the client back to the server. The state object is called a cookie, for no compelling reason.
This simple mechanism provides a powerful new tool which enables a host of new types of applications to be written for web-based environments. Shopping applications can now store information about the currently selected items, for fee services can send back registration information and free the client from retyping a user-id on next connection, sites can store per-user preferences on the client, and have the client supply those preferences every time that site is connected to.
A cookie is introduced to the client by including a Set-Cookie header as part of an HTTP response, typically this will be generated by a CGI script.
This is the format a CGI script would use to add to the HTTP headers a new piece of data which is to be stored by the client for later retrieval.
Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure
This is the only required attribute on the Set-Cookie header.
The date string is formatted as:
Wdy, DD-Mon-YYYY HH:MM:SS GMT
This is based on RFC 822, RFC 850, RFC 1036, and RFC 1123, with the variations that the only legal time zone is GMT and the separators between the elements of the date must be dashes.
expires is an optional attribute. If not specified, the cookie will expire when the user's session ends.
Note: There is a bug in Netscape Navigator version 1.1 and earlier. Only cookies whose path attribute is set explicitly to "/" will be properly saved between sessions if they have an expires attribute.
Only hosts within the specified domain can set a cookie for a domain and domains must have at least two (2) or three (3) periods in them to prevent domains of the form: ".com", ".edu", and "va.us". Any domain that fails within one of the seven special top level domains listed below only require two periods. Any other domain requires at least three. The seven special top level domains are: "COM", "EDU", "NET", "ORG", "GOV", "MIL", and "INT".
The default value of domain is the host name of the server which generated the cookie response.
If the path is not specified, it as assumed to be the same path as the document being described by the header which contains the cookie.
If secure is not specified, a cookie is considered safe to be sent in the clear over unsecured channels.
When requesting a URL from an HTTP server, the browser will match the URL against all cookies and if any of them match, a line containing the name/value pairs of all matching cookies will be included in the HTTP request. Here is the format of that line:
Cookie: NAME1=OPAQUE_STRING1; NAME2=OPAQUE_STRING2 ...
Servers should not expect clients to be able to exceed these limits. When the 300 cookie limit or the 20 cookie per server limit is exceeded, clients should delete the least recently used cookie. When a cookie larger than 4 kilobytes is encountered the cookie should be trimmed to fit, but the name should remain intact as long as it is less than 4 kilobytes.
Similarly, if a client request contains a Cookie: header, it should be forwarded through a proxy, even if the conditional If-modified-since request is being made.
Here are some sample exchanges which are designed to illustrate the use of cookies.
Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT
Cookie: CUSTOMER=WILE_E_COYOTE
Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/
Cookie: CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001
Set-Cookie: SHIPPING=FEDEX; path=/foo
Cookie: CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001
Cookie: CUSTOMER=WILE_E_COYOTE; PART_NUMBER=ROCKET_LAUNCHER_0001; SHIPPING=FEDEX
Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/
Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001
Set-Cookie: PART_NUMBER=RIDING_ROCKET_0023; path=/ammo
Cookie: PART_NUMBER=RIDING_ROCKET_0023; PART_NUMBER=ROCKET_LAUNCHER_0001
"... Using simple Javascript code on a Web page, a Web site can grab the unique ID number of the Windows Media Player belonging to a Web site visitor. This ID number can then be used just like a cookie by Web sites to track a user's travels around the Web."
Web Application Security: "In theory and practice"
http://www.whitehatsec.com/defcon9_pres_html/dc9_pres.txt
Hijacking Session Cookies
http://www.donkboy.com/html/session.htm
Cookie-based Script Execution issue: http://www.microsoft.com/technet/treeview/default.asp?url=/technet/security/bulletin/MS02-015.asp
Additional resourses: Cookie Central by David Whalen @ http://www.cookiecentral.com/faq/#2.6
CIAC Information Bulletin http://ciac.llnl.gov/ciac/bulletins/i-034.shtml
Using Cookies http://wwwultra.scps.nyu.edu/createwww/topics/cookies/
Close a cookie security loophole
http://www.donkboy.com/html/priv1.htm