Answer the question
In order to leave comments, you need to log in
How exactly are sessions and cookies arranged?
As a rule, when executing code on the server, the programmer is given access to such storage variables as cookies and session. On the client, with javascript, we can only access cookies.
As far as I know, cookies are stored on the client (browser), and session on the server.
The following questions arise:
Answer the question
In order to leave comments, you need to log in
1. There is no synchronization. The server can only tell the client that it needs to set cookie X to Y with the Set-Cookie header and read the cookie request from the server (all cookies are sent in every server request).
2. Sessions can be stored on the client (signed cookie session). This uses cookie signing using HMAC.so that the session data cannot be freely modified by the client. But usually sessions are stored on the server. There is a huge choice here: from databases and key-value storages (Redis, for example) to simple files. At the same time, a session ID cookie is sent to the client (this is how the server identifies the user), which an attacker can steal. These cookies, in order to protect users from XSS, are set with the HttpOnly flag, which advises the browser not to give this cookie to scripts like JS. In this case, stealing the cookie will only be possible by taking possession of the browser, the user's file system, or through a browser bug.
3. See the second answer. In some cases, yes. But rarely.
4. You can pass the session id value in the URL string (GET as a parameter), like this: example.com/some/page/?session_id=2af26905dcf31a1d...Some services use this as a fallback option, however, it is very insecure because any XSS or simple harmless JS like Yandex.Metrica sees the entire URL. So, we send the user to enable cookies.
Cookies - a file on the client that stores some data in the form of a key-knowledge and is transmitted in the header https of the request
. The session identifier is stored on the client, by which data about the client is obtained on the server
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question