|
| 1 | +.. |
| 2 | + SPDX-FileCopyrightText: SPDX-FileCopyrightText: 2026 William Woodruff |
| 3 | +
|
| 4 | + SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +======================= |
| 7 | +Security Considerations |
| 8 | +======================= |
| 9 | + |
| 10 | +HTTP caching is a security-sensitive operation. Improper caching and use |
| 11 | +of cached data can introduce security vulnerabilities into otherwise secure |
| 12 | +applications. |
| 13 | + |
| 14 | +This page will help you decide if you *can* use CacheControl securely |
| 15 | +in your application, and if so, how to do so. |
| 16 | + |
| 17 | +CacheControl's security model |
| 18 | +============================= |
| 19 | + |
| 20 | +CacheControl's security model is based on the following assumptions: |
| 21 | + |
| 22 | +* CacheControl provides a **private** cache. This means that both shared |
| 23 | + *and* private responses are cached, and the cache is assumed to be accessible only |
| 24 | + to a single logical user. You **cannot** use CacheControl securely |
| 25 | + in a multi-user environment where cached data may be shared between |
| 26 | + different logical users. **Do not** use CacheControl for this; |
| 27 | + it **will** end badly for you. |
| 28 | + |
| 29 | +* You **must** treat cached data as potentially sensitive. CacheControl |
| 30 | + does not natively encrypt or otherwise protect cached data. If an attacker |
| 31 | + can read your cache, they can read all cached responses. You must |
| 32 | + ensure that your cache storage is protected appropriately for the |
| 33 | + sensitivity of the data you are caching. Another framing of this is that |
| 34 | + CacheControl **assumes** the security of your cache storage, similar to |
| 35 | + how browsers assume the security of your local machine for the purpose |
| 36 | + of storing history, cookies, and cached data. |
| 37 | + |
| 38 | +* You **must** trust the origins (i.e., servers) |
| 39 | + you are communicating with. A malicious origin can always send |
| 40 | + you malicious responses, which in the context of caching can mean |
| 41 | + sending you cacheable responses that you don't expect, spamming you |
| 42 | + with cache entries, and so on. In practice, this means that you must |
| 43 | + also trust your transport layer; if you use HTTP, any |
| 44 | + adversary on your network path can tamper with your connected |
| 45 | + origin's responses, and CacheControl has no way to protect you from that. |
| 46 | + |
| 47 | +Conversely, here are some assumptions that CacheControl **does** attempt |
| 48 | +to enforce; violating these assumptions would be a security vulnerability in |
| 49 | +CacheControl itself: |
| 50 | + |
| 51 | +* An attacker should not be able to trick CacheControl into caching across |
| 52 | + origins. For example, an attacker who controls ``evil.example.com`` |
| 53 | + should not be able to trick CacheControl into caching responses for |
| 54 | + ``bank.example.com``. |
| 55 | + |
| 56 | +* An attacker should not be able to trick CacheControl into serving cached |
| 57 | + responses to requests that would not normally receive those cached |
| 58 | + responses. For example, an attacker should not be able to trick |
| 59 | + CacheControl into serving a cached response to an unauthenticated |
| 60 | + request when the cached response was originally received in response |
| 61 | + to an authenticated request. |
| 62 | + |
| 63 | +Reporting security issues |
| 64 | +========================= |
| 65 | + |
| 66 | +.. important:: |
| 67 | + |
| 68 | + Please make sure to read the security model above before reporting |
| 69 | + issues. Reports that don't take the security model into account will |
| 70 | + be considered invalid. |
| 71 | + |
| 72 | +We take security reports very seriously, and aim to address them as quickly |
| 73 | +as possible. |
| 74 | + |
| 75 | +Please use GitHub's `security advisory process`_ to report security issues. |
| 76 | + |
| 77 | +.. _security advisory process: https://github.com/psf/cachecontrol/security/advisories/new |
0 commit comments