Questions tagged [cookies]

An HTTP cookie is a piece of data stored by the user's web browser. Unless otherwise specified, cookies can be created, read, modified and deleted both by JavaScript and from server-side through HTTP headers.

An HTTP cookie is a piece of data stored by the user's web browser. Unless otherwise specified, cookies can be created, read, modified and deleted both by JavaScript and by server-side through HTTP headers.

Cookies can be used to remember the state of the session, such as authentication, state of GUI controls and personalization through user preferences. They can also be inappropriately used to track the browsing history and to transfer malware.

A server sets a cookie using Set-Cookie HTTP header:

 Set-Cookie: someName=someValue; Expires=Fri, 18-Jan-2013 10:13:13 GMT
 Set-Cookie: someOther=someOtherValue

It is possible to set cookies also on image and similar content that makes them a powerful tracking tool. When cookie is set, it is reported back by the browser:

 Cookie: someName=someValue; someOtherName=someOtherValue

For more security, cookies can be restricted to some domain and path:

 Set-Cookie: name=value; domain=www.foo.com; Path=/hereonly

They can also have additional secure (HTTPS only but accessible through JavaScript) and httponly (HTTP or HTTPS but not accessible through JavaScript) attributes:

 Set-Cookie: goldlocation=somewhere; Domain=.morgan.com; secure; httponly

In this example the cookie is accessible for all subdomains of morgan.com but only through HTTPS and not accessible from JavaScript.

Cookie access control is based on domain, (optionally) path and (optionally) URL scheme (http: vs. https:). The rules governing cookies are not the same as the access control rules of the DOM in JavaScript which are based on the same domain policy, but because cookie access is mostly based on domain name, they are sometimes confused with the usual HTTP same domain policy.

The behaviour of HTTP cookies in real life browsers is not described in any RFC (thus quoting a RFC to describe cookies is almost always wrong). The various RFC are of historical interest.

Browsers are recommended to allow at least 20 cookies per domain and 4KB per cookie. If you are looking for an alternative to cookies that aren't sent in HTTP headers and can store more data, consider

Implementation Hint

For fans, there is a simple plugin make it easy to deal with cookies (write, read and delete) could be found here.


Questions:

34843 questions
10
votes
7 answers

CookieManager for multiple threads

I am trying to make multiple connections via threads. But every connection seems to override the other's cookies, resulting in the connections using the wrong cookies. inside the threaded class's constructor: manager = new CookieManager(); …
Wurstbro
  • 974
  • 1
  • 9
  • 21
10
votes
1 answer

Share a SESSION across multiple servers with different domains

I'm having a little problem. I am developing an application in PHP that is divided into modules. Each module is completely independent, is on a separate server and has an own domain. eg: www.moduloprincipal.com.br, www.modulo2.com.br,…
user875690
  • 227
  • 1
  • 3
  • 8
10
votes
1 answer

Disable anonymous user cookie with Django

I use django auth for my website, which needs to have the session middleware installed. Django session middleware always adds a session cookie, even for anonymous users (users that are not authenticated). When they authenticate the cookie is…
kollo
  • 1,285
  • 3
  • 20
  • 33
10
votes
2 answers

How long does a session cookie last? When should I reauthenticate?

How long can I use a session cookie? I have a client application where I authenticated to a SharePoint site and I am using the cookies for navigating through the subsites. I am saving the cookie and reusing the headers to login to the site at a…
rogerstone
  • 7,541
  • 11
  • 53
  • 62
10
votes
3 answers

Single Sign On (SSO) between Wordpress and CakePHP

I have an existing Wordpress site. The plan is to rebuild the site using the cakePHP framework. Due to time restrictions, I want to replace individual sections of the Wordpress site one at a time. This will mean that both apps will be running side…
emersonthis
  • 32,822
  • 59
  • 210
  • 375
10
votes
4 answers

Getting webbrowser cookies to log in

I am creating an windows forms app, where I have a webbrowser control. After user logs in with the webbrowser, I want to log in also with same account with Microsoft.Http.HttpClient or HttpWebRequest or similar, it should be similar to cURL from…
Jaanus
  • 16,161
  • 49
  • 147
  • 202
10
votes
2 answers

How do I send cookies with request when testing Flask applications through nosetests?

I'm having some trouble sending a cookie with my test request. I've tried something like this: # First request to log in, retrieve cookie from response response = self.app_client.post('/users/login', query_string={ data.. ) cookie =…
moodh
  • 2,661
  • 28
  • 42
10
votes
1 answer

How to remove certain cookies from nginx response

I have nginx set up as a reverse proxy server and I want to remove certain cookies set on the backed server (apache) My website uses a lot of cookies which I can not control (Expression Engine CMS, don't ask me why). I want to delete some of those…
Martin Taleski
  • 6,033
  • 10
  • 40
  • 78
10
votes
2 answers

CORS cookie with domain field is setting only in Firefox using jQuery AJAX

I am not able to set cookie when domain filed is added using cross site request. I am trying to achieve that by calling request through jquery ajax. Is it possible to get it working in other browsers than firefox? Some request…
Mariusz
  • 3,054
  • 2
  • 20
  • 31
10
votes
5 answers

How to read/write cookies for local file:/// HTML document?

How can I read/write cookies for local file:/// HTML document using Javascript or jQuery? I tried this one >> function setCookie(c_name, value, exdays) { var exdate = new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value =…
Ωmega
  • 42,614
  • 34
  • 134
  • 203
10
votes
3 answers

Codeigniter & PHP check if session exist

How can i simply check if cookies are enabled and user session too in PHP? I need the really lighter piece of code of this world to do that, can anyone show me somenthing? I'm on Codeigniter but i'm planning to use native PHP for this control. my…
itsme
  • 48,972
  • 96
  • 224
  • 345
10
votes
1 answer

Compojure/Ring: Why doesn't a session with cookie-store survive a server restart?

I have a compojure app that uses the ring session wrapper to store the OAuth token associated with the current user. I would like for this token to remain available when the server restarts, so that I don't have to go through the auth process each…
jgre
  • 787
  • 5
  • 11
10
votes
2 answers

cURL request on a page requiring JavaScript support

I need to get the HTML source of pinnaclesports.com. The problem is it detects whether cookies and JS are enabled and if not, it just returns some page saying This site requires JavaScript and Cookies to be enabled. Please change your browser…
user965748
  • 2,227
  • 4
  • 22
  • 30
10
votes
2 answers

Apache / PHP Disable Cookies for Subdomain?

I am trying to follow these guidelines to make my page load quicker. I have created a static subdomain to load static content from, however it is advising me to not have cookies sent on this subdomain, any ideas on how I might be able to do this in…
stukerr
  • 716
  • 3
  • 10
  • 18
10
votes
2 answers

Symfony2: setting a cookie

I'm trying to set a cookie within a login controller to achieve "remember me" system. Even though I've used the exact code I found on the web, things for me are going wrong. I hope you can help me figure out what I'm missing. Let's go through the…
Nadjib Mami
  • 5,736
  • 9
  • 37
  • 49