<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sushobhit Goyal on Medium]]></title>
        <description><![CDATA[Stories by Sushobhit Goyal on Medium]]></description>
        <link>https://medium.com/@sushobhitxd?source=rss-83d6cc6d60cb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ANP6KlN6iYQJMzYa</url>
            <title>Stories by Sushobhit Goyal on Medium</title>
            <link>https://medium.com/@sushobhitxd?source=rss-83d6cc6d60cb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 12:07:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sushobhitxd/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Session Fixation: The Bug That Hides Behind a Login]]></title>
            <link>https://sushobhitxd.medium.com/session-fixation-the-bug-that-hides-behind-a-login-e888b880a298?source=rss-83d6cc6d60cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/e888b880a298</guid>
            <category><![CDATA[session-management]]></category>
            <category><![CDATA[session-fixation]]></category>
            <category><![CDATA[owasp-top-10-2025]]></category>
            <dc:creator><![CDATA[Sushobhit Goyal]]></dc:creator>
            <pubDate>Sun, 03 May 2026 22:52:26 GMT</pubDate>
            <atom:updated>2026-05-03T22:52:26.761Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>A university portal was issuing two session cookies post-authentication, neither of which was rotated on login resulting in the dangerous promotion of a pre-auth seed. Here’s the technical breakdown of how this flawed state management leading to Session Fixation (CWE-384)</em></blockquote><pre>CONTENTS<br>1. What is a session?<br>2. What is a session ID?<br>3. What is session fixation?<br>4. Session fixation vs session hijacking<br>5. The discovery: two cookies, one problem<br>6. Exploit delivery vectors ~ how attacker can leud you <br>7. Standards &amp; classification (OWASP, CWE, CAPEC, CVSS)<br>8. Remediation</pre><h3>1. What is a session ?</h3><p>HTTP is a stateless protocol. The server has no inherent memory of who sent the previous request. This is a deliberate design property of HTTP, not an oversight. But this creates an obvious practical problem : how does a web application maintain continuity across requests? In layman terms, how does it know that you’re still logged in between clicking “user dashboard” and “edit profile” ?</p><p>The answer is <strong>sessions</strong>. A session refers to a way of maintaining state information about a user’s interactions with a web application giving HTTP illusion of statefulness.<br>More technically, a session is a server-side data structure that maps a temporary identifier( often referred as session id, we’ll talk later) to a user’s state — their identity, auth level, preferences or any other data application needs to persist across requests.</p><p>The session store lives entirely server-side, never on the client(which holds only the session id). The session ID is authentication. Whoever presents a valid session ID is treated by the server as the legitimate user. There is no secondary channel, no additional verification. This is why attacks that compromise the session ID — fixation, hijacking, theft — are so impactful. You don’t need the password. You need the key.</p><h3>2. What is a Session ID ?</h3><p>A session ID is a cryptographically random token generated by server at time of creating the session. This ID must not be derived from some obvious parameters (such as user ID, timestamp, IP address or anything) and no two concurrent active sessions should share the same session ID. Most importantly, <strong>it should be rotated on a privilege change especially login.</strong><br> Session cookie names are framework-specific and immediately useful during recon because they tell you the backend tech stack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/0*HNTj0f0RSCswQNoO.png" /></figure><p>Seeing PHPSESSID in a response tells you the backend is in PHP and PHP&#39;s native session_* API. This is directly relevant to exploitation — PHP has specific ini directives (session.use_trans_sid, session.use_only_cookies) that control whether session IDs can be delivered via URL parameters, which can be the primary fixation delivery vector.</p><h3>3. What is Session Fixation?</h3><p>Session fixation is an attack in which the attacker predetermines the session ID which they make the victim use for authenticating. Rather than stealing a session token after the fact, the attacker plants a known value on the victim’s browser before authentication happens. If the server doesn’t rotate the session ID upon login, issuing a fresh id and invalidating the old one — the attacker’s pre-planted token becomes and authenticated session.</p><p>The root cause is almost the similar mission operation: the application doesn’t call session_regenerate_id() (or its equivalent) on successful authentication.</p><p>Now let me map out the attack sequence to you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/0*i9vs-Un5saJpg1W2.png" /></figure><p>The attacker never intercepts traffic, exploits XSS on an authenticated session rather sets the trap before login. Victim’s own authentication springs it.<br> This makes fixation particularly insidious — the victim does everything correctly, and they still lose the session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/0*yooZP3_TbBgxqISL.png" /></figure><h3>4. Session Fixation vs Session Hijacking</h3><p>These two are frequently conflicted. They do share the same end state that the attacker hold an authenticated session token they shouldn’t have — but the attack model is fundamentally different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/0*Igj2jE6vhqRCtMxA.png" /></figure><p>The implication: hardening against hijacking does not protect against fixation. You can have HttpOnly, Secure, and short session lifetimes all correctly configured, and still be vulnerable to fixation if you don&#39;t rotate the session ID on login. They require independent mitigations.</p><h3>5. The discovery: two cookies, one problem</h3><p>Well, this is the phase where even i started exploring this more. I was doing recon on a local university’s student portal — managing personal data, grades and records. One finding was it was PHP-based, and a kind of a system which stood up in mid 2000s and been maintained on life support since. Usually while doing recon, i browse the website as an end user first and checking the requestsand known endpoints, what does a request send along (mostly using burp suite) — how they behave, what information do they send/receive.</p><p>What I found was a session management implementation, which in some ways made it harder to spot than a straightforwardly broken single-cookie setup.</p><h4>Observation 1</h4><p>Landing on /login, the server issued a standard pre-auth PHPSESSID. Common, expected behaviour — PHP initialises a session on first request to track pre-auth state (CSRF tokens etc.).</p><pre>HTTP — GET /erp/login (unauthenticated)<br># Request<br>GET /login HTTP/1.1<br>Host: portal.uni.com<br># Response<br>HTTP/1.1 200 OK<br>Set-Cookie: PHPSESSID=&quot;php_session_id&quot;; Path=/; HttpOnly</pre><h4>Observation 2</h4><p>After submitting valid credentials, the response issued two cookies. The original PHPSESSID was re sent with <strong>same value, not rotated</strong> — and a new cookie (auth_token) was also issued. Developers were aware to keep a separate authenticated session layer. But it just kicked to me, do they even validate this auth token?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ae6jlSdGX--xPHrp.png" /></figure><p>To confirm this, i deleted the auth_token from the request and send to /erp/homepage with only PHPSESSID present in request. And guess what the server returned full authenticated dashboard.<br> auth_token was not being validated anywhere in the authorization path. Every route just checked only PHPSESSID. The second cookie was issued, stored by browser but but but never read again by the server-side, never validated to get the authenticated routes.</p><ul><li>Bug 1 <strong>No session rotation on login (CWE-384).</strong> PHPSESSID is not regenerated after successful authentication. A pre-auth session is elevated to authenticated status with the same identifier. This is the textbook definition of session fixation vulnerability.</li><li>Bug 2 <strong>auth_token is never validated.</strong> The server issues a second cookie that implies a layered session model, but no authorization check ever requires it. Any request carrying a valid PHPSESSID is treated as authenticated regardless of whether auth_token is present, absent, or tampered.</li></ul><h3>6. Exploit delivery vectors</h3><blockquote>“The attack vectors described in this section are documented here for defensive purposes — so developers understand what they’re building against, and security teams understand what to look for in testing. All of these vectors are documented in public security literature including OWASP, CAPEC, and PortSwigger’s Web Security Academy.”</blockquote><p>For fixation to be exploitable, the attacker needs a mechanism to place a known session ID into the victim’s browser before they visit the login page. The attacker can be a legitimate user of the website, generate their own sessionID ( PHPSESSID) value and deliver that specific to the victim.</p><h4>Vector A — URL Parameter Injection</h4><p>You won’t find this usually in modern applications because this technique of session management is generally discouraged but who knows hitting a crack opens a treasure.</p><p>The backend systems in PHP contain a php.ini file which is the primary configuration file for PHP scripting language dictating how PHP behaves on a server by defining global settings, resource limits, security rules and configurations or maybe some kind of a file which is usually left untouched for long.<br> PHP uses a directive (configuration settings) called session.use_trans_sid that enables transparent session ID management. When enabled, PHP automatically appends the session id to URLs and forms incase client&#39;s browser doesn&#39;t support or has disabled cookies. The effect is that anyone who can control what URL a victim visits can fix their session ID.<br> Read more about php directives here:- <a href="https://www.php.net/manual/en/ini.list.php"><strong>ini.list</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/0*LimTK720-_yXleav.png" /></figure><p>If session.use_trans_sid is set to 1, it acepts session ID through URL. Now the attacks can follow the same attack sequence; get a valid session id from the website, construct a delivery URL embedding known session ID and deliver it to the victim via phishing email, whatsapp message or any other social engineering channel.<br> The URL would point to the real domain of university portal, no scope of detecting domain spoofing. Only anomaly would be the query parameter, which most users never look at or can be further obscured by using URL shortener or redirect chain.<br> There is no malicious domain. No lookalike URL. No unusual redirect. The link is to the real application. A savvy user inspecting the URL might notice the PHPSESSID parameter, but the majority of users — and most browser address bars on mobile — will not.</p><p><strong>Vector B — Subdomain XSS to Cross-Domain Cookie Injection</strong></p><p>Well this attack vector requires two conditions that aren’t always present but as usual worth checking: an XSS vulnerability somewhere on a subdomain of the target, and a PHPSESSID cookie that was issued with an explicit Domain=.uni.com attribute (leading dot — meaning it&#39;s valid across all subdomains).<br> Let&#39;s say any cookie set by library.uni.com will be sent to portal.uni.com as well. Javascript running on library.uni.com can set a cookie with that domain scope via document.cookie - and the browser will send it to main portal on next request, making the legitimate browser behaviour being abused.</p><p><em>Full subdomain XSS delivery Chain</em></p><pre>// e.g. https://library.uni.com/search?q=&lt;script&gt;PAYLOAD&lt;/script&gt;<br>// Step 1: Attacker visits portal.uni.com/login, receives their PHPSESSID<br>// Step 2: XSS payload on library subdomain plants that value into the shared cookie jar<br><br>document.cookie = [<br>    &quot;PHPSESSID=m0q4blfvtq4q02lv9v3k4a9piv&quot;,<br>    &quot;domain=.uni.com&quot;,  // scoped to parent domain and all subdomains<br>    &quot;path=/&quot;,<br>    &quot;SameSite=Lax&quot;<br>].join(&quot;; &quot;);<br><br>// Step 3: Silently redirect victim to the real portal login page<br>// Victim lands on the login page already carrying the attacker&#39;s session ID<br><br>window.location.replace(&quot;https://portal.uni.com/login&quot;);<br><br>// The replace() call avoids leaving the XSS URL in browser history</pre><p>The victim clicks on the link, gets forwarded to the portal login page, logs in normally and never see anything suspicious. For the attacker, as soon as the victim logs in, the attacker’s session gets changed to victim’s session and now they have full account access.</p><p><strong>Vector C — CRLF Injection / HTTP Response Splitting</strong></p><p>CRLF injection is a class of vulnerability where user-controlled input gets reflected into HTTP response headers without stripping carriage return (\r, URL-encoded as %0d) and line feed (\n, URL-encoded as %0a) characters. In HTTP/1.1, headers are delimited by CRLF sequences. If an attacker can inject a CRLF into a header value, they can terminate the current header and begin a new one — including Set-Cookie.</p><p>This vector doesn’t require JavaScript, doesn’t require XSS, and bypasses Content Security Policy entirely because it operates at the HTTP layer before the browser parses any HTML. The injected header arrives as part of a legitimate server response from the target domain.</p><p>This requires <br><strong>-&gt;</strong> an endpoint that reflects user-controlled input into a response header ( Location on a redirect, Content-Type or maybe some custom header )<br><strong> -&gt;</strong> A server-side framework that doesn&#39;t strip \r\n from the reflected value before writing to header.<br><strong> -&gt;</strong> The HTTP server itself doesn&#39;t sanitise headers before transmission (modern versions of Apache and Nginx do reject bare CR/LF in most contexts, but application-level header injection via language APIs may still work)</p><p><strong>The delivery chain</strong>: attacker sends the victim a link to portal.uni.com/redirect?url=.... The URL is on the real domain, so it passes URL inspection. The response from the server sets the cookie. The browser follows the redirect to wherever <a href="http://legit.com/">legit.com</a> points — possibly another page the attacker controls that instructs the victim to &quot;click here to log in,&quot; pointing to the real login page.</p><p>But but but, natively CRLF injection doesn’t work as described in HTTP/2 because headers are send as binary key-value pairs, not raw text. But (again, yes), Many applications still speak HTTP/1.1 between their load balancer and backend app server ( nginx -&gt; PHP over HTTP/1.1) — if CRLF injection affects the backend, it may still work.</p><p><strong>Vector D — Cookie Jar Overflow / Eviction Attack</strong></p><p>Least commonly documented but technically interesting vector. Browsers impose a maximum number of cookies per domain — typically around 50 in most modern browsers. When the limit is reached and a new cookie needs to be set, the browser evicts an existing one to make space. The eviction order varies by browser but generally follows a “least recently used” or “oldest” policy.</p><p>An attacker who can execute JavaScript on the target domain (or a shared domain) can flood the cookie jar with junk cookies until the legitimate PHPSESSID is evicted, then immediately set their own known value in the now-available slot.</p><pre>// Flood the cookie jar to trigger evicton of legitimate PHPSESSID<br>for(let i=0;i&lt;55;i++){<br>    document.cookie = `junk_${i}=x; path=/`;<br>}<br>// browser has evicted the cookies now, attacker hopes for PHPSESSID too<br>document.cookie = &quot;PHPSESSID=attacker&#39;s_cookie_here; path=/&quot;;<br><br>// clean up the junk cookies<br>for (let i = 0; i &lt; 55; i++) {<br>    document.cookie = `junk_${i}=; expires=Thu, 01 Jan 2027 00:00:00 GMT; path=/`;<br>}<br>//and redirect to login page <br>window.location.href = &quot;https://portal.uni.com/login&quot;;</pre><h4>Vector E — Open Redirect Chaining</h4><p>Open redirects are often dismissed as low-severity findings — “it just redirects somewhere, what’s the harm?” Session fixation is one concrete answer to that question. If the application has an open redirect endpoint, an attacker can use it as a two-hop delivery mechanism: the redirect first plants the session cookie (via CRLF or URL parameter), then bounces the victim to the real login page. The victim sees the real domain in the link they clicked, gets redirected to the real login page, and logs in normally.</p><blockquote><em>needs an open redirect endpoint on target domain — </em><em>/redirect?url= or </em><em>/go?to=, </em><em>/out?link= are used as common patterns</em></blockquote><blockquote><em>Either </em><em>use_trans_sid is on (so the session ID can be planted via URL), or the redirect endpoint is also CRLF-injectable (so a </em><em>Set-Cookie header can be injected into the redirect response)</em></blockquote><h4>Vector F — Login CSRF to Force-Authenticate with attacker session</h4><p>What happens sometimes is, if the website’s login endpoint accept POST requests from any origin without a CSRF token (or a predictable one) , an attacker can pre seed their own session ID into victim&#39;s browser via any earlier said mechanism ( say XSS for instance), then uses a CSRF-abled login to submit a login request for an attacker-controlled test account. The victim&#39;s browser logs into attacker&#39;s account but as the attacker&#39;s session is now in authenticated state, they realize they are not in their account and may log out and login again - but but but as the session ID is still not rotated, the same fixation pattern plays out again.</p><p><em>Summing up, this requires the victim to visit an attacker-controlled page while their browser has the attacker’s session ID set, and the login form is submittable cross-origin ( This is the catch where the devs might need to focus on ).</em><br> This can be called an edge-case chaining technique, but it demonstrates how missing CSRF protection on a login endpoint and missing session rotation combine into a compounding attack surface.</p><p><strong>We’ve have been discussing the attack vectors for a while now, what do you think could be some major observations ?</strong></p><p>-&gt; None of these vectors are blocked by HttpOnly or Secure alone . These prevent against theft of a cookie, not against planting a known cookie.</p><p>-&gt; Vector A — which included use_trans_sid is the most accessible attack vector for an attacker with no foothold on network or website. Just a phishing URL on the real domain.</p><p>-&gt; Most important one — no attack vector works if it is blocked by use_strict_mode .<br> use_strict_mode is a security setting that ensures the session module rejects unitialized session IDs and forces the creation of new, valid session ID.</p><blockquote><em>Basically with strict mode turned off, a user can decide which session ID they want to use.</em></blockquote><p><strong>Configuration:</strong> Recommended to be enabled in php.ini or via ini_set(&#39;session.use_strict_mode&#39;, 1);</p><p>The two-cookie detail is the part worth sitting with. Someone on that team was thinking about session security — enough to introduce a second token, scope it to /erp, set HttpOnly and Secure. The failure wasn&#39;t indifference. It was an incomplete implementation that was never audited end-to-end. The token was issued and forgotten. The original session was never rotated. And the combination of those two gaps produced something that looked more secure than a straightforwardly broken system while being functionally equivalent to one.</p><p>The entire chain from recon to authenticated access involves one HTTP request to confirm the vector, one email, and waiting for the victim to log in. The victim did nothing wrong — they visited the real domain, entered real credentials, and completed a normal login. The server did everything wrong.</p><h3>7. Standards &amp; classification</h3><p>Here’s the full mapping, useful if you’re writing this up as a pentest finding or submitting to a bug bounty programme.</p><blockquote><strong><em>According to OWASP ASVS MAPPING, this finding maps to ASVS V3.2.1 — “verify the application generates a new session token on user auth”<br> and to V3.3.1 — “ verify that logout and expiration invalidate the session token”. both of them being the Level 1 requirements. And yes, Level 1 is the baseline, the foundational requirement.</em></strong></blockquote><blockquote><strong><em>According to OWASP TOP 10 (2021), this primarily maps to </em></strong><strong><em>A07:2021 -&gt; </em></strong><strong><em>Identification and Authentication Failures</em></strong></blockquote><p>OWASP explicitly mentions “does not invalidate session IDs” as A07 failure example. Session fixation via non-rotation falls perfectly here.</p><blockquote><strong><em>Secondarily, this maps to </em></strong><strong><em>A05:2021 -&gt; </em></strong><strong><em>Security Misconfiguration</em></strong></blockquote><p>SameSite=None on a session cookie and the unvalidated auth_token are security misconfigurations — features either misconfigured or not fully implemented.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/0*BRrmX6ci7pCKzw-I.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/0*7w5088N4v1epB6U6.png" /></figure><pre><strong>#CVSS Score</strong></pre><pre>Attack Vector (AV):        Network    (N)   ← exploitable remotely<br>Attack Complexity (AC):    Low        (L)   ← no special conditions, no race<br>Privileges Required (PR):  None       (N)   ← attacker needs no prior access<br>User Interaction (UI):     Required   (R)   ← victim must complete login<br>Scope (S):                 Unchanged  (U)<br>Confidentiality (C):       High       (H)   ← full session access = all victim data<br>Integrity (I):             High       (H)   ← attacker can act as victim<br>Availability (A):          Low        (L)   ← session invalidation possible</pre><pre>Base Score:    8.0 — High</pre><h3>8. Remediation</h3><p>Let me walk you through how you can fix the probable issues we discusses above ( don’t get hoaxed for the cvss score, we’ll fix it)</p><h4>FIX 1 — Rotate Session ID on login</h4><pre>// VULNERABLE - what the application was doing<br>function login($username, $password) {<br>    if (verify_credentials($username, $password)) {<br>        $_SESSION[&#39;user&#39;] = $username;<br>        $_SESSION[&#39;authenticated&#39;] = true;<br>        // session_regenerate_id() never called<br>        // PHPSESSID stays the same — pre-auth session elevated as-is<br>    }<br>}<br>// CORRECT — regenerate on every privilege change<br>function login($username, $password) {<br>    if (verify_credentials($username, $password)) {<br>        session_regenerate_id(true);   // true = delete old session file server-side<br>        $_SESSION[&#39;user&#39;] = $username;<br>        $_SESSION[&#39;authenticated&#39;] = true;<br>    }<br>}</pre><blockquote><em>The </em><em>true argument to </em><em>session_regenerate_id() matters. Without it, the old session ID remains valid in the session store even after a new one is issued. An attacker who planted the old value could still use it. </em><em>true deletes the old session file entirely.</em></blockquote><h4>FIX 2 — Enforce AUTH_TOKEN on every protected route</h4><pre>function require_authenticated() {<br>    // 1: session must be authenticated<br>    if (empty($_SESSION[&#39;authenticated&#39;])) {<br>        redirect_to_login(); exit;<br>    }    <br>    // 2: auth_token must be present AND valid in the DB<br>    // Not just present — validated against the stored value for this user<br>    $token = $_COOKIE[&#39;auth_token&#39;] ?? null;<br>    if (!$token || !validate_auth_token($token, $_SESSION[&#39;user_id&#39;])) {<br>        session_destroy();<br>        redirect_to_login(); exit;<br>    }<br>}</pre><h4>Fix 3 — Harden PHP.INI Session config</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/0*VEG5RKIEGcO26kbg.png" /></figure><p>session.use_strict_mode = 1 is worth highlighting separately. PHP will reject any session ID not generated by the server in the current session. Even if an attacker delivers a crafted PHPSESSID via URL, the server will discard it and generate a fresh one — breaking the fixation model at the session engine level.<br> Enforcing server-side session expiry is also a great way of handling this. A session that never expires server-side is a session that can be used forever.</p><blockquote><em>session_destroy() </em><strong><em>on logout.</em></strong><em> Destroy the server-side session record not just the client-side control. An attacker who has fixed a session and whose victim has &quot;logged out&quot; via client-only cookie deletion would still hold a valid server-side session.</em></blockquote><h3>CONCLUSION</h3><p>Session fixation has been documented since at least 2002. It maps to a single missing function call. But still could be found sitting in a modern day website. Assumptions are where vulnerabilities live.</p><p>Session fixation is not a novel or sophisticated attack. It does not require a zero-day, a custom exploit. It requires one missing function call on the server, one phishing link, and patience.<br> Hopefully someone reading this checks their own php.ini before the next researcher has to.</p><p>Thank you for staying till the end. Open to feedbacks<br> Connect with me<br> <strong>X</strong> -&gt; <a href="https://x.com/sushobhitxd">sushobhitxd</a><br> <strong>LinkedIn</strong> -&gt;<a href="https://www.linkedin.com/in/sushobhit-goyal-xdxd/">sushobhit</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e888b880a298" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>