Skip to content

[FrameworkBundle][HttpKernel] Add support for SYMFONY_TRUSTED_PROXIES, SYMFONY_TRUSTED_HEADERS, SYMFONY_TRUST_X_SENDFILE_TYPE_HEADER and SYMFONY_TRUSTED_HOSTS env vars #58161

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 1 commit into from
Sep 25, 2024

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Sep 3, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
Issues #40906
License MIT

Adding support for SYMFONY_TRUSTED_PROXIES, SYMFONY_TRUSTED_HEADERS, SYMFONY_TRUST_X_SENDFILE_TYPE_HEADER and SYMFONY_TRUSTED_HOSTS env vars.

This PR proposes making the default configuration rely on these env var when the corresponding config options are not set.

This should make it easier to package or deploy Symfony apps together with a pre-configured web-server or reverse-proxy.

@@ -745,11 +745,30 @@ private function preBoot(): ContainerInterface
$container = $this->container;

if ($container->hasParameter('kernel.trusted_hosts') && $trustedHosts = $container->getParameter('kernel.trusted_hosts')) {
Request::setTrustedHosts($trustedHosts);
Request::setTrustedHosts(\is_array($trustedHosts) ? $trustedHosts : preg_split('/\s*+,\s*+(?![^{]*})/', $trustedHosts));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this check that the parameter is a string before using preg_split on it ? Especially during booting, we need the code to be robust against unexpected parameter values (an old cache with an unsupported parameter might prevent you from running cache:clear in the prod environment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't do it for the other parameters so I didn't bother

@nicolas-grekas nicolas-grekas force-pushed the hk-trusted-env-vars branch 2 times, most recently from f2433c0 to f838316 Compare September 17, 2024 10:49
@nicolas-grekas
Copy link
Member Author

PR ready ;)

…S`, `SYMFONY_TRUSTED_HEADERS`, `SYMFONY_TRUST_X_SENDFILE_TYPE_HEADER` and `SYMFONY_TRUSTED_HOSTS` env vars
@fabpot
Copy link
Member

fabpot commented Sep 25, 2024

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 902c7d9 into symfony:7.2 Sep 25, 2024
8 of 10 checks passed
@nicolas-grekas nicolas-grekas deleted the hk-trusted-env-vars branch September 26, 2024 11:11
nicolas-grekas added a commit that referenced this pull request Oct 4, 2024
…ereguiluz)

This PR was squashed before being merged into the 7.2 branch.

Discussion
----------

[FrameworkBundle] Simplify the configuration class

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Spotted while documenting #58161.

Commits
-------

429fc32 [FrameworkBundle] Simplify the configuration class
@fabpot fabpot mentioned this pull request Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants