Skip to content

Commit 7f6a236

Browse files
authored
Clearly warn against computing algorithms from the token’s alg (jpadilla#647)
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
1 parent fb86f9d commit 7f6a236

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

docs/algorithms.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,15 @@ of allowed algorithms:
5757
5858
In the above case, if the JWT has any value for its alg header other than
5959
HS512 or HS256, the claim will be rejected with an ``InvalidAlgorithmError``.
60+
61+
.. warning::
62+
63+
Do **not** compute the ``algorithms`` parameter based on the
64+
``alg`` from the token itself, or on any other data that an
65+
attacker may be able to influence, as that might expose you to
66+
various vulnerabilities (see `RFC 8725 §2.1
67+
<https://www.rfc-editor.org/rfc/rfc8725.html#section-2.1>`_). Instead,
68+
either hard-code a fixed value for ``algorithms``, or configure it
69+
in the same place you configure the ``key``. Make sure not to mix
70+
symmetric and asymmetric algorithms that interpret the ``key`` in
71+
different ways (e.g. HS\* and RS\*).

docs/api.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,18 @@ API Reference
2828

2929
:param list algorithms: allowed algorithms, e.g. ``["ES256"]``
3030

31-
.. note:: It is highly recommended to specify the expected ``algorithms``.
32-
33-
.. note:: It is insecure to mix symmetric and asymmetric algorithms because they require different kinds of keys.
31+
.. warning::
32+
33+
Do **not** compute the ``algorithms`` parameter based on
34+
the ``alg`` from the token itself, or on any other data
35+
that an attacker may be able to influence, as that might
36+
expose you to various vulnerabilities (see `RFC 8725 §2.1
37+
<https://www.rfc-editor.org/rfc/rfc8725.html#section-2.1>`_). Instead,
38+
either hard-code a fixed value for ``algorithms``, or
39+
configure it in the same place you configure the
40+
``key``. Make sure not to mix symmetric and asymmetric
41+
algorithms that interpret the ``key`` in different ways
42+
(e.g. HS\* and RS\*).
3443

3544
:param dict options: extended decoding and validation options
3645

0 commit comments

Comments
 (0)