Skip to content

Commit 9c4aee1

Browse files
committed
[Routing] document UriSigner::verify()
1 parent 50c531c commit 9c4aee1

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

Diff for: routing.rst

+27-2
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,11 @@ service, which you can inject in your services or controllers::
27632763
}
27642764
}
27652765

2766+
.. versionadded:: 7.3
2767+
2768+
Signed URI hashes no longer include the ``/`` or ``+`` characters, as these
2769+
may cause issues with certain clients, since Symfony 7.3.
2770+
27662771
For security reasons, it's common to make signed URIs expire after some time
27672772
(e.g. when using them to reset user credentials). By default, signed URIs don't
27682773
expire, but you can define an expiration date/time using the ``$expiration``
@@ -2810,10 +2815,30 @@ argument of :method:`Symfony\\Component\\HttpFoundation\\UriSigner::sign`::
28102815

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

2818+
If you need to know the reason why a signed URI is invalid, you can use the
2819+
``verify()`` method which throws exceptions on failure::
2820+
2821+
use Symfony\Component\HttpFoundation\Exception\ExpiredSignedUriException;
2822+
use Symfony\Component\HttpFoundation\Exception\UnsignedUriException;
2823+
use Symfony\Component\HttpFoundation\Exception\UnverifiedSignedUriException;
2824+
2825+
// ...
2826+
2827+
try {
2828+
$uriSigner->verify($uri); // $uri can be a string or Request object
2829+
2830+
// the URI is valid
2831+
} catch (UnsignedUriException) {
2832+
// the URI isn't signed
2833+
} catch (UnverifiedSignedUriException) {
2834+
// the URI is signed but the signature is invalid
2835+
} catch (ExpiredSignedUriException) {
2836+
// the URI is signed but expired
2837+
}
2838+
28132839
.. versionadded:: 7.3
28142840

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

28182843
Troubleshooting
28192844
---------------

0 commit comments

Comments
 (0)