Cache-Control
The Cache-Control header holds directives (instructions) for caching in both requests and responses. From a security perspective, it is crucial for preventing sensitive information from being stored in shared caches or on local disks.
Why Cache-Control Matters for Security
If a web application serves sensitive data (like banking details, personal information, or session tokens) and does not explicitly disable caching, an intermediary proxy or the user's browser might store this data.
If the user is on a shared computer (e.g., in an internet cafe or a library), the next person to use that computer could hit the "Back" button or inspect the browser cache and view the previous user's sensitive data.
Basic Example
Cache-Control: no-store, max-age=0
This policy dictates that:
- no-store: Caches must not store any part of the request or response. This is the strongest directive against caching.
- max-age=0: If a cache does have a copy, it is immediately considered stale and must revalidate with the server.
Common Pitfalls
While `no-store` is great for security, applying it globally to all assets (like images, CSS, and JS) will severely degrade your website's performance. You should only apply strict no-cache headers to HTML pages or API endpoints that serve sensitive, user-specific data.
Check Your Header
Use the SecurityHeaders.nl scanner to verify if your application correctly implements modern HTTP security standards.