#2221699: HTTP_HOST header cannot be trusted will enable the Symfony trusted host mechanism as an opt-in protection, configured from settings.php. If the setting is empty, the trusted host mechanism is not enabled.
The initial trusted host settings should be set in the installer, either automatically, or through an additional setting on the CONFIGURE SITE step of the process.
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | allow_trusted_hosts_to-20404259-35.patch | 5.43 KB | purencool |
| #34 | allow_trusted_hosts_to-20404259-34.patch | 5.43 KB | purencool |
| #34 | Screenshot 2023-09-04 at 3.47.02 PM.png | 35.94 KB | purencool |
| #20 | interdiff-2404259-2-20.txt | 1.16 KB | jacobsanford |
| #20 | allow_trusted_hosts_to-20404259-20.patch | 833 bytes | jacobsanford |
Issue fork drupal-2404259
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
mpdonadioParent issue was committed, so setting this Active. Initial patch for discussion purposes will be coming later tonight.
Comment #2
mpdonadioOk, here is a starting point. This hunk was removed from #2221699: HTTP_HOST header cannot be trusted. It presets the trusted host to the one that the web installer was run as.
Comment #4
dawehnerI guess we want to add some test coverage for that bit of code as well.
Comment #6
iantresman commentedBeing bold setting this to critical, but having just installed beta 15, my status reports shows that the "Trusted Host Settings" is "Not enabled". This is surely critical as it states:
Isn't this trivial to configure in the installer, by setting "trusted_host_patterns" in settings.php to the base URL, and localhost?
Comment #7
platinum1 commentedI assume a lot of people won't be happy with a new critical so close to the intended RC1 release date, but this is a great usability improvement, especially for those new to Drupal.
Comment #8
tim.plunkettThis is not a security issue, and calling it a security improvement is borderline. I'd say this is a feature request, but leaving for now.
Also all patches are against the dev branch, we can't change beta15.
Comment #9
mpdonadio#6, the discussion of why this wasn't part of the installer starts at #2221699-58: HTTP_HOST header cannot be trusted and picks up again at #2221699-112: HTTP_HOST header cannot be trusted. The main issue has to do with local/remote workflows.
The only other option that I can think of is to add a checkbox w/ message that enables/disables the logic in the patch in #2.
Comment #10
c-logemannI'd like to have a possibility for configuring the trusted host at install process. But it should be optional for several reasons I can imagine.
On a second step it would be fine if this setting is changeable. There could be a textfield where the actual host can used as default value.
Another idea is a support for CLI installation. But for this it's easy to create a drush command based on site-alias domain setting.
Comment #11
aaronbaumanRTBC +1
Also: this really feels like a UX bug.
The current situation is directly opposed with D8's goals for increasing adoption and improving UX.
Immediately upon install, every user will be faced with the menacing error message
"One or more problems were detected with your Drupal installation."
Then, upon clicking through, they're sent to an esoteric explanation of a complex topic, with the actual solution buried 2 screens down.
All this confusion could have been avoided if the installer had simply detected or asked what the user to provide a base url.
Comment #15
dkre commentedYeah I have to agree with #11.
Ideally you shouldn't need to google a problem as soon as you've installed new software.
Yes there is a help message: "The trusted_host_patterns setting is not configured in settings.php." but at first contact (with Drupal) the user won't know where this file is or what it's for. A red error message will make them feel like something is very wrong and will likely assume their installation process, hosting config or something external to the software is possibly creating a conflict or is at fault.
If trusted_hosts being unset isn't a problem or should be optional then surely it makes sense to remove the warning/error and lower the warning level on the status page notification to prevent users thinking their installation is broken or they're doing something wrong.
Comment #16
aaronbaumanMore than a year since Drupal 8 stable dropped, and still the first thing a new admin sees is a bright red error message.
Maybe changing this issue to a UX bug will get it some more attention.
Comment #17
cilefen commentedI agree this doesn't look good on installs but I can't commit it without regression tests.
Comment #18
alexpottWe also need to bear in my mind that a fair few hosters don't allow settings.php to be written during an install. See parts of #2156401: Write install_profile value to configuration and only to settings.php if it is writeable for a long and big discussion of this.
Comment #19
cilefen commentedThank you, everyone, for working on this issue. @alexpott, @catch, @cottser, @xjm and I considered this issue and agreed this should be a major priority task in the install system.
Comment #20
jacobsanfordThe patch in #1 no longer applied to 8.4.x. A reroll with no further modifications is attached.
Comment #22
donquixote commentedI agree with the issue.
But what we describe and agree on the intended behavior, and add it to the issue summary, before posting patches?
I think it is important that a user sees what will be registered as trusted host pattern.
I don't think the installer should do this silently.
Easy solution
Provide a checkbox in the installer: "Only allow requests from detected.hostname.com. This setting can later be changed in the settings.php under $settings['trusted_host_patterns']."
The checkbox could be enabled by default.
Advanced solution
Let the installer show a form element, where a user can define which hosts should be trusted.
This should be pre-filled with the host from the current request.
It could be a textarea, where each line is a host.
Initially, this will not use regular expressions, but the plain host as-is. So it would say "example.com", not "^example\.com$".
There could be a checkbox or something to switch this to regular expression mode.
But maybe this is not even needed. People who need those could do it in settings.php directly.
Add a description / help text, explaining that this will be converted into a regular expression in the settings.php, allowing to add additional trusted hosts later.
Comment #34
purencool commentedThe attached patch serves as a proof of concept to extend the functionality of the installer's SiteConfigureForm.php class. It enables the site installer to easily add domains to the trusted_host_patterns found in the settings.php file. The idea came from comment #22 which is mentioned below.
Initial Criteria
In order to ensure a developer-friendly experience while maintaining usability for first-time Drupal installation, I have compiled the following criteria for consideration:
Current solution
The installation screen

Results in the settings.php
Know Issues
I'm currently experiencing difficulty in finding a solution to prevent two "\\" from being written into the settings.php in the trusted_host_patterns array. It appears that the SettingsEditor::rewrite applies a regular expression and adds an another forward slash. However, it is not clear to me how this happens.
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
The second main issue relates to the permission settings of the settings.php file. During the installation process, the code requires write permissions to be granted. However, it is necessary to overwrite the existing permissions using PHP and then reset them again so that the trusted_host_patterns array can write to the file. I can't seem to find another solution to resolve this without changing the permissions and don't know if it's good practice.
Comment #35
purencool commentedThe bot didn't recognize "recognise" in the translation strings.