Deprecated function: trim(): Passing null to parameter #1 ($string) in AutobanController.php

Created on 23 January 2023, over 1 year ago
Updated 25 June 2024, 4 days ago

After updating to 8.x-1.8 every time cron triggers autoban (once a minute) I get (2) identical Debug reports in Dblog.

Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\autoban\Controller\AutobanController->getBannedIp() (line 54 of /var/www/html/web/modules/contrib/autoban/src/Controller/AutobanController.php)

Full message as follows:
#0 /var/www/html/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(8192, 'trim(): Passing...', '/var/www/html/w...', 54)
#1 [internal function]: _drupal_error_handler(8192, 'trim(): Passing...', '/var/www/html/w...', 54)
#2 /var/www/html/web/modules/contrib/autoban/src/Controller/AutobanController.php(54): trim(NULL)
#3 /var/www/html/web/modules/contrib/autoban/src/AutobanBatch.php(24): Drupal\autoban\Controller\AutobanController->getBannedIp('rule1')
#4 /var/www/html/web/modules/contrib/autoban/autoban.module(50): Drupal\autoban\AutobanBatch::ipBan('rule1', Array)
#5 [internal function]: autoban_cron()
#6 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(417): call_user_func_array(Object(Closure), Array)
#7 /var/www/html/web/modules/contrib/simple_cron/src/Plugin/SimpleCron/Cron.php(70): Drupal\Core\Extension\ModuleHandler->invoke('autoban', 'cron')
#8 /var/www/html/web/modules/contrib/simple_cron/src/Entity/CronJob.php(326): Drupal\simple_cron\Plugin\SimpleCron\Cron->process()
#9 /var/www/html/web/modules/contrib/simple_cron/src/SimpleCron.php(102): Drupal\simple_cron\Entity\CronJob->run(1674506041, false)
#10 /var/www/html/web/modules/contrib/simple_cron/src/ProxyClass/SimpleCron.php(70): Drupal\simple_cron\SimpleCron->run()
#11 /var/www/html/web/core/modules/system/src/CronController.php(46): Drupal\simple_cron\ProxyClass\SimpleCron->run()
#12 [internal function]: Drupal\system\CronController->run()
#13 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#14 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#15 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#16 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#17 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#19 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(191): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(128): Drupal\page_cache\StackMiddleware\PageCache->fetch(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(82): Drupal\page_cache\StackMiddleware\PageCache->lookup(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /var/www/html/web/modules/contrib/advban/src/AdvbanMiddleware.php(57): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /var/www/html/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\advban\AdvbanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(713): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#31 {main}

It appears to be coming from from the merge listed in autoban/issues/3314098
the line number in question is directly related to that issue as it was added when I compared that patch code to the v 1.8

Having found that I was hoping by setting the new setting "Default window" would at least make the notice stop but it doesn't after setting "Default window to: 1 hour ago", clearing cache and all the typical things anyone would normally check doesn't help.

To test in regards to the new feature, I commented that line (54) $window = trim($entity->window);as well as line 144-147 (the new $date addition, where $window was used from line 54) $date = strtotime($window); if ($date) { $query->condition('log.timestamp', $date, '>='); } for the "default window function" stops the error from logging, however I assume that would negate the use of the new feature resulting in autoban's previous behavior which was to just check the entire dblog against set rules.
(which for me is fine - I personally don't use advance ban to let blocked IP's expire as 99.9999% of the IP's my rules ban for are people trying to hack-in as if was a wordpress website) so I just block everything related to wordpress no questions asked "banned for life".. anyway..

For good measure this is on Drupal 9.5.2, PHP 8.1.13, MySQL v 5.7.40 and Apache 2.4.38

If you need any other information please let me know.

πŸ› Bug report
Status

Needs review

Version

1.9

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States sidgrafix

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @sidgrafix
  • Can confirm. Same error for me.
    I have core ban module activated.

    -----------------------------
    Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\autoban\Controller\AutobanController->getBannedIp() (line 54 of /code/web/modules/contrib/autoban/src/Controller/AutobanController.php)
    #0 /code/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(8192, 'trim(): Passing...', '/code/web/modul...', 54)
    #1 [internal function]: _drupal_error_handler(8192, 'trim(): Passing...', '/code/web/modul...', 54)
    #2 /code/web/modules/contrib/autoban/src/Controller/AutobanController.php(54): trim(NULL)
    #3 /code/web/modules/contrib/autoban/src/AutobanBatch.php(24): Drupal\autoban\Controller\AutobanController->getBannedIp('rule8')
    #4 /code/web/modules/contrib/autoban/autoban.module(50): Drupal\autoban\AutobanBatch::ipBan('rule8', Array)
    #5 [internal function]: autoban_cron(Object(Drupal\ultimate_cron\Entity\CronJob))
    #6 /code/web/modules/contrib/ultimate_cron/src/Entity/CronJob.php(325): call_user_func('autoban_cron', Object(Drupal\ultimate_cron\Entity\CronJob))
    #7 /code/web/modules/contrib/ultimate_cron/src/Entity/CronJob.php(471): Drupal\ultimate_cron\Entity\CronJob->invokeCallback()
    #8 /code/web/modules/contrib/ultimate_cron/src/Plugin/ultimate_cron/Launcher/SerialLauncher.php(213): Drupal\ultimate_cron\Entity\CronJob->run(Object(Drupal\Core\StringTranslation\TranslatableMarkup))
    #9 /code/web/modules/contrib/ultimate_cron/src/Plugin/ultimate_cron/Launcher/SerialLauncher.php(334): Drupal\ultimate_cron\Plugin\ultimate_cron\Launcher\SerialLauncher->launch(Object(Drupal\ultimate_cron\Entity\CronJob))
    #10 /code/web/modules/contrib/ultimate_cron/src/Plugin/ultimate_cron/Launcher/SerialLauncher.php(309): Drupal\ultimate_cron\Plugin\ultimate_cron\Launcher\SerialLauncher->runThread('222908', 1, Array)
    #11 /code/web/modules/contrib/ultimate_cron/src/UltimateCron.php(64): Drupal\ultimate_cron\Plugin\ultimate_cron\Launcher\SerialLauncher->launchJobs(Array)
    #12 /code/web/modules/contrib/ultimate_cron/src/ProxyClass/UltimateCron.php(70): Drupal\ultimate_cron\UltimateCron->run()
    #13 /code/web/core/modules/automated_cron/src/EventSubscriber/AutomatedCron.php(65): Drupal\ultimate_cron\ProxyClass\UltimateCron->run()
    #14 [internal function]: Drupal\automated_cron\EventSubscriber\AutomatedCron->onTerminate(Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
    #15 /code/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
    #16 /code/vendor/symfony/http-kernel/HttpKernel.php(103): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...')
    #17 /code/vendor/stack/builder/src/Stack/StackedHttpKernel.php(32): Symfony\Component\HttpKernel\HttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\big_pipe\Render\BigPipeResponse))
    #18 /code/web/core/lib/Drupal/Core/DrupalKernel.php(697): Stack\StackedHttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\big_pipe\Render\BigPipeResponse))
    #19 /code/web/index.php(22): Drupal\Core\DrupalKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\big_pipe\Render\BigPipeResponse))
    #20 {main}
    ---------------------------------

    Drupal 9.5.2 - PHP 8.1.14 - 10.4.25-MariaDB-log

  • πŸ‡ΊπŸ‡¦Ukraine goodboy Kharkiv, Ukraine

    Fixed in dev version, please test

  • Still same message using Drupal 9.5.3 and the dev version

  • πŸ‡ΊπŸ‡ΈUnited States sidgrafix

    @goodboy

    Tested against dev version:

    The initial error: Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\autoban\Controller\AutobanController->getBannedIp() (line 54 of /var/www/html/web/modules/contrib/autoban/src/Controller/AutobanController.php)
    --> is gone

    However this brings on the new error I mentioned (after my initial test by commenting out the new feature at line 54)

    as well as line 144-147 (the new $date addition, where $window was used from line 54) $date = strtotime($window); if ($date) { $query->condition('log.timestamp', $date, '>='); }

    which is:
    Deprecated function: strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated in Drupal\autoban\Controller\AutobanController->getBannedIp() (line 144 of /var/www/html/web/modules/contrib/autoban/src/Controller/AutobanController.php)

    I'm adding a patch I created for myself for version 1.8 (Note: this basically disables the newly added feature)

    • goodboy β†’ committed f7835f3e on 8.x-1.x
      Issue #3335947 by sidgrafix, binkdot5: Deprecated function: trim():...
  • πŸ‡ΊπŸ‡¦Ukraine goodboy Kharkiv, Ukraine

    @sidgrafix, I tried to keep the window feature and made a comit again, Please test

  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine goodboy Kharkiv, Ukraine
  • πŸ‡ΊπŸ‡ΈUnited States sidgrafix

    @goodboy

    Tested against dev version appears to take care of the errors that were previously being logged each time Autoban is triggered by cron.

    However after reviewing your commit I'm not entirely sure this actually solves the underlying problem...
    $window = !empty($entity->window) ? trim($entity->window) : NULL; appears to just make it so $window "if empty" will not be passed therefor if ($window) { $date = strtotime($window); if ($date) { $query->condition('log.timestamp', $date, '>='); }} won't run, as there is no $window set, thus no errors are logged.

    Maybe I'm wrong, but I did have the new setting set "Default window" to 1 hour ago in Autoban settings when the change was introduced and I was getting the error notices. I think the underlying problem is elsewhere before $window = !empty($entity->window) ? trim($entity->window) : NULL; is even evaluated (at least for what I'm seeing) - but maybe I'm wrong. I haven't had time or tried to backtrack thru the code to find out were $entity->window should be coming from to confirm anything.

    This does absolutely stop the errors from being logged, but I'm not entirely sure the actual features functions are working! So I figured I'd mention it.

  • Just update and run cron, no errors showing as of yet so seems to have fixed the issue. Many Thanks

  • πŸ‡«πŸ‡·France quimic Paris

    I get the debug messages (Drupal 9.5.9) but I cannot seem to apply the #5 patch. It gets rejected.

  • Assigned to koston022
  • Hello. I added condition for $entity->referer to fix Deprecated function: trim(): Passing null to parameter.

    $referer = !empty($entity->referer) ? trim($entity->referer) : NULL;

Production build 0.69.0 2024