![]() |
CookieSecurity |
| Introduction |
1. Why cookies are necessaryHTTP is a stateless protocol to transmit data in a computer network. It is mainly used to communicate between a server and a client in the WWW. As the protocol is stateless, it's not possible for the server to associate the different requests of a client. Often there is a demand on assigning data to a specified user for a defined period of time. For example there is a need to save the specific behaviour of a user over a defined period of time or to save different products in a virtual shopping cart in an internet shop application. Because the HTTP protocol is not able to fulfil these requirements in 1994 Netscape invented a mechanism called cookie. Later this mechanism was defined in RFC 2109 and updated in RFC 2965. 2. The CookieA cookie is a small piece of data which is stored on the user's local hard drive by the browser. Either each cookie is saved in a single text file or all cookies are saved in a list in one text file. All common browsers support cookies and most of them offer the option to deactivate them. From the time when a cookie is set from a web server it will continuously be a part of the http Request header for the given lifetime of the cookie. The cookie will only be sent back to the server which had set it. Therefore the domain and the path the cookie is valid for are stored inside the cookie. There are two different kinds of cookies:
Persistent cookies can be stored up to a year on the local hard drive. They are used to configure web applications or to realize a permanent login. The lifetime of a persistent cookie has to be set by the developer. Session cookies are only valid for one session that means from the first visit of a website until the website is closed. After closing the browser window a session cookie is deleted and not valid any more. 3. From a technical point of viewThe web server sets a cookie when the web application instructs it. The data concerning the cookie are sent via the HTTP response header. In the HTTP header two different keywords indicate that a cookie has to be stored by the browser, Set-Cookie (RFC 2109) and Set-Cookie2 (RFC 2965). Actually the MS Internet Explorer 6.0 and Mozilla Firefox 1.5 still use the Set-Cookie keyword from RFC 2109 because the new specification does not provide any fundamental changes. Also the cookie class from the java servlet class javax.servlet.http.Cookie uses the old specification. Excerpt from a HTTP header for setting a persistant cookie: HTTP/1.x 302 Moved Temporarily In the following table you can find all parameters of the Set-Cookie and Set-Cookie2 command:
The domain, path and port attributes are always set. If the developer does not specify the values, the browser automatically writes the attributes in the cookie. Because not every cookie should be sent to every requested web server there is a validation mechanism. A cookie is sent back to a web server when certain circumstances occur:
The cookie in a HTTP header will be identified by the keyword Cookie. Excerpt from a HTTP request header: Cookie: user=login=true;
JSESSIONID=BD33790B59FA3E64DD01A5193D0C3CA2 Further information concerning the technical details of cookies can be found in the RFCs. 4. When are cookies neededFor example cookies are needed to:
|
| < Back to startpage | Next page > |