Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How client know which cookies should be send to the server

When I go to the HTTPS server, I can see in Developer tools (or in Fiddler) a request cookies that are send to the server by client. But how client know, which cookies should be sent, if no response cookies are sent by server. At least I can´t see any response cookies in Developer tools or Fiddler.

like image 674
kores59 Avatar asked Apr 07 '18 12:04

kores59


People also ask

How does browser know which cookies to send?

The web server — which stores the website's data — sends a short stream of identifying info to your web browser. Browser cookies are identified and read by “name-value” pairs. These tell cookies where to be sent and what data to recall. The server only sends the cookie when it wants the web browser to save it.

How does client send cookie to the server?

Cookies are set using the Set-Cookie header field, sent in an HTTP response from the web server. This header field instructs the web browser to store the cookie and send it back in future requests to the server (the browser will ignore this header field if it does not support cookies or has disabled cookies).

Are cookies set from server-side or client-side?

Cookies are client-side files that are stored on a local computer and contain user information. Sessions are server-side files that store user information. Cookies expire after the user specified lifetime. The session ends when the user closes the browser or logs out of the program.

Are all cookies sent with every request?

Cookies are sent with every request, so they can worsen performance (especially for mobile data connections). Modern APIs for client storage are the Web Storage API ( localStorage and sessionStorage ) and IndexedDB.


1 Answers

First up each domain has its own cookies in a cookie jar / cookie store. Whenever a request is made by the browser to the server all cookies in the store for that domain or subdomain will be sent to the server.

secure cookies vs insecure cookies

Secure cookies will be sent only on connections that are made over ssl(https protocol). Normal cookies will be sent on both http and https protocols.

session cookies vs. persistent cookies

  • session cookies - These cookies persist as long as the browser session is open. This means that Once you have cleared cache or closed the browser they get lost.

  • persistent cookies - These will persist even if the browser is closed and opened again unless you have set the browser to clear cookies on exit in which case they will behave just like session cookies.

First party cookies vs. Third party cookies.

  • First party cookies - generated by the domain currently open as main document - this means they have same domain as the one displayed in your browser.
  • Third party cookies - generated by a different domain then currently opened by the browser(in the addressbar) but which are managed inside an iframe or various resource calls like css, script, media(images, videos or other embedded media)

CORS - cross domain calls via xhttp ajax calls - this case arises when you create a domain requests resources from another domain via xhttp(ajax calls). In this case the browser makes a preflight check to see if the receiving domain accepts queries from the origin domain(origin headers are sent to the domain to check the cross domain policy). The server must necessarily respond with a valid options header and the server may allow identity data which is short for cookie data. If the remote domain has answered correctly with an "Access-Control-Allow-Origin" header that allows your domain or "*" then you are allowed to send cookies via this request. And these will behave just like normal calls.

To read more about cors:

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

like image 186
Paul G Mihai Avatar answered Sep 22 '22 05:09

Paul G Mihai