@@ -772,6 +772,36 @@ Alternatively, you can also disable ``verify_host`` and ``verify_peer`` (see
772772:ref: `http_client config reference <reference-http-client >`), but this is not
773773recommended in production.
774774
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+
775805Performance
776806-----------
777807
@@ -1052,7 +1082,7 @@ This behavior provided at destruction-time is part of the fail-safe design of th
10521082component. No errors will be unnoticed: if you don't write the code to handle
10531083errors, exceptions will notify you when needed. On the other hand, if you write
10541084the 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
10561086remaining to do.
10571087
10581088Concurrent Requests
@@ -1876,3 +1906,4 @@ test it in a real application::
18761906.. _`Server-sent events` : https://html.spec.whatwg.org/multipage/server-sent-events.html
18771907.. _`EventSource` : https://www.w3.org/TR/eventsource/#eventsource
18781908.. _`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