@@ -784,6 +784,36 @@ Alternatively, you can also disable ``verify_host`` and ``verify_peer`` (see
784
784
:ref: `http_client config reference <reference-http-client >`), but this is not
785
785
recommended in production.
786
786
787
+ SSRF (Server-side request forgery) Handling
788
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
789
+
790
+ .. versionadded :: 5.1
791
+
792
+ The SSRF protection was introduced in Symfony 5.1.
793
+
794
+ `SSRF `_ allows an attacker to induce the backend application to make HTTP
795
+ requests to an arbitrary domain. These attacks can also target the internal
796
+ hosts and IPs of the attacked server.
797
+
798
+ If you use an ``HttpClient `` together with user-provided URIs, it is probably a
799
+ good idea to decorate it with a ``NoPrivateNetworkHttpClient ``. This will
800
+ ensure local networks are made inaccessible to the HTTP client::
801
+
802
+ use Symfony\Component\HttpClient\HttpClient;
803
+ use Symfony\Component\HttpClient\NoPrivateNetworkHttpClient;
804
+
805
+ $client = new NoPrivateNetworkHttpClient(HttpClient::create());
806
+ // nothing changes when requesting public networks
807
+ $client->request('GET', 'https://example.com/');
808
+
809
+ // however, all requests to private networks are now blocked by default
810
+ $client->request('GET', 'http://localhost/');
811
+
812
+ // the second optional argument defines the networks to block
813
+ // in this example, requests from 104.26.14.0 to 104.26.15.255 will result in an exception
814
+ // but all the other requests, including other internal networks, will be allowed
815
+ $client = new NoPrivateNetworkHttpClient(HttpClient::create(), ['104.26.14.0/23']);
816
+
787
817
Performance
788
818
-----------
789
819
@@ -1074,7 +1104,7 @@ This behavior provided at destruction-time is part of the fail-safe design of th
1074
1104
component. No errors will be unnoticed: if you don't write the code to handle
1075
1105
errors, exceptions will notify you when needed. On the other hand, if you write
1076
1106
the error-handling code (by calling ``$response->getStatusCode() ``), you will
1077
- opt-out from these fallback mechanisms as the destructor won't have anything
1107
+ opt-out from these fallback mechanisms as the destructor won't have anything
1078
1108
remaining to do.
1079
1109
1080
1110
Concurrent Requests
@@ -1910,3 +1940,4 @@ test it in a real application::
1910
1940
.. _`Server-sent events` : https://html.spec.whatwg.org/multipage/server-sent-events.html
1911
1941
.. _`EventSource` : https://www.w3.org/TR/eventsource/#eventsource
1912
1942
.. _`idempotent method` : https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods_and_web_applications
1943
+ .. _`SSRF` : https://portswigger.net/web-security/ssrf
0 commit comments