> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/cheat-sheets/authentication-sessions/session-attacks.md). Agents can also search and read this documentation through its [MCP server](https://hacking-notes.jord4n.pro/~gitbook/mcp).

# Session Attacks Cheat Sheet: Fixation, Tokens and Logout Checks

Session security tests for fixation, predictable identifiers, cookie scope, token rotation, logout invalidation and session lifecycle flaws.

## Session Attacks — Cheat Sheet

{% hint style="info" %}
**What are Session Attacks?**

Session attacks exploit weaknesses in how an application creates, binds, rotates, or invalidates login state. A session identifier must remain secret and unpredictable, and its server-side privileges must reflect the user's current authentication state.
{% endhint %}

<details open>

<summary>Session Fixation</summary>

{% code title="core fixation test" overflow="wrap" %}

```
Set a known session ID before login, then authenticate
```

{% endcode %}

{% code title="delivery of the fixed ID" overflow="wrap" %}

```http
Cookie: SESSIONID=attacker_known_value
```

{% endcode %}

{% code title="confirmation step" overflow="wrap" %}

```
Compare SESSIONID before vs after login
```

{% endcode %}

</details>

<details open>

<summary>Weak &#x26; Predictable Session IDs</summary>

{% code title="randomness analysis" overflow="wrap" %}

```
Collect 100+ tokens and analyze entropy (Burp Sequencer)
```

{% endcode %}

{% code title="structure inspection" overflow="wrap" %}

```
Decode the token (base64 / hex)
```

{% endcode %}

{% code title="predictability test" overflow="wrap" %}

```
Increment/decrement a numeric session or 'remember-me' token
```

{% endcode %}

</details>

<details open>

<summary>Cookie Attributes &#x26; Scope</summary>

{% code title="the secure default" overflow="wrap" %}

```http
Set-Cookie: id=...; HttpOnly; Secure; SameSite=Lax
```

{% endcode %}

{% code title="XSS impact amplifier" overflow="wrap" %}

```
Check for missing HttpOnly on the session cookie
```

{% endcode %}

{% code title="scope abuse" overflow="wrap" %}

```
Domain=.example.com (overly broad scope)
```

{% endcode %}

{% code title="pairs with CSRF testing" overflow="wrap" %}

```
SameSite=None — test CSRF reachability
```

{% endcode %}

</details>

<details open>

<summary>Cookie Injection &#x26; Tossing</summary>

{% code title="subdomain trust abuse" overflow="wrap" %}

```javascript
document.cookie='session=evil; domain=.example.com; path=/'
```

{% endcode %}

{% code title="the hardening fix" overflow="wrap" %}

```
__Host-session=...; Secure; Path=/ (no Domain)
```

{% endcode %}

{% code title="edge-case DoS/logic" overflow="wrap" %}

```
Send many junk cookies to evict the real one (cookie jar overflow)
```

{% endcode %}

</details>

<details open>

<summary>Logout &#x26; Invalidation</summary>

{% code title="broken server-side invalidation" overflow="wrap" %}

```
Replay the session token after clicking logout
```

{% endcode %}

{% code title="session-not-revoked" overflow="wrap" %}

```
Use an old token after a password change
```

{% endcode %}

{% code title="JWT-specific pitfall" overflow="wrap" %}

```
Reuse a JWT after 'logout'
```

{% endcode %}

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/cheat-sheets/authentication-sessions/session-attacks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
