@@ -772,6 +772,36 @@ Alternatively, you can also disable ``verify_host`` and ``verify_peer`` (see
772
772
:ref: `http_client config reference <reference-http-client >`), but this is not
773
773
recommended in production.
774
774
775
+ SSRF (Server-side request forgery) Handling
776
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
777
+
778
+ .. versionadded :: 5.1
779
+
780
+ The SSRF protection was introduced in Symfony 5.1.
781
+
782
+ `SSRF `_ allows an attacker to induce the backend application to make HTTP
783
+ requests to an arbitrary domain. These attacks can also target the internal
784
+ hosts and IPs of the attacked server.
785
+
786
+ If you use an ``HttpClient `` together with user-provided URIs, it is probably a
787
+ good idea to decorate it with a ``NoPrivateNetworkHttpClient ``. This will
788
+ ensure local networks are made inaccessible to the HTTP client::
789
+
790
+ use Symfony\Component\HttpClient\HttpClient;
791
+ use Symfony\Component\HttpClient\NoPrivateNetworkHttpClient;
792
+
793
+ $client = new NoPrivateNetworkHttpClient(HttpClient::create());
794
+ // nothing changes when requesting public networks
795
+ $client->request('GET', 'https://example.com/');
796
+
797
+ // however, all requests to private networks are now blocked by default
798
+ $client->request('GET', 'http://localhost/');
799
+
800
+ // the second optional argument defines the networks to block
801
+ // in this example, requests from 104.26.14.0 to 104.26.15.255 will result in an exception
802
+ // but all the other requests, including other internal networks, will be allowed
803
+ $client = new NoPrivateNetworkHttpClient(HttpClient::create(), ['104.26.14.0/23']);
804
+
775
805
Performance
776
806
-----------
777
807
@@ -1052,7 +1082,7 @@ This behavior provided at destruction-time is part of the fail-safe design of th
1052
1082
component. No errors will be unnoticed: if you don't write the code to handle
1053
1083
errors, exceptions will notify you when needed. On the other hand, if you write
1054
1084
the error-handling code (by calling ``$response->getStatusCode() ``), you will
1055
- opt-out from these fallback mechanisms as the destructor won't have anything
1085
+ opt-out from these fallback mechanisms as the destructor won't have anything
1056
1086
remaining to do.
1057
1087
1058
1088
Concurrent Requests
@@ -1876,3 +1906,4 @@ test it in a real application::
1876
1906
.. _`Server-sent events` : https://html.spec.whatwg.org/multipage/server-sent-events.html
1877
1907
.. _`EventSource` : https://www.w3.org/TR/eventsource/#eventsource
1878
1908
.. _`idempotent method` : https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods_and_web_applications
1909
+ .. _`SSRF` : https://portswigger.net/web-security/ssrf
0 commit comments