In computer network security, session fixation attacks attempt to exploit the vulnerability of a system that allows one person to fixate (find or set) another person's session identifier. Most session fixation attacks are web based, and most rely on session identifiers being accepted from URLs (query string) or POST data.
Attack scenarios Alice has an account at the bank http://unsafe.example.com/ Mallory intends to target Alice's money from her bank. Alice has a reasonable level of trust in Mallory, and will visit links Mallory sends her.
A simple attack scenario Straightforward scenario:
Mallory has determined that http://unsafe.example.com/ accepts any session identifier, accepts session identifiers from query strings and has no security validation. http://unsafe.example.com/ is thus not secure. Mallory sends Alice an e-mail: "Hey, check this out, there is a cool new account summary feature on our bank, http://unsafe.example.com/?SID=I_WILL_KNOW_THE_SID". Mallory is trying to fixate the SID to I_WILL_KNOW_THE_SID. Alice is interested and visits http://unsafe.example.com/?SID=I_WILL_KNOW_THE_SID. The usual log-on screen pops up, and Alice logs on. Mallory visits http://unsafe.example.com/?SID=I_WILL_KNOW_THE_SID and now has unlimited access to Alice's account.
Attack using server generated SID A misconception is that if a server only accepts server-generated session identifiers, it is safe from fixation. This is false. Scenario:
Mallory visits http://vulnerable.example.com/ and checks which SID is returned. For example, the server may respond: Set-Cookie: SID=0D6441FEA4496C2. Mallory is now able to send Alice an e-mail: "Check out this new cool feature on our bank, http://vulnerable.example.com/?SID=0D6441FEA4496C2." Alice logs on, with fixated session identifier SID=0D6441FEA4496C2. Mallory visits http://vulnerable.example.com/?SID=0D6441FEA4496C2 and now has unlimited access to Alice's account.
Attacks using cross-subdomain cookie This type of attack is similar to a cross-site cookie attack except that it does not rely on the vulnerability of the user's browser. Rather, it relies on the fact that wildcard cookies can be set by a subdomain and that those cookies may affect other subdomains. Scenario:
A web site www.example.com hands out subdomains to untrusted third parties One such party, Mallory, who now controls evil.example.com, lures Alice to his site A visit to evil.example.com sets a session cookie with the domain .example.com on Alice's browser When Alice visits www.example.com this cookie will be sent with the request and Alice will have the session specified by Mallory's cookie. If Alice now logs on, Mallory can use her account. When this attack is complete, Mallory can gain access to www.example.com as Alice. It is not essential that a user login to exploit session fixation attacks and, although these unauthenticated attacks are not constrained to cross-sub-domain cookie attacks, the implications of sub-domain attacks are relevant to these unauthenticated scenarios. For example, Mallory may provide a URL from their evil site, fixating a session into an unauthenticated scenario, and use those techniques to exploit their target. This includes scenarios exploiting both the unauthenticated scenarios (e.g. forms or registration) as well as the ability to feed the user an established session to bypass the login completely. Consider, for example, that Mallory may create a user A1ice on www.example.com and login that user to capture a current, valid session identifier. Mallory then entraps Alice with a URL from evil.example.com which fixates that session cookie in Alice's browser (as described above) and redirects to www.example.com for finalizing a particular transaction (or, in fact, broader use). Mallory is thus able to ghost the session from their original login, scraping data and executing operations as 'A1ice' on 'www.example.com'. If Alice was successfully duped and saved her credit card to the account, Mallory might then make purchases using that card.
Countermeasures
Do not accept session identifiers from GET / POST variables Session identifiers in URL (query string, GET variables) or POST variables are not recommended as they simplify this attack – it is easy to make links or forms that set GET / POST variables.
The SID is leaked to other people as users cut & paste "interesting links" from the address bar into chats, forums, communities, etc. The SID is stored in many places (browser history log, web server log, proxy logs, ...) Note: Cookies are shared between tabs and popped up browser windows. If your system requires to be hit with the same domain (www.example.com/?code=site1 and www.example.com/?code=site2 ), cookies may conflict with one another between tabs. It may be required to send the session identifier on the URL in order to overcome this limitation. If possible use site1.example.com or site2.example.com so there are no domain conflicts in the cookies. This may incur costs with extra SSL certificates. This behavior can be seen on many sites by opening another tab and trying to do side by side search results. One of the sessions will become unusable. Session identifiers in GET and POST were deprecated in PHP 8.4 and will be removed in PHP 9.0.
Best solution: Identity confirmation This attack can be largely avoided by changing, regenerating the session ID when users log in. If every request specific to a user requires the user to be authenticated with ("logged into") the site, an attacker would need to know the id of the victim's log-in session. When the victim visits the link with the fixed session id, however, they will need to log into their account in order to do anything "important" as themselves. At this point, their session id will change, and the attacker will not be able to do anything "important" with the anonymous session ID. A similar technique can be used to solve the phishing problem. If the user protects their account with two passwords, then it can be solved to a great extent. This technique is also useful against cross-site request forgery attacks.
Solution: Store session identifiers in HTTP cookies The session identifier on most modern systems is stored by default in an HTTP cookie, which has a moderate level of security as long as the session system disregards GET/POST values. However, this solution is vulnerable to cross-site request forgery, and it does not meet the statelessness requirement of REST.
… excerpt ends here. Continue reading the full article.