- Issue created by @kvo_4x
- π³π±Netherlands batigolix Utrecht
@kvo_4x can you provide step by step instructions on how to replicate this error?
I am facing the same issue with the shield on. https://www.drupal.org/project/shield β
Simply enable the shield alongside with flood_control
I can also confirm this issue happens with Flood Control and Drupal Shield module enabled, using Drupal 10.2.6. Doesn't seem to occur in Drupal 10.1.8.
This seems to be due to the isIpWhitelisted function trying to call the flood_control_get_whitelist_ips function that is defined in the flood_control.module file:
<?php ... protected function isIpWhitelisted(string $ipAddress = ''): bool { $request = $this->requestStack->getCurrentRequest(); if ($request && !$ipAddress) { $ipAddress = $request->getClientIp() ?? ''; } // Gets the values from the config. $ipsWhiteList = flood_control_get_whitelist_ips(); ..... ?>
it seems to be failing to resolve that particular function when called from that location. Oddly enough, in Form/FloodControlSettingsForm.php, the code does a similar call:
<?php ... public function validateForm(array &$form, FormStateInterface $form_state) { // Validating whitelisted ip addresses. $whitelistIps = flood_control_get_whitelist_ips($form_state->getValue('ip_white_list')); // Checking single ip addresses. if (!empty($whitelistIps['addresses'])) { foreach ($whitelistIps['addresses'] as $ipAddress) { if (!filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) { $form_state->setErrorByName('ip_white_list', $this->t('IP address %ip_address is not valid.', ['%ip_address' => $ipAddress])); } } } ..... ?>
But that one does NOT cause an error.
The error seems to partly stem from the namespace causing PHP to look in the wrong spot, IE its looking for Drupal\flood_control\flood_control_get_whitelist_ips(), but since that function isn't in the Drupal/flood_control namespace, it fails. However, I did try doing something like:
<?php ... protected function isIpWhitelisted(string $ipAddress = ''): bool { .... $ipsWhiteList = \flood_control_get_whitelist_ips(); .... ?>
But it results in essentially the same error (and I'm not sure if that is even that way to go about that anyways).
I'm not sure whether this is an issue with the flood control module itself, or some issue introduced by core that is causing this issue with resolving the function.
- πΊπ¦Ukraine vselivanov Kyiv, Ukraine
Hi!
Have the same error. It happens because shield middleware do it's job before modules are loaded. It calls authenticate and flood whitelist checks, but there is no flood_control_get_whitelist_ips() function yet.This patch to the shield module helped me:
https://www.drupal.org/project/shield/issues/3277210#comment-15104934 π Shield middleware invokes hooks before modules are loaded, corrupting module_implements cache Needs work - Status changed to Closed: works as designed
6 months ago 2:45am 17 June 2024 - π¦πΊAustralia elc
This very much sounds like a bug in Shield rather than Flood Control - there's no way functionality will exist if the modules haven't been loaded yet! It is outside the bounds of reason for a module to ensure that a file that is always loaded is loaded in every situation.
Looking at what Shield does, it would be better to use Apache/Nginx for the HTTP auth so that the site underneath is not loaded at all until valid credentials are provided.
Anyway, this is not a bug for this module.