Skip to content

Commit f1380f4

Browse files
committed
Merge branch '5.3' into 5.4
* 5.3: Tweaks Add a mention of NoPrivateNetworkHttpClient and SSRF to the docs
2 parents d0c3598 + 244d498 commit f1380f4

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

http_client.rst

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,36 @@ Alternatively, you can also disable ``verify_host`` and ``verify_peer`` (see
784784
:ref:`http_client config reference <reference-http-client>`), but this is not
785785
recommended in production.
786786

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+
787817
Performance
788818
-----------
789819

@@ -1074,7 +1104,7 @@ This behavior provided at destruction-time is part of the fail-safe design of th
10741104
component. No errors will be unnoticed: if you don't write the code to handle
10751105
errors, exceptions will notify you when needed. On the other hand, if you write
10761106
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
10781108
remaining to do.
10791109

10801110
Concurrent Requests
@@ -1910,3 +1940,4 @@ test it in a real application::
19101940
.. _`Server-sent events`: https://html.spec.whatwg.org/multipage/server-sent-events.html
19111941
.. _`EventSource`: https://www.w3.org/TR/eventsource/#eventsource
19121942
.. _`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

Comments
 (0)