How I Discovered a Session Management Vulnerability That Could Lead to Account Takeover | By…
The application accepted a valid session identifier from one account when supplied in a request from another account, returning the authenticated session of the first account. An attacker who obtains a victim's valid session identifier could access the victim's account without knowing their password.
Published on samadhanshimple.medium.com
Cybersecurity
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
While testing a web application during bug bounty research, I came across a weakness in how the application handled authenticated sessions. The application used PHP session identifiers, exposed to the browser as the PHPSESSID cookie, to recognise authenticated users across requests.
Normally the flow is straightforward:
- User A logs in to the application.
- The server creates a session.
- The browser stores a session cookie.
- The browser sends that cookie with subsequent requests.
- The server uses the session identifier to recognise the authenticated user.
A simplified example of the cookie looks like this:
PHPSESSID=abc123456789
The session identifier is a temporary reference to an authenticated session. If someone obtains another user's valid session identifier, they may be able to access that user's account without knowing their password, which is why these identifiers must be handled carefully.

The image at the top of the article is described as AI generated.
Setup
To investigate the session management behaviour I used two separate browser environments and two test accounts that I controlled:
- Account A: logged in using Firefox.
- Account B: logged in using Microsoft Edge.
- Burp Suite: used to inspect HTTP requests and responses.
Using two separate accounts helped me understand how the application associated session identifiers with authenticated users. All testing was performed only with accounts under my control.
Finding it
I started by logging in to Account A using Firefox. After authentication, I opened Burp Suite and intercepted a request to the account profile page. I examined the request headers and identified the PHPSESSID cookie.
Next, I logged in to Account B using Microsoft Edge and observed its session cookie separately. At this point I had two authenticated sessions belonging to my own test accounts, and I wanted to understand how the server handled session identifiers supplied through the cookie header.
What I noticed was that the application accepted the valid session identifier associated with Account B when it was supplied in a request originally captured from Account A. The server returned a response associated with Account B rather than Account A. In other words, changing the session identifier changed the authenticated identity associated with the request.
This looked wrong because it showed that possession of another user's valid session identifier was sufficient to access that user's authenticated session. It also showed why protecting session identifiers is critical.
One important technical distinction: this observation demonstrates session hijacking through session ID substitution. It does not independently prove session fixation. To confirm session fixation, I would also need to establish that an attacker-controlled session identifier remains unchanged when the victim logs in.
Exploitation
Step 1: Establish two authenticated sessions
I logged in to Account A in Firefox and Account B in Microsoft Edge, so that I held two valid authenticated sessions belonging to my own test accounts.
Step 2: Capture a request from Account A
With Burp Suite intercepting, I captured a request to the Account A profile page and examined its headers. The relevant cookie was the PHPSESSID value belonging to Account A.
Step 3: Substitute the session identifier
I took the valid session identifier associated with Account B and supplied it in the request originally captured from Account A, replacing the PHPSESSID value in the cookie header.
Step 4: Observe the response
Changing the session identifier changed the authenticated identity associated with the request, showing that a valid session identifier from one account was accepted in place of another.
Root cause
The report lists several possible session management weaknesses that could contribute to this type of issue; which one applied to the target is not established. The report describes several possible session management weaknesses that can contribute to this type of issue:
- Failure to regenerate session IDs. A secure application should regenerate the session identifier when authentication privileges change. In PHP, developers can use:
session_regenerate_id(true);
This generates a new session identifier and helps prevent an existing unauthenticated session from becoming an authenticated session without changing its identifier.
-
Trusting client-supplied session identifiers. Accepting an identifier is not automatically a vulnerability, but applications must ensure that session IDs are unpredictable, properly generated, securely associated with server-side sessions, and protected against fixation.
-
Weak session lifecycle management. Session management does not end at login. Logout, session expiration, privilege changes and session invalidation must all be handled correctly, otherwise authenticated sessions may remain exposed to unauthorised access.
Which of these applied to the target is not established by the observation itself; the report presents them as possible contributing weaknesses.
Impact
The impact depends on the application's session management implementation and on the attacker's ability to obtain or fix a valid session identifier. Potential consequences include:
- Account takeover. If an attacker obtains a victim's valid authenticated session identifier, they may be able to access the victim's account without knowing their credentials.
- Unauthorised access to private information. Depending on the application's functionality, an attacker may gain access to personal information, account settings, private messages or other sensitive resources.
- Unauthorised actions. If the application does not properly protect authenticated requests, an attacker may be able to perform actions using the victim's account.
- Privilege abuse. If the affected session belongs to a privileged user, the consequences could be more serious.
The actual impact should always be determined by testing which resources and actions are accessible through the affected session.
Fix
The report does not describe a fix applied by the target. It lists secure session management practices developers should follow to reduce the risk of session fixation and session hijacking:
- Regenerate session IDs after authentication. Generate a new session identifier after successful login and whenever the user's privilege level changes.
- Use secure cookie attributes. Configure session cookies with
HttpOnly(prevents JavaScript from accessing the cookie),Secure(ensures the cookie is transmitted over HTTPS) andSameSite(helps reduce certain cross-site request risks). - Implement proper session expiration. Authenticated sessions should expire according to the application's security requirements.
- Invalidate sessions during logout. When a user logs out, the server should invalidate the corresponding session rather than simply removing the cookie from the browser.
- Avoid trusting user-controlled session state. Session identifiers should be generated securely and managed through server-side session mechanisms.
Variants to test
- A positive result is that the identifier remains the same after authentication and the attacker can reuse it to reach the authenticated session.
- Session identifier substitution across accounts. With two accounts you control, swap the
PHPSESSIDvalue from one account into a request captured from the other. A positive result is a response belonging to the account whose identifier was supplied. - A positive result is that the old identifier still grants access, showing the server did not invalidate the session.
- A positive result is that the same identifier now carries the higher privileges.
- A positive result is a session cookie missing one or more of these attributes, which widens the paths by which an identifier can be obtained.
As bug bounty hunters, we should focus on understanding the actual behaviour of an application, collecting reliable evidence, and demonstrating the security impact without making assumptions. Session management is as important as login forms, password reset functionality and OTP verification, and a small weakness in how an application handles session identifiers can potentially create a serious security issue.
What happened, in plain words
A security researcher was testing a website during bug bounty research and found a problem with how the site remembered who was logged in. The site used a cookie called PHPSESSID to keep track of logged-in users. The researcher discovered that if you took the cookie value from one account and used it in a request that originally came from a different account, the server would treat the request as coming from the first account. In other words, anyone who got hold of your session cookie could act as you, without needing your password. This is a session management weakness that could lead to account takeover.

The image at the top of the article is described as AI generated.
1. Understanding the PHPSESSID cookie
Before we dive into the testing, let's explain what a cookie is and what PHPSESSID does.
A cookie is a small piece of data that a website asks your browser to store. When you visit the site again, your browser sends that data back to the server. Cookies are used for many things, including keeping you logged in.
When you log in to a website, the server needs a way to recognise you on subsequent requests. Since the web is stateless (each request is independent), the server creates a session: a temporary record on the server that says "this user is authenticated". To link your browser to that session, the server sends a session identifier (a long random string) in a cookie. Your browser stores it and sends it with every request to that site. The server looks up the identifier and knows which session it belongs to.
In PHP applications, this cookie is typically called PHPSESSID. Here is a simplified example of what it looks like:
PHPSESSID=abc123456789
This line shows the cookie name (PHPSESSID) and its value (abc123456789). The value is the session identifier. In a real application, this value would be a long, random string that is hard to guess.
The important point is that the session identifier acts as a temporary key to your logged-in session. If someone else obtains your valid session identifier, they can use it to access your account without knowing your password. That's why these identifiers must be kept secret and handled securely.
2. What is session fixation?
Session fixation is a type of vulnerability where an attacker can make a victim use a session identifier that the attacker already knows, and that identifier remains valid after the victim logs in. The attacker can then use the same identifier to hijack the victim's authenticated session.
The core problem is that the application does not change the session identifier when the user logs in. A secure application should always generate a new session identifier after a successful login (and whenever the user's privileges change).
Here is a simplified attack scenario:
- The attacker obtains or sets a session identifier (for example, by sending a link with a fixed session ID).
- The victim is tricked into using that session identifier (e.g. by clicking the link).
- The victim logs in to their account.
- The application continues to use the same session identifier.
- The attacker, who knows the identifier, can now access the victim's authenticated session.
The key issue is the failure to establish a fresh session identifier after authentication. A secure application should regenerate the session identifier when authentication privileges change.
3. My testing environment
To investigate the session management behaviour, I used two separate browser environments and two test accounts that I controlled:
- Account A: logged in using Firefox.
- Account B: logged in using Microsoft Edge.
- Burp Suite: used to inspect HTTP requests and responses.
Using two separate accounts helped me understand how the application associated session identifiers with authenticated users. All testing was performed only with accounts under my control.
Why two browsers? Because each browser stores its own cookies separately. By using Firefox for Account A and Edge for Account B, I could keep the two sessions completely separate and avoid mixing them up. This made it easier to see exactly which cookie belonged to which account.
What is Burp Suite? Burp Suite is a tool that sits between your browser and the web server, allowing you to intercept, inspect, and modify HTTP requests and responses. It's commonly used in security testing to see exactly what data is being sent back and forth. In this case, I used it to capture requests and view the cookies.
4. Investigating the PHPSESSID cookie
I started by logging in to Account A using Firefox. After authentication, I opened Burp Suite and intercepted a request to the account profile page. I examined the request headers and identified the PHPSESSID cookie.
Next, I logged in to Account B using Microsoft Edge and observed its session cookie separately. At this point, I had two authenticated sessions belonging to my own test accounts. I wanted to understand how the server handled session identifiers supplied through the cookie header.
What is an HTTP header? When your browser sends a request to a server, it includes headers: extra pieces of information like the type of browser, the language, and cookies. The Cookie header contains all the cookies for that site. By inspecting the request in Burp Suite, I could see the PHPSESSID cookie being sent.
Why capture a request? I needed to see the exact request that included the session cookie so that I could later modify it and observe the server's response. This is a common technique in web security testing: capture a legitimate request, change one part, and see how the server reacts.
5. The interesting observation
During my investigation, I observed that the application accepted the valid session identifier associated with Account B when it was supplied in a request originally captured from Account A. The server returned a response associated with Account B rather than Account A. In other words, changing the session identifier changed the authenticated identity associated with the request.
This was an important observation because it demonstrated that possession of another user's valid session identifier was sufficient to access that user's authenticated session. It also showed why protecting session identifiers is critical.
Important technical distinction: This particular observation demonstrates session hijacking through session ID substitution. It does not independently prove session fixation. To confirm session fixation, I would also need to establish that an attacker-controlled session identifier remains unchanged when the victim logs in.
What is session hijacking? Session hijacking is when an attacker takes over a user's session by stealing or guessing their session identifier. In this case, the attacker only needs a valid session identifier for the account they want to access. By substituting it into a request, they can impersonate that user.
Why is this different from session fixation? In session fixation, the attacker tricks the victim into using a session identifier that the attacker already knows, and that identifier stays the same after login. In session hijacking by substitution, the attacker simply uses a valid session identifier from another account. The report focuses on the latter.
6. Why does this happen?
There are several possible session management weaknesses that can contribute to this type of issue.
Failure to regenerate session IDs
One important security practice is regenerating the session identifier after successful authentication. In PHP, developers can use:
session_regenerate_id(true);
This line calls the PHP function session_regenerate_id with the argument true. The function generates a new session identifier and helps prevent an existing unauthenticated session from becoming an authenticated session without changing its identifier. This helps prevent an existing unauthenticated session from becoming an authenticated session without changing its identifier. In other words, it makes session fixation much harder.
Trusting client-supplied session identifiers
Applications must carefully manage session identifiers received through cookies. Accepting an identifier is not automatically a vulnerability. However, applications must ensure that session IDs are unpredictable, properly generated, securely associated with server-side sessions, and protected against fixation.
What does "client-supplied" mean? The client (your browser) sends the session identifier in a cookie. The server should treat this as a hint, not as absolute truth. If the server blindly trusts whatever identifier the client sends, an attacker can supply any identifier they want. The server should ensure that session IDs are unpredictable, properly generated, securely associated with server-side sessions, and protected against fixation.
Weak session lifecycle management
Session management does not end when a user logs in. Applications must also handle logout, session expiration, privilege changes, and session invalidation correctly. If these processes are not implemented properly, authenticated sessions may remain exposed to unauthorised access.
What is session lifecycle? It's the entire life of a session: creation at login, use during the session, and destruction at logout or expiration. Each stage needs to be secure. For example, on logout, the server should invalidate the session so that the old identifier cannot be reused. If it doesn't, an attacker who stole the identifier could continue to use it even after the user logs out.
7. Potential security impact
The impact of this type of vulnerability depends on the application's session management implementation and the attacker's ability to obtain or fix a valid session identifier. Potential consequences include:
- Account takeover: If an attacker obtains a victim's valid authenticated session identifier, they may be able to access the victim's account without knowing their credentials.
- Unauthorised access to private information: Depending on the application's functionality, an attacker may gain access to personal information, account settings, private messages, or other sensitive resources.
- Unauthorised actions: If the application does not properly protect authenticated requests, an attacker may be able to perform actions using the victim's account.
- Privilege abuse: If the affected session belongs to a privileged user, the consequences could be more serious.
The actual impact should always be determined by testing which resources and actions are accessible through the affected session.
Why is this serious? Because session identifiers are the keys to the kingdom. If an attacker can get one, they can access the account without knowing the password. They don't need to crack anything; they just use the valid session. This is why session management is a critical part of web security.
8. How developers can prevent this vulnerability
Developers should follow secure session management practices to reduce the risk of session fixation and session hijacking. Here are some important recommendations:
- Regenerate session IDs after authentication. Generate a new session identifier after successful login and whenever the user's privilege level changes.
- Use secure cookie attributes. Configure session cookies with appropriate security attributes:
HttpOnly: Prevents JavaScript from accessing the cookie.Secure: Ensures the cookie is transmitted over HTTPS.SameSite: Helps reduce certain cross-site request risks.
- Implement proper session expiration. Authenticated sessions should expire according to the application's security requirements.
- Invalidate sessions during logout. When a user logs out, the server should invalidate the corresponding session rather than simply removing the cookie from the browser.
- Avoid trusting user-controlled session state. Session identifiers should be generated securely and managed through server-side session mechanisms.
What do these attributes do?
HttpOnlytells the browser that the cookie should not be accessible via JavaScript. This helps prevent attacks where malicious scripts steal cookies.Securetells the browser to only send the cookie over HTTPS, so it can't be intercepted on an insecure network.SameSitecontrols when the browser sends the cookie with cross-site requests, reducing the risk of cross-site request forgery (CSRF) attacks.
9. Lessons I learned
This investigation reminded me that authentication testing is not only about checking login forms, password reset functionality, or OTP verification. Session management is equally important.
A small weakness in how an application handles session identifiers can potentially create a serious security issue.
One important lesson is to distinguish between session fixation and session hijacking. Although both involve session identifiers, their root causes and attack conditions are different.
As bug bounty hunters, we should focus on understanding the actual behaviour of an application, collecting reliable evidence, and demonstrating the security impact without making assumptions.
Conclusion
Session management is one of the most important parts of web application security.
During my testing, I discovered that the application accepted another test account's valid PHPSESSID and returned the corresponding authenticated account. This demonstrated a session security weakness that could allow unauthorised account access if an attacker obtained a victim's valid session identifier.
The key takeaway is simple: applications should never treat session management as a minor implementation detail. Proper session regeneration, secure cookie configuration, and server-side session validation are essential for protecting authenticated users.
Keep testing, keep learning, and always focus on understanding the root cause behind a vulnerability.
AI assistance: I used an AI-powered grammar and spelling checker to review this article. The ideas, research, technical analysis, and final content are my own.
*Have questions or want to share your own workflow?
🔗Linkdin: https://www.linkedin.com/company/sam-shield/
🔗Youtube: https://www.youtube.com/@sam_shield-w7l
Glossary
- Cookie: A small piece of data stored by your browser on behalf of a website, sent back to the server with each request to that site.
- Session: A temporary record on the server that represents a user's authenticated state.
- Session identifier: A unique string that links a user's browser to their session on the server.
- PHPSESSID: The default name of the session cookie used by PHP applications.
- Session fixation: A vulnerability where an attacker can make a victim use a session identifier known to the attacker, and that identifier remains valid after login.
- Session hijacking: Taking over a user's session by stealing or guessing their session identifier.
- Session ID substitution: Replacing the session identifier in a request with another valid identifier to impersonate a different user.
- Burp Suite: A tool used for web security testing that can intercept and modify HTTP requests and responses.
- HTTP header: Extra information sent with an HTTP request or response, such as cookies, browser type, etc.
- Cookie attributes: Settings like
HttpOnly,Secure, andSameSitethat control how cookies behave. - HttpOnly: A cookie attribute that prevents JavaScript from accessing the cookie.
- Secure: A cookie attribute that ensures the cookie is only sent over HTTPS.
- SameSite: A cookie attribute that controls when cookies are sent with cross-site requests.
- Session regeneration: The process of creating a new session identifier after login or privilege change.
- Account takeover: Gaining unauthorised access to another user's account.
- Privilege escalation: Gaining higher levels of access than authorised.
- OTP: One-time password, often used for two-factor authentication.
- CSRF: Cross-Site Request Forgery, an attack that tricks a user's browser into performing unwanted actions on a site where they are authenticated.