Skip to content

Commit 344a3f6

Browse files
authored
Add a security section to the docs (#409)
1 parent 900b4e6 commit 344a3f6

File tree

5 files changed

+132
-18
lines changed

5 files changed

+132
-18
lines changed

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ format:
1919

2020
doc: $(VENV)/bin/sphinx-build
2121
. $(ACTIVATE) && \
22-
cd docs && \
23-
make html
22+
make -C docs html
2423

2524
clean: clean-build clean-pyc clean-test
2625

docs/hacking.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
=======================
2+
Hacking on CacheControl
3+
=======================
4+
5+
CacheControl is a pure Python library. We use uv_ to manage its development.
6+
7+
Linting and Formatting
8+
======================
9+
10+
We use Ruff_ and mypy_ for linting/formatting and type checking. You can run
11+
them with:
12+
13+
.. code-block:: console
14+
15+
$ make lint
16+
$ make format
17+
18+
Tests
19+
=====
20+
21+
The tests are all in ``cachecontrol/tests`` and are runnable by ``py.test``.
22+
23+
You can use ``make test`` to run the tests:
24+
25+
.. code-block:: console
26+
27+
$ make test
28+
29+
Documentation
30+
=============
31+
32+
The documentation is built with Sphinx_. You can build it by running
33+
``make doc``:
34+
35+
.. code-block:: console
36+
37+
$ make doc
38+
39+
.. _uv: https://docs.astral.sh/uv/
40+
.. _Ruff: https://docs.astral.sh/ruff/
41+
.. _mypy: https://mypy-lang.org/
42+
.. _Sphinx: https://www.sphinx-doc.org/

docs/index.rst

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ requirements. See :doc:`storage` for more info.
3434
Quick Start
3535
===========
3636

37+
.. important::
38+
39+
You **must** read the :doc:`security` page before using CacheControl.
40+
3741
For the impatient, here is how to get started using CacheControl:
3842

3943
.. code-block:: python
@@ -52,25 +56,11 @@ For the impatient, here is how to get started using CacheControl:
5256
This uses a thread-safe in-memory dictionary for storage.
5357

5458

55-
Tests
56-
=====
57-
58-
The tests are all in ``cachecontrol/tests`` and are runnable by ``py.test``.
59-
60-
6159
Disclaimers
6260
===========
6361

64-
CacheControl is relatively new and might have bugs. I have made an
65-
effort to faithfully port the tests from httplib2 to CacheControl, but
66-
there is a decent chance that I've missed something. Please file bugs
67-
if you find any issues!
68-
69-
With that in mind, CacheControl has been used successfully in
70-
production environments, replacing httplib2's usage.
71-
72-
If you give it a try, please let me know of any issues.
73-
62+
HTTP caching comes with important security considerations. Please
63+
read the :doc:`security` page for more information.
7464

7565
.. _httplib2: https://github.com/httplib2/httplib2
7666
.. _requests: https://requests.readthedocs.io/en/latest/
@@ -89,12 +79,14 @@ Contents
8979
etags
9080
custom_heuristics
9181
tips
82+
security
9283

9384
.. toctree::
9485
:hidden:
9586
:caption: Development
9687
:maxdepth: 2
9788

89+
hacking
9890
release_notes
9991
GitHub <https://github.com/psf/cachecontrol>
10092
PyPI <https://pypi.org/project/cachecontrol>

docs/security.rst

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

docs/usage.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
Using CacheControl
88
====================
99

10+
.. important::
11+
12+
You **must** read the :doc:`security` page before using CacheControl.
13+
1014
CacheControl assumes you are using a `requests.Session` for your
1115
requests. If you are making ad-hoc requests using `requests.get` then
1216
you probably are not terribly concerned about caching.

0 commit comments

Comments
 (0)