Cybersecurity / 5 min read
Session Fixation
Session fixation is an attack in which someone gains access to a user’s account by getting the user to log in with a session ID the attacker already knows.
.jpg)
Description
Session fixation is an attack in which someone gains access to a user’s account by getting the user to log in with a session ID the attacker already knows.
The weakness lies in how the application handles sessions during authentication, particularly when it keeps the existing session ID after a successful login instead of replacing it with a new one.
An attacker first obtains a valid session ID from the application, then finds a way to make the victim’s browser use that same ID.
When the victim logs in, the application associates their account with the existing session, allowing the attacker to reuse the known ID to access the authenticated account.
The attacker does not need to know the victim’s password because the application has already accepted their credentials and attached their identity to the shared session.
How It Differs From Session Hijacking
Session fixation begins before the victim logs in, with the attacker arranging for the victim to use a known session ID.
In the session hijacking scenario described here, the attacker steals a session ID after the user has already authenticated.
Both can result in access to another person’s account, but session fixation depends on establishing the known session ID before authentication takes place.
Common Techniques
The method an attacker uses depends on how the application accepts session IDs and how much control the attacker has over the victim’s browser or the application’s responses.
Session ID in a URL
Some applications accept a session ID as part of a URL, allowing an attacker to send the victim a link containing an ID the attacker already knows.
If the victim follows the link and logs in, the account may become associated with that session ID when the application fails to replace it during authentication.
Session ID in a Hidden Form Field
An application may accept a session ID through a hidden field in a login form.
An attacker can prepare a form containing a known session ID and persuade the victim to use it to log in to the legitimate application.
The form might be placed on a website controlled by the attacker or included in an HTML email where the email client permits forms.
If the application accepts the supplied ID and keeps it after login, the attacker may be able to reuse it to access the victim’s account.
Session ID in a Cookie
Applications commonly use cookies to store session IDs in the browser.
If an attacker can make the victim’s browser store a known session ID in the relevant cookie, the application may continue using that ID when the victim authenticates.
Several techniques have been used to attempt this.
Client Side Scripting
A vulnerability such as cross site scripting may allow an attacker to execute JavaScript within the application’s origin in the victim’s browser.
Where cookie protections allow it, the script can use document.cookie to set a session cookie containing a value known to the attacker.
If the application accepts that value and does not replace the session ID after login, the attacker may be able to access the authenticated session.
META Tags
Older descriptions of session fixation include attempts to set cookies through an injected HTML META tag using the http-equiv attribute with the value Set-Cookie.
This technique depends on browser support and should be understood as a historical example rather than a method that reliably works in modern browsers.
The intended result is the same as with other cookie techniques, which is to make the victim’s browser use a session ID already known to the attacker.
HTTP Response Headers
An attacker who can influence an application’s HTTP response may attempt to insert a Set-Cookie header containing a known session ID.
When the browser accepts the cookie, it may send that session ID with later requests to the application.
This requires some way to control or modify the relevant response, such as a vulnerability in the application or an opportunity to tamper with unprotected traffic.
Examples
Example 1: Session ID Supplied Through a Link
The attacker visits the application and receives a valid session ID.
Alternatively, where the application allows it, the attacker may choose a session ID that the server accepts.
The attacker then sends the victim a link to the application containing that ID.
When the victim opens the link, the application recognises the supplied session ID and continues using the existing session.
The victim enters their username and password, and the application authenticates them without changing the session ID.
Because the attacker already knows that ID, they can submit it in their own requests and may gain access to the victim’s account.
Example 2: Session ID Set Through JavaScript
In this example, the attacker attempts to place the known session ID directly in the victim’s cookie instead of including it in a link.
A cross site scripting vulnerability may provide a way to run JavaScript in the application’s origin and set the relevant cookie, provided its protections permit this.
The victim then logs in while the browser is using the session ID chosen or obtained by the attacker.
If the application keeps the same ID after authentication, the attacker may reuse it to access the account.
Example 3: Session ID Set Through a META Tag
In the historical META tag example, the attacker injects HTML intended to make the browser store a cookie containing a known session ID.
If the browser supports the behaviour and accepts the cookie, the victim may authenticate using that ID.
The attack then depends on the application preserving the same session ID after login.
Modern browsers generally do not support setting cookies through this META tag mechanism.
Example 4: Session ID Set Through an HTTP Response
In this example, the attacker has a way to modify a response sent to the victim’s browser.
The attacker adds a Set-Cookie header containing a session ID they already know.
If the browser accepts the cookie, subsequent requests may use that ID, including requests made when the victim logs in.
If the application authenticates the victim without replacing the session ID, the attacker may reuse the same value to access the authenticated session.
← Back to Cybersecurity