Skip to content

[Security] [LoginLink] Add technical details #17872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions security/login_link.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ intercept requests to this route:
throw new \LogicException('This code should never be reached');
}
}

.. code-block:: php-attributes

// src/Controller/SecurityController.php
namespace App\Controller;

Expand Down Expand Up @@ -428,6 +428,13 @@ The signed URL contains 3 parameters:
properties. Whenever these change, the hash changes and previous login
links are invalidated.

For a user that returns ``user@example.com`` on ``$user->getUserIdentifier()``
call, the generated login link looks like this:

.. code-block:: text

http://example.com/login_check?user=user@example.com&expires=1675707377&hash=f0Jbda56Y...A5sUCI~TQF701fwJ...7m2n4A~

You can add more properties to the ``hash`` by using the
``signature_properties`` option:

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

Hashing Strategy
~~~~~~~~~~~~~~~~

Internally, the :class:`Symfony\\Component\\Security\\Http\\LoginLink\\LoginLinkHandler`
implementation uses the
:class:`Symfony\\Component\\Security\\Core\\Signature\\SignatureHasher` to create the
hash contained in the login link.

This hasher creates a first hash with the expiration
date of the link, the values of the configured signature properties and the
user identifier. The used hashing algorithm is SHA-256.

Once this first hash is processed and encoded in Base64, a new one is created
from the first hash value and the ``kernel.secret`` container parameter. This
allows Symfony to sign this final hash, which is contained in the login URL.
The final hash is also a Base64 encoded SHA-256 hash.

Customizing the Success Handler
-------------------------------

Expand Down