You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: http_client.rst
+22Lines changed: 22 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -694,6 +694,28 @@ called when new data is uploaded or downloaded and at least once per second::
694
694
Any exceptions thrown from the callback will be wrapped in an instance of
695
695
``TransportExceptionInterface`` and will abort the request.
696
696
697
+
SSRF (Server-side request forgery) Handling
698
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
699
+
700
+
[SSRF](https://portswigger.net/web-security/ssrf) allows an attacker to induce the backend application to make HTTP requests to an arbitrary domain. These attacks can also target the internal hosts and IPs of the attacked server.
701
+
702
+
If you use an ``HttpClient`` together with user-provided URIs, it is probably a good idea to decorate it with a ``NoPrivateNetworkHttpClient``. This will ensure local networks are made inaccessible to the HTTP client::
703
+
704
+
use Symfony\Component\HttpClient\HttpClient;
705
+
use Symfony\Component\HttpClient\NoPrivateNetworkHttpClient;
706
+
707
+
$client = new NoPrivateNetworkHttpClient(HttpClient::create());
708
+
// nothing changes when requesting public networks
709
+
$client->request('GET', 'https://example.com/');
710
+
711
+
// however, all requests to private networks are now blocked by default
712
+
$client->request('GET', 'http://localhost/');
713
+
714
+
// the second optional argument defines the networks to block
715
+
// in this example, requests from 104.26.14.0 to 104.26.15.255 will result in an exception
716
+
// but all the other requests, including other internal networks, will be allowed
717
+
$client = new NoPrivateNetworkHttpClient(HttpClient::create(), ['104.26.14.0/23']);
0 commit comments