Regenerate the session ID after login. That is the fastest way to kill session fixation. OWASP tells you what good session security should look like. PortSwigger helps you prove your app is broken before an attacker does.
TLDR: Session fixation happens when an attacker tricks a victim into using a session ID the attacker already knows. Example: Alice clicks a login link with a planted session cookie, logs in, and the attacker reuses that same ID to enter her account. In a small test of 100 login flows, even a 5% failure rate means 5 accounts could be exposed. Use OWASP for rules, then use PortSwigger-style testing to verify the rules work.
What is session fixation?
Session fixation is the web version of saving someone a seat, then stealing their wallet when they sit down.
Here is the simple flow:
- The attacker gets or creates a session ID.
- The attacker tricks the victim into using it.
- The victim logs in.
- The app keeps the same session ID.
- The attacker uses that ID to act as the victim.
The ugly bit is step four. If the session ID does not change after login, the app may have handed the attacker a golden ticket.
Honestly, it feels like a tiny bug. One cookie. One missed refresh. Then boom. Account takeover.
OWASP vs PortSwigger: the short version
OWASP is like the safety code for building a bridge. It gives clear rules. It says what secure session management should include.
PortSwigger is like a crash test lab. It teaches you how attacks work. Burp Suite helps you test real requests, cookies, redirects, and login flows.
Both are useful. They just solve different pains.
- OWASP: Best for policy, secure design, checklists, and developer standards.
- PortSwigger: Best for hands-on testing, bug hunting, and proof of risk.
- Together: Best for reducing session bugs before release.
What OWASP says to do
OWASP guidance is clear on the big rule. Change the session ID after authentication.
That means a user can browse as a guest. Fine. They may have a session ID already. But after login, the app must issue a new one.
OWASP also pushes these controls:
- Use strong random session IDs. No guessable values. No user IDs. No timestamps.
- Set Secure cookies. Send them only over HTTPS.
- Set HttpOnly cookies. Block JavaScript from reading them.
- Use SameSite. Cut down cross-site cookie abuse.
- Expire sessions. Idle timeouts and absolute timeouts both matter.
- Destroy sessions on logout. Do not just hide the logout button and call it a day.
- Do not accept session IDs from URLs. Those leak in logs, browser history, and referrers.
This is where OWASP shines. It gives teams shared language. Product owners, developers, QA, and security people can agree on what “secure enough” means.
The annoying part? OWASP can feel broad. You may read a rule and still ask, “Cool, but how do I test this exact login flow?” That is where PortSwigger earns its snacks.
What PortSwigger brings to the table
PortSwigger is famous for the Web Security Academy and Burp Suite. Its value is practical. You see the attack. You repeat it. You catch the bug.
For session fixation, a tester might use Burp like this:
- Open the site as a guest.
- Capture the first session cookie.
- Send the login request.
- Compare the session ID before and after login.
- If it stayed the same, raise the alarm.
This test is fast. Sometimes it takes less than a minute. Sometimes it takes 20 minutes because the app has three redirects, two tracking cookies, and one mystery token named bananaSessionFinal2. It drives me crazy that cookie names can be that unhelpful.
PortSwigger also helps test related issues. For example:
- Can the attacker set a session ID through a URL?
- Does the app accept a session cookie created before login?
- Does logout truly kill the session?
- Can a session be reused from another device?
- Are cookies missing Secure, HttpOnly, or SameSite flags?
The key difference: rules vs proof
OWASP gives the rule: renew the session ID after privilege change.
PortSwigger helps you prove if the app obeys that rule.
Think of OWASP as the recipe. Think of PortSwigger as tasting the soup. If the soup tastes like old socks, the recipe alone does not save dinner.
Session fixation is not just a login issue, either. Regenerate the session ID after any major privilege change. This includes:
- Login
- Multi-factor authentication completion
- Password reset
- Role upgrade
- Admin impersonation mode
- Switching tenant or workspace
If the user becomes more powerful, the session should become new.
A simple user case
Imagine a small online store. It has 50,000 monthly users. Around 8,000 log in each week.
A tester checks the login. The guest session cookie is:
SESSIONID=abc123
After login, it is still:
SESSIONID=abc123
Bad news.
An attacker could send a victim a link that plants or preserves that session. If only 1% of weekly users fall for a crafted link, that is 80 risky logins per week. Not all become account takeovers. But the door is open. That is enough to ruin someone’s Friday.
How to prevent session fixation
Use this checklist. It is short. It works.
- Regenerate the session ID after login. This is the main fix.
- Invalidate the old session ID. Do not leave it alive in the background.
- Regenerate after MFA. The user is more trusted now.
- Set cookie flags. Use Secure, HttpOnly, and SameSite.
- Reject session IDs in URLs. Cookies are safer for session tokens.
- Use short idle timeouts. Pick a sane value, such as 15 to 30 minutes for sensitive apps.
- Log session events. Track creation, login, logout, and regeneration.
- Test every release. Login flows change more often than teams admit.
Developers should also use safe framework features. Most modern frameworks can rotate session IDs. In many cases, the fix is a built-in method call. The hard part is remembering to use it in every login path.
Which one should your team use?
Use OWASP when you need standards. It is great for secure coding rules, audits, training, and acceptance criteria.
Use PortSwigger when you need evidence. It is great for testing, demos, bug reports, and teaching developers why the issue matters.
The best workflow is simple:
- Write your session rules from OWASP guidance.
- Build the login flow.
- Test it with PortSwigger methods and tools.
- Fix what fails.
- Add automated checks where possible.
Final takeaway
OWASP helps you design safer sessions. PortSwigger helps you catch weak sessions in the wild. For session fixation, the core defense is boring and beautiful: rotate the session ID after login and kill the old one.
Do that well, test it often, and your app becomes much harder to trick. Tiny cookie. Big impact. No drama required.
