Skip to content

[Routing] document UriSigner::verify() #20905

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
Apr 21, 2025
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
24 changes: 22 additions & 2 deletions routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2810,10 +2810,30 @@ argument of :method:`Symfony\\Component\\HttpFoundation\\UriSigner::sign`::

The feature to add an expiration date for a signed URI was introduced in Symfony 7.1.

If you need to know the reason why a signed URI is invalid, you can use the
``verify()`` method which throws exceptions on failure::

use Symfony\Component\HttpFoundation\Exception\ExpiredSignedUriException;
use Symfony\Component\HttpFoundation\Exception\UnsignedUriException;
use Symfony\Component\HttpFoundation\Exception\UnverifiedSignedUriException;

// ...

try {
$uriSigner->verify($uri); // $uri can be a string or Request object

// the URI is valid
} catch (UnsignedUriException) {
// the URI isn't signed
} catch (UnverifiedSignedUriException) {
// the URI is signed but the signature is invalid
} catch (ExpiredSignedUriException) {
// the URI is signed but expired
}

.. versionadded:: 7.3

Starting with Symfony 7.3, signed URI hashes no longer include the ``/`` or
``+`` characters, as these may cause issues with certain clients.
The ``verify()`` method was introduced in Symfony 7.3.

Troubleshooting
---------------
Expand Down