How I Found a Session Hijacking Bug That Could Lead to Account Takeover | by Samadhan Shimple
The application accepted a valid PHPSESSID from another browser as the authenticated victim, allowing the attacker to perform a password change on the victim's account. An attacker who obtains a victim's session ID could impersonate that user and take over the account.
Published on samadhanshimple.medium.com
Account Takeover Attacks
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
This write-up describes a session-management weakness found while testing a web application. The application used a PHPSESSID cookie to track authenticated sessions. The feature involved is the password-change functionality, which normally lets a logged-in user change the password of their own account after the application has identified them from their session.
At first glance the cookie looked like an ordinary PHP session identifier. During testing, however, a valid session ID could be reused from a different browser, and the application still treated the request as coming from the authenticated victim. In other words, the application appeared to rely almost entirely on the supplied PHPSESSID to decide which user was making the request.

The image is an AI-generated illustration used as the article header.
Setup
The researcher used two separate accounts and two different browsers so that the sessions were completely separate:
- Account A: the attacker account.
- Account B: the victim account.
Account B was logged in with Microsoft Edge, and the authenticated PHPSESSID was captured. Account A was used in Firefox. Requests were intercepted and modified with Burp Suite. No other tools, versions or preconditions are described in the report.
Finding it
The starting point was the PHPSESSID cookie itself. It looked normal, but testing showed that a valid session ID could be reused from another browser and the application would still treat the request as the authenticated victim. That meant that anyone holding a victim's valid session ID could potentially impersonate that user and perform sensitive account actions.
The researcher then focused on the password-change functionality, because a hijacked session that can reach a sensitive account-management function turns session compromise into something more serious.
Exploitation
Step 1: Create two accounts
Create two separate accounts, an attacker account A and a victim account B.
Step 2: Authenticate as the victim
Log into Account B using a separate browser and capture the authenticated PHPSESSID.
Step 3: Authenticate as the attacker
Log into Account A using another browser. Navigate to the password-change functionality and intercept the request using Burp Suite.
Step 4: Replace the session cookie
Modify the intercepted request by replacing Account A's PHPSESSID with the valid PHPSESSID obtained from Account B, then forward the request. The report does not include the raw request or the exact cookie value.
Step 5: Observe the result
The application accepted the victim's session cookie without requiring any additional authentication or verification. The request was processed in the context of Account B. In testing, the researcher was able to observe victim-account information and successfully perform the password-change operation while operating from the attacker session. The response indicated that the request had been successfully executed against the victim account.
This demonstrated that possession of the victim's session identifier was sufficient to impersonate that session.
Root cause
The application appeared to rely almost entirely on the supplied PHPSESSID to determine the authenticated user. A session identifier belonging to one account was usable to authenticate as another account, even though the request did not genuinely originate from that authenticated session.
Sensitive operations such as changing a password should also require appropriate authorisation and, where appropriate, re-authentication or additional verification. In this case the password-change request was accepted purely on the strength of the swapped cookie. The report does not describe the underlying code, so the precise implementation mistake is not stated; The report does not describe the underlying code, so the precise implementation mistake is not stated.
Impact
Depending on the privileges associated with the compromised session, an attacker could potentially:
- Access private account information.
- Perform actions as the victim.
- Modify account settings.
- Change the victim's password.
- Lock the legitimate user out of their account.
- Access sensitive functionality available to the victim.
- Potentially escalate the attack if the compromised account has administrative privileges.
The password-change functionality makes this particularly concerning because successful exploitation could turn session compromise into persistent account takeover. The attacker may not need the victim's username or password, only a valid authenticated session identifier.
The researcher classifies the issue primarily as a session management / authentication failure with potential account takeover impact, with these mappings:
| Classification | Reference |
|---|---|
| OWASP Top 10 2021 | A07: Identification and Authentication Failures |
| CWE-384 | Session Fixation |
| CWE-287 | Improper Authentication |
| CWE-522 | Insufficiently Protected Credentials |
| Bug bounty category | Session Hijacking / Account Takeover |
The exact CWE depends on the root cause. If the application allows an attacker to fix or force a victim into a known session, CWE-384 is particularly relevant. If the core issue is simply that possession of a stolen session token is enough to impersonate the user, the report may be better described as an authentication/session-management vulnerability.
Fix
The report does not say whether the application was changed. It recommends reviewing the complete session-management implementation and applying these protections:
- Generate session identifiers using a cryptographically secure random mechanism.
- Ensure session IDs are sufficiently long and unpredictable.
- Rotate the session ID after authentication and important privilege changes.
- Invalidate the previous session when appropriate.
- Properly destroy sessions after logout.
- Set appropriate cookie attributes such as
Secure,HttpOnly, and an appropriateSameSitepolicy. - Avoid exposing session identifiers through URLs, logs, responses, or client-side JavaScript.
- Implement appropriate session expiration and inactivity timeouts.
- Require re-authentication or additional verification for highly sensitive operations such as password changes.
- Review whether sessions should be revoked after password changes or other security-sensitive account events.
Most importantly, authorisation decisions should be correctly tied to the authenticated session, and sensitive operations should not be performable simply by supplying another user's session identifier.
Variants to test
- Cookie swap on other sensitive endpoints. Repeat the swap against account recovery, email change, privilege changes and logout. A positive result is the request being processed in the victim's context, for example a success response or a visible change on the victim account.
- Session rotation after login. Capture the session ID before and after authentication. A positive result is the same ID being valid both before and after login, which points to session fixation.
- Session invalidation after logout. Log out and replay the old cookie. A positive result is the old session still being accepted.
- Session invalidation after password change. Change the password and replay the previous session cookie. A positive result is the old session remaining valid.
- Cookie attribute review. Inspect
Secure,HttpOnlyandSameSiteon the session cookie. A positive result is a missing attribute that allows the cookie to be read by script or sent over plain HTTP. - Session ID exposure. Check URLs, responses, logs and client-side storage for session identifiers. A positive result is a session ID appearing where an attacker could read it.
When testing, use controlled accounts and only the minimum actions needed to verify impact, as the researcher did. Report the issue privately through the organisation's security or bug-bounty programme with clear reproduction steps and evidence, and allow time for remediation before disclosing technical details.
What happened, in plain words
A security researcher was testing a website and found a problem with the way the site remembered who was logged in. When you log in to a website, the site gives your browser a small piece of data called a cookie. Your browser sends that cookie back with every request, and the site uses it to recognise you. On this site the cookie was called PHPSESSID.
The researcher discovered that this cookie was the only thing the site checked. If you took a valid cookie from one person's browser and put it into another person's browser, the site believed the second person was the first. The researcher proved this by taking the cookie from a victim account and using it to change the victim's password from a completely different account.
That is serious because it means anyone who gets hold of that cookie can act as the person it belongs to, without knowing their username or password. In this case the attacker could change the victim's password and lock them out of their own account.

The image above is an AI-generated illustration used as the header of the article.
The ideas you need first
Before the steps make sense, here are the basic pieces, explained from scratch.
A cookie. A cookie is a small label that a website sticks onto your browser. When you log in, the site creates a session (a temporary record of "this browser is logged in as this user") and gives your browser a cookie containing a session ID, a long random-looking string. Every time your browser asks the site for a page, it shows the cookie, like a wristband at an event. The site reads the wristband and lets you in without asking for your password again.
A session ID. The string inside the cookie. It is meant to be unguessable. If someone else gets your session ID, they can wear a copy of your wristband.
PHPSESSID. The default name PHP (a programming language many websites are built with) gives to its session cookie. Seeing this name tells you the site is probably built with PHP, but it is otherwise just a name.
Session hijacking. Stealing or reusing someone else's session ID so that the site treats you as them. The word "hijacking" is literal: you take over a session that is already open.
Account takeover. Going further: using that access to actually control the account, for example by changing its password so the real owner can no longer log in.
A browser. The program you use to visit websites, such as Firefox or Microsoft Edge. Each browser keeps its own separate set of cookies, which is why the researcher used two different browsers: it keeps the two accounts' sessions from mixing.
Burp Suite. A tool used by security testers. It sits between your browser and the website and lets you pause a request before it is sent, look at it, change it, and then send it on. Think of it as a post office worker who lets you open a letter, swap a page, and seal it again before delivery.
Intercepting a request. Pausing that outgoing message so you can edit it. The researcher used this to swap the cookie.
Password-change functionality. The page on a website where a logged-in user sets a new password for their own account. Normally the site first works out who you are from your session, then lets you change that account's password.
Authentication versus authorisation. Authentication is the site working out who you are. Authorisation is the site deciding what you are allowed to do. This bug is mostly an authentication failure: the site got "who are you" wrong.
Setting up the test
The researcher used two accounts and two browsers so the two sessions could never get mixed up:
- Account A: the attacker account, the one the researcher controls and uses to launch the attack.
- Account B: the victim account, standing in for a real user whose session gets stolen.
Account B was logged in with Microsoft Edge, and its authenticated PHPSESSID was captured. Account A was used in Firefox. Requests were paused and edited with Burp Suite. The report does not describe any other tools, versions or conditions.
Why two browsers? Because a browser stores cookies per site. If you logged into both accounts in the same browser, the second login would overwrite the first cookie and you could not hold both sessions at once. Two browsers give you two independent wristbands.
Finding it
The starting point was the PHPSESSID cookie itself. It looked normal, but testing showed that a valid session ID could be reused from another browser and the application would still treat the request as the authenticated victim. That meant anyone holding a victim's valid session ID could potentially impersonate that user and perform sensitive account actions.
The researcher then focused on the password-change page, because a hijacked session that can reach a sensitive account-management function turns a temporary session problem into something much worse: a permanent takeover.
Doing the attack, step by step
Step 1: Create two accounts
Create two separate accounts, an attacker account A and a victim account B.
Why: you need one account to attack from and one to attack, and you must own both so the test stays legal and controlled.
Step 2: Log in as the victim
Log into Account B using a separate browser and capture the authenticated PHPSESSID.
Why: this gives you the victim's wristband. "Capture" means reading the cookie value, for example from the browser's developer tools or from a request paused in Burp Suite. The report does not show the exact value.
Step 3: Log in as the attacker
Log into Account A using another browser. Navigate to the password-change functionality and intercept the request using Burp Suite.
Why: you want to catch the moment the attacker's browser asks the site to change a password, so you can edit that message before it arrives.
Step 4: Replace the session cookie
Modify the intercepted request by replacing Account A's PHPSESSID with the valid PHPSESSID obtained from Account B, then forward the request. The report does not include the raw request or the exact cookie value.
Why: this is the whole trick. The request still looks like it came from the attacker's browser, but the wristband inside now belongs to the victim. If the site trusts the wristband alone, it will think the victim is asking for the password change. "Forward" means letting the edited request continue to the server.
Step 5: Watch what happens
The application accepted the victim's session cookie without requiring any additional authentication or verification. The request was processed in the context of Account B. In testing, the researcher was able to observe victim-account information and successfully perform the password-change operation while operating from the attacker session. The response indicated that the request had been successfully executed against the victim account.
Why this matters: the site accepted the victim's session cookie without requiring any additional authentication or verification. It simply believed the cookie.
This demonstrated that possession of the victim's session identifier was sufficient to impersonate that session.
Why it happened
The application appeared to rely almost entirely on the supplied PHPSESSID to determine the authenticated user. A session identifier belonging to one account was usable to authenticate as another account, even though the request did not genuinely originate from that authenticated session.
Sensitive operations such as changing a password should also require appropriate authorisation and, where appropriate, re-authentication or additional verification. In this case the password-change request was accepted purely on the strength of the swapped cookie.
In everyday terms: the bouncer at the door only looked at the wristband and never checked the face wearing it.
What an attacker could do
Depending on the privileges associated with the compromised session, an attacker could potentially:
- Access private account information.
- Perform actions as the victim.
- Modify account settings.
- Change the victim's password.
- Lock the legitimate user out of their account.
- Access sensitive functionality available to the victim.
- Potentially escalate the attack if the compromised account has administrative privileges.
The password-change functionality makes this particularly concerning because successful exploitation could turn session compromise into persistent account takeover. The attacker may not need the victim's username or password, only a valid authenticated session identifier.
The report says successful exploitation could turn session compromise into persistent account takeover, because the attacker may then be able to change the password and lock the victim out.
The researcher classifies the issue primarily as a session management / authentication failure with potential account takeover impact, with these mappings:
| Classification | Reference |
|---|---|
| OWASP Top 10 2021 | A07: Identification and Authentication Failures |
| CWE-384 | Session Fixation |
| CWE-287 | Improper Authentication |
| CWE-522 | Insufficiently Protected Credentials |
| Bug bounty category | Session Hijacking / Account Takeover |
OWASP Top 10 is a widely used list of the most common categories of web security mistakes. CWE is a catalogue of specific weakness types, each with a number. The exact CWE depends on the root cause. If the application allows an attacker to fix or force a victim into a known session, CWE-384 is particularly relevant. If the core issue is simply that possession of a stolen session token is enough to impersonate the user, the report may be better described as an authentication/session-management vulnerability.
How to fix it
It recommends reviewing the complete session-management implementation and applying these protections:
- Generate session identifiers using a cryptographically secure random mechanism.
- Ensure session IDs are sufficiently long and unpredictable.
- Rotate the session ID after authentication and important privilege changes.
- Invalidate the previous session when appropriate.
- Properly destroy sessions after logout.
- Set appropriate cookie attributes such as
Secure,HttpOnly, and an appropriateSameSitepolicy. - Avoid exposing session identifiers through URLs, logs, responses, or client-side JavaScript.
- Implement appropriate session expiration and inactivity timeouts.
- Require re-authentication or additional verification for highly sensitive operations such as password changes.
- Review whether sessions should be revoked after password changes or other security-sensitive account events.
A few of those terms in plain words. "Cryptographically secure random" means generated by a method designed so nobody can predict the next value. "Rotate" means issue a fresh session ID at key moments, so an old one stops working. "Invalidate" means mark it as no longer valid. Secure means the cookie is only sent over encrypted connections. HttpOnly means scripts running in the page cannot read it. SameSite controls whether the cookie is sent when your browser is sent to the site from somewhere else. "Re-authentication" means asking the user to prove who they are again, for example by typing their current password, before a dangerous action.
Most importantly, authorisation decisions should be correctly tied to the authenticated session, and sensitive operations should not be performable simply by supplying another user's session identifier.
Other things worth testing
Once you understand the idea, you can look for the same pattern elsewhere:
- Cookie swap on other sensitive pages. Repeat the swap against account recovery, email change, privilege changes and logout. A positive result is the request being processed in the victim's context, for example a success response or a visible change on the victim account.
- Session rotation after login. Capture the session ID before and after logging in. A positive result is the same ID being valid both before and after login, which points to session fixation.
- Session invalidation after logout. Log out and replay the old cookie. A positive result is the old session still being accepted.
- Session invalidation after password change. Change the password and replay the previous session cookie. A positive result is the old session remaining valid.
- Cookie attribute review. Inspect
Secure,HttpOnlyandSameSiteon the session cookie. A positive result is a missing attribute that allows the cookie to be read by script or sent over plain HTTP. - Session ID exposure. Check URLs, responses, logs and client-side storage for session identifiers. A positive result is a session ID appearing where an attacker could read it.
When testing, use controlled accounts and only the minimum actions needed to verify impact, as the researcher did. Report the issue privately through the organisation's security or bug-bounty programme with clear reproduction steps and evidence, and allow time for remediation before disclosing technical details.
Glossary
- Account takeover: gaining control of someone else's account, often by changing their password so they cannot get back in.
- Authentication: the process of proving who you are, usually by logging in.
- Authorisation: the process of deciding what a logged-in user is allowed to do.
- Browser: the program used to visit websites, such as Firefox or Microsoft Edge.
- Burp Suite: a tool that sits between your browser and a website so you can pause, inspect and edit requests.
- Cookie: a small piece of data a website stores in your browser and receives back with each request, often used to remember that you are logged in.
- Cookie attributes: settings on a cookie that control how it is protected and when it is sent, such as
Secure,HttpOnlyandSameSite. - CWE: a numbered catalogue of specific software weakness types.
- CWE-287: Improper Authentication, a weakness where the system does not correctly verify who a user is.
- CWE-384: Session Fixation, a weakness where an attacker can make a victim use a session ID the attacker already knows.
- CWE-522: Insufficiently Protected Credentials, a weakness where login secrets such as session IDs or passwords are not adequately protected.
- Forward (a request): letting a paused request continue on to the server after editing it.
- HttpOnly: a cookie setting that stops scripts in the page from reading the cookie.
- Intercept: pause a request in transit so you can look at or change it.
- Invalidate (a session): mark a session as no longer valid so its cookie stops working.
- OWASP Top 10: a widely used list of the most common categories of web application security mistakes.
- OWASP A07: the 2021 entry for Identification and Authentication Failures.
- Password-change functionality: the page where a logged-in user sets a new password for their own account.
PHPSESSID: the default name PHP gives to its session cookie.- PHP: a programming language commonly used to build websites.
- Re-authentication: asking the user to prove who they are again before a sensitive action.
- Request: the message your browser sends to a website asking for a page or an action.
- Response: the message the website sends back.
- Rotate (a session ID): replace the session ID with a new one at key moments so the old one stops working.
- SameSite: a cookie setting that controls whether the cookie is sent when you arrive at the site from another site.
- Secure: a cookie setting that means the cookie is only sent over encrypted connections.
- Session: a temporary record on the server that a particular browser is logged in as a particular user.
- Session fixation: an attack where the attacker gets the victim to use a session ID the attacker already knows.
- Session hijacking: stealing or reusing someone else's session ID so the site treats you as them.
- Session ID: the long, supposedly unguessable string inside a session cookie that identifies the session.
- Session management: how a website creates, stores, checks, rotates and destroys sessions.
- Token: a general word for a piece of data that stands in for proof of identity or permission; a session ID is one kind.