goal
Session variables were created primarily to combat stateless HTTP protocol behavior. Since each page request was processed completely completely separately from the request for another page, the developers wanted ways to link the sequence of requests together. A canonical example of this is the login page, which authenticates the user, and then changes the behavior of the pages requested after login.
To deal with this problem, many languages โโand / or frameworks have provided the concept of a session variable, which would allow the developer to store data that will be associated with a specific browser and will be saved through separate requests from the same browser.
So, to take logins as an example, the first time a new browser is requested, the Session variable will be empty. Then the user will fill in the authentication information and believing that this is correct, on the server side, the code will set a session variable for this browser to contain some kind of identifier to say that its browser has been authenticated. Then, during subsequent requests, the code could check this identifier in the session variable to execute certain code requiring login.
Another common use case would be a wizard workflow. You may have a multi-page form that you want the user to fill out several separate requests. When a user fills out a form, you can add values โโto the session until the user reaches the end of the form, after which you can save it in another persistent storage.
Storage and management
There are many ways to store session variables. Any permanent storage will work, which will be permanent for all requests. Probably the easiest way is to create a separate file for each session. PHP does this by taking the session identifier, which it saved as a cookie in the browser, and then searches for the file with the name obtained from the session identifier.
You can also store session variables in databases, shared memory, or even in the cookie itself. Ruby on Rails stores session variables by encrypting the data and then setting a cookie for the encrypted data. Thus, the session is stored in the user's browser itself.
Typically, the Session Variable is associated with a cookie, which is somehow stored in a web browser. This cookie is usually controlled automatically by the language or framework in which the web server application is written. The language or structure detects a new session and creates a new session variable that it provides to the web server application through some kind of API. The web server application can then use the API to store information in a session variable, to delete it, create a new one, etc. Typically, the framework has a specific default value for the session lifetime, but this is usually configured using the API. I think that the most typical default lifetime is the lifetime of the browser process through a cookie, the lifetime of which is associated with the user browser process.
Security
There are many security issues in session variables, as they are commonly used to control authorization and authentication in web applications.
For example, many applications set the session lifetime using the cookie lifetime. Many login systems want to force the user to re-login after a certain time, but you cannot trust the browser to expire the cookie when you tell it. The browser may be a mistake, it may be written by an attacker or manipulated by the user himself in order to set the cookie lifetime. Therefore, if your Session Variable API uses the cookie lifetime, you may need a secondary mechanism that causes the Session Expire variable to expire even if the cookie does not work.
Some other security issues are related to storage. If you store the session identifier in a cookie, and then use this session identifier as the file name to store the session variable, the malicious browser may change the session identifier in the cookie to a different identifier, and then requests from this browser will begin to use some other browser session file.
Another issue is stolen session information. By using an XSS or package check, session information can be stolen from a user browser session and then used by an attacker to access other user accounts. This issue is usually mitigated using SSL to secure the session on the go.
This page explains many security concerns when using PHP session variable variables. Ruby on Rails has a similar page that describes security issues with session variables for this platform.