Skip to content

[FrameworkBundle] Add support to set BinaryFileResponse::trustXSendfileTypeHeader over config #45724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CHANGELOG
* Add `cache:pool:invalidate-tags` command
* Add `xliff` support in addition to `xlf` for `XliffFileDumper`
* Deprecate the `reset_on_message` config option. It can be set to `true` only and does nothing now
* Add `trust_x_sendfile_type_header` option

6.0
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public function getConfigTreeBuilder(): TreeBuilder
->info("Set true to enable support for the '_method' request parameter to determine the intended HTTP method on POST requests. Note: When using the HttpCache, you need to call the method in your front controller instead")
->defaultTrue()
->end()
->scalarNode('trust_x_sendfile_type_header')
->info('Set true to enable support for xsendfile in binary file responses.')
->defaultFalse()
->end()
->scalarNode('ide')->defaultValue('%env(default::SYMFONY_IDE)%')->end()
->booleanNode('test')->end()
->scalarNode('default_locale')->defaultValue('en')->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public function load(array $configs, ContainerBuilder $container)
}

$container->setParameter('kernel.http_method_override', $config['http_method_override']);
$container->setParameter('kernel.trust_x_sendfile_type_header', $config['trust_x_sendfile_type_header']);
$container->setParameter('kernel.trusted_hosts', $config['trusted_hosts']);
$container->setParameter('kernel.default_locale', $config['default_locale']);
$container->setParameter('kernel.enabled_locales', $config['enabled_locales']);
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
use Symfony\Component\Form\DependencyInjection\FormPass;
use Symfony\Component\HttpClient\DependencyInjection\HttpClientPass;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
Expand Down Expand Up @@ -95,6 +96,10 @@ public function boot()
if ($this->container->getParameter('kernel.http_method_override')) {
Request::enableHttpMethodParameterOverride();
}

if ($this->container->getParameter('kernel.trust_x_sendfile_type_header')) {
BinaryFileResponse::trustXSendfileTypeHeader();
}
}

public function build(ContainerBuilder $container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
</xsd:choice>

<xsd:attribute name="http-method-override" type="xsd:boolean" />
<xsd:attribute name="trust-x-sendfile-type-header" type="xsd:boolean" />
<xsd:attribute name="ide" type="xsd:string" />
<xsd:attribute name="secret" type="xsd:string" />
<xsd:attribute name="default-locale" type="xsd:string" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ protected static function getBundleDefaultConfig()
{
return [
'http_method_override' => true,
'trust_x_sendfile_type_header' => false,
'ide' => '%env(default::SYMFONY_IDE)%',
'default_locale' => 'en',
'enabled_locales' => [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
],
],
'http_method_override' => false,
'trust_x_sendfile_type_header' => true,
'esi' => [
'enabled' => true,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config secret="s3cr3t" ide="file%%link%%format" default-locale="fr" http-method-override="false">
<framework:config secret="s3cr3t" ide="file%%link%%format" default-locale="fr" http-method-override="false" trust-x-sendfile-type-header="true">
<framework:enabled-locale>fr</framework:enabled-locale>
<framework:enabled-locale>en</framework:enabled-locale>
<framework:csrf-protection />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ framework:
csrf_protection:
field_name: _csrf
http_method_override: false
trust_x_sendfile_type_header: true
esi:
enabled: true
ssi:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ public function testHttpMethodOverride()
$this->assertFalse($container->getParameter('kernel.http_method_override'));
}

public function testTrustXSendfileTypeHeader()
{
$container = $this->createContainerFromFile('full');

$this->assertTrue($container->getParameter('kernel.trust_x_sendfile_type_header'));
}

public function testEsi()
{
$container = $this->createContainerFromFile('full');
Expand Down