Skip to content

Commit

Permalink
Clearly warn against computing algorithms from the token’s alg (#647)
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Loading branch information
andersk authored Apr 28, 2021
1 parent fb86f9d commit 7f6a236
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 12 additions & 0 deletions docs/algorithms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,15 @@ of allowed algorithms:
In the above case, if the JWT has any value for its alg header other than
HS512 or HS256, the claim will be rejected with an ``InvalidAlgorithmError``.

.. warning::

Do **not** compute the ``algorithms`` parameter based on the
``alg`` from the token itself, or on any other data that an
attacker may be able to influence, as that might expose you to
various vulnerabilities (see `RFC 8725 §2.1
<https://www.rfc-editor.org/rfc/rfc8725.html#section-2.1>`_). Instead,
either hard-code a fixed value for ``algorithms``, or configure it
in the same place you configure the ``key``. Make sure not to mix
symmetric and asymmetric algorithms that interpret the ``key`` in
different ways (e.g. HS\* and RS\*).
15 changes: 12 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ API Reference

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

.. note:: It is highly recommended to specify the expected ``algorithms``.

.. note:: It is insecure to mix symmetric and asymmetric algorithms because they require different kinds of keys.
.. warning::

Do **not** compute the ``algorithms`` parameter based on
the ``alg`` from the token itself, or on any other data
that an attacker may be able to influence, as that might
expose you to various vulnerabilities (see `RFC 8725 §2.1
<https://www.rfc-editor.org/rfc/rfc8725.html#section-2.1>`_). Instead,
either hard-code a fixed value for ``algorithms``, or
configure it in the same place you configure the
``key``. Make sure not to mix symmetric and asymmetric
algorithms that interpret the ``key`` in different ways
(e.g. HS\* and RS\*).

:param dict options: extended decoding and validation options

Expand Down

0 comments on commit 7f6a236

Please sign in to comment.