---
title: "Keep private pages out of shared caches · Agent Wranglers"
url: https://agentwranglers.se/playbook/application-security/requests-files-and-caches/private-responses-uncached
id: APS-46
level: Required
applies: accounts
risk: data
updated: 2026-10-27
build: a2a6bdfed830
tokens: 1152
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Keep private pages out of shared caches

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Requests, files and caches](https://agentwranglers.se/playbook/application-security/requests-files-and-caches.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: APS-46
- Level: Required
- Chapter: [Requests, files and caches](https://agentwranglers.se/playbook/application-security/requests-files-and-caches.md)
- Rule: Mark every reply that depends on the logged-in user `Cache-Control: private`, and never let a CDN cache by file extension alone.
- Check: Logged in as a test user, request `/account/profile` and `/account/profile/x.css` through the CDN. Then request both again with no cookie. Neither reply without a cookie contains the test user's data. The profile reply carries `Cache-Control: private`, and the `x.css` address answers 404.
- Risk: Data leaked or lost
- Applies when: The project has user accounts.
- How: Set the header once in the middleware that loads the session, so no route can forget it. Use `private, no-cache` for ordinary account pages. Use `no-store` only for payment, health or identity pages, because it also blocks the [back/forward cache](https://agentwranglers.se/playbook/website/performance/bfcache.md). JSON answers from an API follow [API cache headers](https://agentwranglers.se/playbook/api-design/requests-and-responses/api-cache-headers.md). Configure the CDN to respect the origin's `Cache-Control`, and to skip caching when a request has a session cookie or an `Authorization` header. Return 404 for unknown paths under private routes, such as `/account/x.css`. This stops web cache deception, where a CDN stores a private page because its address ends in `.css`.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
app.use('/account', (req, res, next) => { res.set('Cache-Control', 'private, no-cache'); next(); });
```

### Python example

```python
@app.after_request
def private_cache(response):
    if request.path.startswith("/account"):
        response.headers["Cache-Control"] = "private, no-cache"
    return response
```

## Sources

- [RFC 9111 HTTP Caching, the private directive](https://www.rfc-editor.org/rfc/rfc9111#section-5.2.2.7)

## Related rules

- WEB-42 [Cache files for a year and pages briefly](https://agentwranglers.se/playbook/website/performance/cache-control.md) in Website
- WEB-53 [Keep the back button instant](https://agentwranglers.se/playbook/website/performance/bfcache.md) in Website
- WEB-227 [Serve the last good page when the server fails](https://agentwranglers.se/playbook/website/errors-and-outages/serve-stale-on-error.md) in Website
- API-14 [Set caching headers on every response](https://agentwranglers.se/playbook/api-design/requests-and-responses/api-cache-headers.md) in API design
- SCL-43 [Cache public pages at the edge for a few seconds](https://agentwranglers.se/playbook/scaling/caching/edge-micro-cache.md) in Scaling
- AGT-17 [Send cache hints and a stable order with every list](https://agentwranglers.se/playbook/agents-as-users/mcp-servers/list-cache-hints.md) in Agents as users
- MED-19 [Give every file version its own address](https://agentwranglers.se/playbook/files-and-media/serving-files/versioned-file-addresses.md) in Files and media
- APS-47 [Keep unkeyed headers from changing cached pages](https://agentwranglers.se/playbook/application-security/requests-files-and-caches/web-cache-poisoning.md) in Application security

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/application-security/requests-files-and-caches/private-responses-uncached">Agent Wranglers application security playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Unpack archives safely](https://agentwranglers.se/playbook/application-security/requests-files-and-caches/safe-archive-extraction.md)
- Next: [Keep unkeyed headers from changing cached pages](https://agentwranglers.se/playbook/application-security/requests-files-and-caches/web-cache-poisoning.md)
- [Requests, files and caches](https://agentwranglers.se/playbook/application-security/requests-files-and-caches.md)
