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
9
votes
3 answers

Storing an encrypted cookie with Rails

I need to store a small piece of data (less than 10 characters) in a cookie in Rails and I need it to be secure. I don't want anybody being able to read that piece of data or injecting their own piece of data (as that would open up the app to many…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
9
votes
2 answers

asp.net secure cookies

I want to secure my cookies, i read about "HTTPOnly" and "Secure" cookie flags for the ASP.NET_SessionId cookie. I create new asp.net project in VS. And in fiddler in Inspectors -> raw i have: Cookie: DXCurrentThemeMVC=Office2010Black;…
Andriy Khrystyanovich
  • 1,422
  • 3
  • 19
  • 38
9
votes
1 answer

Cross subdomain cookie handling for session?

Is it possible to set an auth cookie that would be valid on: sub1.domain.com sub2.domain.com Or will each subdomain always require it's own cookie?
cjm2671
  • 18,348
  • 31
  • 102
  • 161
9
votes
1 answer

How to login with cURL with POST and Cookie

The server successfully receives login, password and CAPTCHA. How do I do it with a cookie? I don't know what info is needed for help i'll show all: Login Form:
Tedy
  • 107
  • 1
  • 1
  • 8
9
votes
1 answer

Adding cookies to drag and drop

I'm creating an drag and drop plugin and I thought to make it a little unique i would add a cookies feature to save the position of the dragged elements. I'm currently using the following code for the get and set cookies: $.setCookie =…
Shawn31313
  • 5,978
  • 4
  • 38
  • 80
9
votes
3 answers

How to prevent session timeout

I know this is probably an easy question for most of you guys. But my problem is that my server host empty their session pools every minute. So how do I get my users to stay logged in longer than one minute? I've heard that I could use…
Michael Tot Korsgaard
  • 3,892
  • 11
  • 53
  • 89
9
votes
2 answers

FormsAuthentication.SignOut Not Working With Custom-Domain Cookie

Title should say it all. Here's the code to set the cookie: // snip - some other code to create custom ticket var httpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encodedTicket); httpCookie.Domain =…
RPM1984
  • 72,246
  • 58
  • 225
  • 350
9
votes
5 answers

Safari 5.1 cookie format specs

the way of storing cookie for SAFARI has changed whith SAFARI 5.1 and that they add a kind of integrity control code in the last 8 bytes of the file : The file is %APPDATA%\Apple Computer\Safari\Cookies\Cookies.binarycookies Does anybody know what s…
user382591
  • 1,320
  • 5
  • 19
  • 39
9
votes
1 answer

Default session expiration timeout?

By default the JSESSIONID cookie is expired when you close the browser, but how long is the associated HttpSession really valid on the server side?
Misak
  • 125
  • 1
  • 1
  • 6
9
votes
3 answers

Does HttpGet handle cookies automatically?

I would like to preserve a session while connecting to server using HttpGet and I need to understand how it handles cookies. The server developer says that he handles all cookies stuff by himself. I use HttpGet request to access the server as…
Asaf Pinhassi
  • 15,177
  • 12
  • 106
  • 130
9
votes
1 answer

How to set cookie in Jersey?

I am using jersey jax-rs in myeclipse as backend of my project and jsp as frontend. I want to set cookie from server after successful login. In the jersey's official document, I can only find how to get cookie by jersey. Does anyone can give me a…
mons
  • 138
  • 1
  • 2
  • 6
9
votes
1 answer

Sending POST request with username and password and save session cookie

How can I save cookies with Jsoup after sending a POST request with username and password? Or must I first provide them to connection object and then save?
Jevgeni Smirnov
  • 3,787
  • 5
  • 33
  • 50
9
votes
1 answer

Is it possible to share a cookie between a domain and a subsubdomain

I'm trying to share a cookie between www.example.com and admin.other.example.com I've being able to make it work with other.example.com, but there's no way to access the sub-sub-domain Edit: I handle subdomains by defining the cookie domain as…
Maurizio Pozzobon
  • 3,044
  • 7
  • 34
  • 44
9
votes
4 answers

Delete cookie on clicking sign out

I am creating the cookie using the code below, How to read the txtusername value in another page and how to delete the cookie when I click sign out(code for sign out). I am new to programming please help. string cookiestr; HttpCookie…
rookie
  • 401
  • 3
  • 13
  • 29
9
votes
1 answer

How to implement cookie authentication | SvelteKit & MongoDB

The question stands as-is - how to implement cookie authentication in a SvelteKit & MongoDB app? Meaning how to properly use hooks, endpoints, establish a DB connection and show it on a boilerplate-ish project.
1 2 3
99
100