> 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/cookie-security.md). Agents can also search and read this documentation through its [MCP server](https://hacking-notes.jord4n.pro/~gitbook/mcp).

# Cookie Security Cheat Sheet: SameSite, HttpOnly and Scope

Cookie security checks for Secure, HttpOnly, SameSite, prefixes, domain and path scope, session fixation, cookie tossing and storage limits.

## Cookie Security — Cheat Sheet

{% hint style="info" %}
**What is Cookie Security?**

Cookies carry browser state according to their domain, path, and security attributes. Cookie security combines those attributes with server-side session handling; hiding a cookie from JavaScript does not prevent requests from using it.
{% endhint %}

<details open>

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

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

```http
Set-Cookie: sid=...; HttpOnly; Secure; SameSite=Lax; Path=/
```

{% endcode %}

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

```
Missing HttpOnly on session cookie
```

{% endcode %}

{% code title="transport exposure" overflow="wrap" %}

```
Missing Secure flag
```

{% endcode %}

{% code title="CSRF reachability" overflow="wrap" %}

```
SameSite=None; Secure (cross-site send enabled)
```

{% endcode %}

{% code title="implicit-default trap" overflow="wrap" %}

```powershell
Set-Cookie with no SameSite (browser default = Lax)
```

{% endcode %}

{% code title="token-lifetime review" overflow="wrap" %}

```
Expires/Max-Age far in the future on auth cookie
```

{% endcode %}

{% code title="Strict usability tradeoff" overflow="wrap" %}

```
SameSite=Strict on the session, separate Lax read cookie
```

{% endcode %}

</details>

<details open>

<summary>Cookie Prefixes &#x26; Hardening</summary>

{% code title="strongest cookie binding" overflow="wrap" %}

```http
Set-Cookie: __Host-sid=...; Secure; Path=/
```

{% endcode %}

{% code title="weaker prefix" overflow="wrap" %}

```http
Set-Cookie: __Secure-sid=...; Secure; Domain=example.com
```

{% endcode %}

{% code title="prefix enforcement check" overflow="wrap" %}

```
Strip a __Host- cookie's Secure flag and replay
```

{% endcode %}

{% code title="path is not a boundary" overflow="wrap" %}

```http
Set-Cookie: sid=...; Path=/admin (path scoping)
```

{% endcode %}

{% code title="leakage audit" overflow="wrap" %}

```
Compare cookie set on HTTPS vs accessible on HTTP
```

{% endcode %}

{% code title="third-party isolation" overflow="wrap" %}

```
Partitioned (CHIPS): Set-Cookie: id=...; Secure; SameSite=None; Partitioned
```

{% endcode %}

</details>

<details open>

<summary>Cookie Scoping &#x26; Domain Abuse</summary>

{% code title="overly broad scope" overflow="wrap" %}

```http
Set-Cookie: id=...; Domain=.example.com
```

{% endcode %}

{% code title="least-privilege scope" overflow="wrap" %}

```
Host-only cookie (no Domain attribute)
```

{% endcode %}

{% code title="upward scoping rule" overflow="wrap" %}

```
Set cookie on example.com from sub.example.com
```

{% endcode %}

{% code title="PSL / supercookie defense" overflow="wrap" %}

```
Attempt Domain=com / Domain=co.uk (public suffix)
```

{% endcode %}

{% code title="trust-zone mapping" overflow="wrap" %}

```
Shared cookie between app.example.com and login.example.com
```

{% endcode %}

{% code title="isolation verification" overflow="wrap" %}

```http
host:1.example.com vs 2.example.com cookie isolation
```

{% endcode %}

</details>

<details open>

<summary>Session Fixation</summary>

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

```
Capture sid pre-login, authenticate, compare sid
```

{% endcode %}

{% code title="URL-based fixation delivery" overflow="wrap" %}

```
https://app.example.com/?sessionid=KNOWN
```

{% endcode %}

{% code title="XSS-assisted fixation" overflow="wrap" %}

```javascript
document.cookie='sid=KNOWN' from XSS on a subdomain
```

{% endcode %}

{% code title="privilege-boundary rotation" overflow="wrap" %}

```
Test fixation after step-up / re-auth, not just login
```

{% endcode %}

{% code title="fixation via tossing" overflow="wrap" %}

```
Set a second cookie that shadows the real session
```

{% 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="scope precedence trick" overflow="wrap" %}

```
Set duplicate-name cookie at more specific Path to win precedence
```

{% endcode %}

{% code title="CRLF cookie injection" overflow="wrap" %}

```
Inject via header: param=val%0D%0ASet-Cookie:%20admin=1
```

{% endcode %}

{% code title="value delimiter injection" overflow="wrap" %}

```
name=val; injected=value (semicolon/comma in cookie value)
```

{% endcode %}

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

```
__Host- prefix to block tossing
```

{% endcode %}

{% code title="parser ambiguity probe" overflow="wrap" %}

```
Compare server parsing of multiple same-name cookies
```

{% endcode %}

</details>

<details open>

<summary>Cookie Jar Overflow &#x26; Eviction</summary>

{% code title="per-domain cap abuse" overflow="wrap" %}

```
Set 180+ junk cookies for a domain to evict the real one
```

{% endcode %}

{% code title="double-submit defeat" overflow="wrap" %}

```
Evict a __Host-CSRF token, leaving a stale tossed one
```

{% endcode %}

{% code title="size-limit DoS" overflow="wrap" %}

```
Exceed the ~4KB per-cookie size limit
```

{% endcode %}

{% code title="fallback-behavior test" overflow="wrap" %}

```
Overflow then observe whether the session falls back insecurely
```

{% endcode %}

{% code title="persistent DoS" overflow="wrap" %}

```
Cookie bomb across shared subdomain to break victim's site
```

{% 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/cookie-security.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.
