What is the session
In web projects, a session is the use of an application by a user, usually comprising a sequence of requests.
On the other hand, the term session may also refer to the content, location or storage variable of the state stored. For example, in Java there is the session map, in PHP the superglobal variable $_SESSION
and so on.
How the session works
To identify that the sequence of actions come from the same user, some technique is used to identify it, the most common being:
- Cookies: a session identifier is placed in a Cookie, which will persist at least until the user changes or closes the browser. Remember that the Cookies are sent from the browser to the server at each request.
- URL rewriting: a session identifier is generated on the first access to the system and all system links add this identifier as a URL parameter. This way, in each request can identify the user.
It is then understood that the general procedure is to generate a id
single per user and then have every request enter this id
in some way, through which the language, the framework or the server can store and retrieve the state user session.
What makes it safe
Nothingness. There are several easy-to-perform attacks on systems that rely only on the session to authenticate and authorize users. The most common is the sequestration. Just get somehow the Cookie or URL that contains the session identifier and put it in any other browser.
Security, however, can be implemented reasonably efficiently with asymmetric encryption (HTTPS/SSL). Certificates signed by certifying authorities (CA’s) can also be used to ensure that the conversation is actually being done with whom you expect and not with a "stranger". In addition, the content of Cookies could not be intercepted by an intermediary between client and server, because only the true agents could decrypt the data with the private key.
The pattern of Cookies specifies a parameter secure
what force a Cookie to be sent only if the connection is secure (HTTPS). This can give a certain assurance that it will not "escape" by mistake in some HTTP request common to the server.
Anyway, I’m not a security expert. There are certainly many details pertinent to this subject, but I hope this is a good introduction.
+1, very good content. However, note - a requested URL under HTTPS is, yes, encrypted. It is part of the request payload. The server name can be determined since an initial TCP connection (which is where SSL/TLS happens) is required for Handshake.
– OnoSendai
@Onosendai, you are right. I made an ugly mess with the URL reminding of a case I’ve seen where a proxy log could be used to steal the session, but it really wasn’t HTTPS.
– utluiz
In fact you are correct if the communication between the client and proxy occurs via HTTP and the proxy takes advantage of Nating to switch to HTTPS - the Proxy in this case would know which URL was used.
– OnoSendai
There are cases also that the management of the session takes place by an id inserted inside the HTML page itself.
– Inael Rodrigues
@Inaelrodrigues Well remembered. This is a technique widely used to maintain *one session per tab". However, the id is still sent via cookie, url parameter or as part of the body in each request. What changes is basically the scope of the session.
– utluiz