The TrustedHosts check only seems to analyze a sites main settings.php, but should also check any included/required settings.php. Some service providers automatically populate the trusted_host_patterns in environment-specific settings files based on domain names entered into their admin UI.
OR better yet, leverage or re-use code from the Drupal core check (see below) that checks for the trusted_hosts_pattern in the active environment, rather than inside settings files. This was previous suggested by @acrosman: https://www.drupal.org/project/security_review/issues/2855840#comment-12...
From https://cgit.drupalcode.org/drupal/tree/core/modules/system/system.insta...
// See if trusted hostnames have been configured, and warn the user if they
// are not set.
if ($phase == 'runtime') {
$trusted_host_patterns = Settings::get('trusted_host_patterns');
if (empty($trusted_host_patterns)) {
Issue fork security_review-3008957
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:
- 3008957-refactor-host
changes, plain diff MR !28
- 3008957-refactor-trusted-hosts
changes, plain diff MR !1
Comments
Comment #4
ambient.impactI've added a first draft of using
\Drupal\Core\Site\Settings::get()to detecttrusted_host_patternsregardless of where or how it's set. I have a few questions:global $base_url;- is this okay or is there a better way to get this without tokenizing?Comment #5
ambient.impactComment #6
smustgrave commentedWonder with the addition https://www.drupal.org/project/security_review/issues/2581071 if that affects this solution.
Comment #7
smustgrave commentedComment #8
smustgrave commentedPostponing until https://www.drupal.org/project/security_review/issues/2581071 lands. But I think we can drop the settings for trusted all together and just use core.
So will need
Comment #10
smustgrave commentedMoved over credit from https://www.drupal.org/project/security_review/issues/3155650.
Comment #12
smustgrave commentedWas able to drop the settings form
Updated check to use Settings::get('trusted_host_patterns')
Deleted schema and config settings
Added update to hook to delete config value.
Comment #13
ednark commentedI have tested this and it functions as expected without errors.
Tested on 10.1.x-dev with a standard install
module drupal/security_review:2.0.x-dev@dev
branch 3008957-refactor-host
Test procedure:
Do not specify any trusted host patterns
run test to see "Trusted hosts are not set"
add trusted_host within main settings.php
run test to see "Trusted hosts are set"
remove trusted_host within main settings.php
add trusted host within secondary file included/required from settings.php
run test to see "Trusted hosts are set"
Comment #15
smustgrave commented