@@ -379,16 +379,16 @@ method might be vulnerable to some of these attacks because it depends on
379
379
the configuration of your web server. One simple solution to avoid these
380
380
attacks is to whitelist the hosts that your Symfony application can respond
381
381
to. That's the purpose of this ``trusted_hosts `` option. If the incoming
382
- request's hostname doesn't match one in this list, the application won't
383
- respond and the user will receive a 500 response.
382
+ request's hostname doesn't match one of the regular expressions in this list,
383
+ the application won't respond and the user will receive a 400 response.
384
384
385
385
.. configuration-block ::
386
386
387
387
.. code-block :: yaml
388
388
389
389
# app/config/config.yml
390
390
framework :
391
- trusted_hosts : ['example.com', 'example.org']
391
+ trusted_hosts : ['^ example\ .com$ ', '^ example\ .org$ ']
392
392
393
393
.. code-block :: xml
394
394
@@ -402,8 +402,8 @@ respond and the user will receive a 500 response.
402
402
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
403
403
404
404
<framework : config >
405
- <framework : trusted-host >example.com</framework : trusted-host >
406
- <framework : trusted-host >example.org</framework : trusted-host >
405
+ <framework : trusted-host >^ example\ .com$ </framework : trusted-host >
406
+ <framework : trusted-host >^ example\ .org$ </framework : trusted-host >
407
407
<!-- ... -->
408
408
</framework : config >
409
409
</container >
@@ -412,17 +412,17 @@ respond and the user will receive a 500 response.
412
412
413
413
// app/config/config.php
414
414
$container->loadFromExtension('framework', array(
415
- 'trusted_hosts' => array('example.com', 'example.org'),
415
+ 'trusted_hosts' => array('^ example\ .com$ ', '^ example\ .org$ '),
416
416
));
417
417
418
- Hosts can also be configured using regular expressions (e.g. `` ^(.+\.)?example.com$ ``),
419
- which make it easier to respond to any subdomain .
418
+ Hosts can also be configured to respond to any subdomain, via
419
+ `` ^(.+\.)?example\.com$ `` for instance .
420
420
421
421
In addition, you can also set the trusted hosts in the front controller
422
422
using the ``Request::setTrustedHosts() `` method::
423
423
424
424
// web/app.php
425
- Request::setTrustedHosts(array('^(.+\.)?example.com$', '^(.+\.)?example.org$'));
425
+ Request::setTrustedHosts(array('^(.+\.)?example\ .com$', '^(.+\.)?example\ .org$'));
426
426
427
427
The default value for this option is an empty array, meaning that the application
428
428
can respond to any given host.
0 commit comments