Skip to content

Commit a2f8e23

Browse files
committed
minor #17872 [Security] [LoginLink] Add technical details (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [Security] [LoginLink] Add technical details Fixes #17139 Although a bit technical, I think it's a good idea to give a bit of details to the reader on this kind of subject. If the reader needs more information and is more curious, the linked classes will be there to guide him through the good parts of the code 👍 Commits ------- 9309628 [LoginLink] Add technical details
2 parents 9d5ffbe + 9309628 commit a2f8e23

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

security/login_link.rst

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ intercept requests to this route:
111111
throw new \LogicException('This code should never be reached');
112112
}
113113
}
114-
114+
115115
.. code-block:: php-attributes
116-
116+
117117
// src/Controller/SecurityController.php
118118
namespace App\Controller;
119119
@@ -428,6 +428,13 @@ The signed URL contains 3 parameters:
428428
properties. Whenever these change, the hash changes and previous login
429429
links are invalidated.
430430

431+
For a user that returns ``user@example.com`` on ``$user->getUserIdentifier()``
432+
call, the generated login link looks like this:
433+
434+
.. code-block:: text
435+
436+
http://example.com/login_check?user=user@example.com&expires=1675707377&hash=f0Jbda56Y...A5sUCI~TQF701fwJ...7m2n4A~
437+
431438
You can add more properties to the ``hash`` by using the
432439
``signature_properties`` option:
433440

@@ -673,6 +680,23 @@ user create this POST request (e.g. by clicking a button)::
673680
</form>
674681
{% endblock %}
675682

683+
Hashing Strategy
684+
~~~~~~~~~~~~~~~~
685+
686+
Internally, the :class:`Symfony\\Component\\Security\\Http\\LoginLink\\LoginLinkHandler`
687+
implementation uses the
688+
:class:`Symfony\\Component\\Security\\Core\\Signature\\SignatureHasher` to create the
689+
hash contained in the login link.
690+
691+
This hasher creates a first hash with the expiration
692+
date of the link, the values of the configured signature properties and the
693+
user identifier. The used hashing algorithm is SHA-256.
694+
695+
Once this first hash is processed and encoded in Base64, a new one is created
696+
from the first hash value and the ``kernel.secret`` container parameter. This
697+
allows Symfony to sign this final hash, which is contained in the login URL.
698+
The final hash is also a Base64 encoded SHA-256 hash.
699+
676700
Customizing the Success Handler
677701
-------------------------------
678702

0 commit comments

Comments
 (0)