Skip to content

Commit 7dec5b9

Browse files
authored
Add a mention of NoPrivateNetworkHttpClient and SSRF to the docs
1 parent 9e971f8 commit 7dec5b9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

http_client.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,28 @@ called when new data is uploaded or downloaded and at least once per second::
694694
Any exceptions thrown from the callback will be wrapped in an instance of
695695
``TransportExceptionInterface`` and will abort the request.
696696

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']);
718+
697719
Performance
698720
-----------
699721

0 commit comments

Comments
 (0)