@@ -2617,6 +2617,47 @@ defined as annotations:
2617
2617
:doc: `another way to enforce HTTP or HTTPS </security/force_https >`
2618
2618
via the ``requires_channel `` setting.
2619
2619
2620
+ Signing URIs
2621
+ ~~~~~~~~~~~~
2622
+
2623
+ A signed URI is an URI that includes a hash value that depends on the contents of
2624
+ the URI. This way, you can later check the integrity of the signed URI by
2625
+ recomputing its hash value and comparing it with the original hash.
2626
+
2627
+ Symfony provides a utility to sign URIs, no matter if you generated them yourself
2628
+ with the methods explained above or if they were given to you. The utility is
2629
+ implemented in the :class: `Symfony\\ Component\\ HttpKernel\\ UriSigner ` service,
2630
+ which you can inject in your services or controllers::
2631
+
2632
+ // src/Service/SomeService.php
2633
+ namespace App\Service;
2634
+
2635
+ use Symfony\Component\HttpKernel\UriSigner;
2636
+
2637
+ class SomeService
2638
+ {
2639
+ public function __construct(
2640
+ private UriSigner $uriSigner,
2641
+ ) {
2642
+ }
2643
+
2644
+ public function someMethod()
2645
+ {
2646
+ // ...
2647
+
2648
+ // generate a URL youself or get it somehow...
2649
+ $url = 'https://example.com/foo/bar?sort=desc';
2650
+
2651
+ // sign the URL (it adds a query parameter called '_hash')
2652
+ $signedUrl = $this->uriSigner->sign($url);
2653
+ // $url = 'https://example.com/foo/bar?sort=desc&_hash=e4a21b9'
2654
+
2655
+ // check the URL signature
2656
+ $uriSignatureIsValid = $this->uriSigner->check($signedUrl);
2657
+ // $uriSignatureIsValid = true
2658
+ }
2659
+ }
2660
+
2620
2661
Troubleshooting
2621
2662
---------------
2622
2663
0 commit comments