matomo-org / plugin-TrackingSpamPrevention

GNU General Public License v3.0
12 stars 7 forks source link

Do not try to use GeoIP database if UserCountry plugin is disabled #41

Closed MichaIng closed 2 years ago

MichaIng commented 2 years ago

If the UserCountry plugin is disabled, TrackingSpamPrevention still tries to get GeoIP info, which triggers the following error on every tracker request:

PHP Fatal error:  Uncaught TypeError: Piwik\Plugins\UserCountry\VisitorGeolocator::getLocationObject(): Argument #1 ($provider) must be of type Piwik\Plugins\UserCountry\LocationProvider, null given, called in /var/www/matomo/plugins/UserCountry/VisitorGeolocator.php on line 115 and defined in /var/www/matomo/plugins/UserCountry/VisitorGeolocator.php:143
Stack trace:
#0 /var/www/matomo/plugins/UserCountry/VisitorGeolocator.php(115): Piwik\Plugins\UserCountry\VisitorGeolocator->getLocationObject()
#1 /var/www/matomo/plugins/TrackingSpamPrevention/BlockedGeoIp.php(31): Piwik\Plugins\UserCountry\VisitorGeolocator->getLocation()
#2 /var/www/matomo/plugins/TrackingSpamPrevention/BlockedGeoIp.php(65): Piwik\Plugins\TrackingSpamPrevention\BlockedGeoIp->detectLocation()
#3 /var/www/matomo/plugins/TrackingSpamPrevention/TrackingSpamPrevention.php(134): Piwik\Plugins\TrackingSpamPrevention\BlockedGeoIp->isExcludedProvider()
#4 [internal function]: Piwik\Plugins\TrackingSpamPrevention\TrackingSpamPrevention->isExcludedVisit()
#5 /var/www/matomo/core/EventDispatcher.php(141): call_user_func_array()
#6 /var/www/matomo/core/Piwik.php(845): Piwik\EventDispatcher->postEvent()
#7 /var/www/matomo/core/Tracker/VisitExcluded.php(97): Piwik\Piwik::postEvent()
#8 /var/www/matomo/plugins/CoreHome/Tracker/VisitRequestProcessor.php(100): Piwik\Tracker\VisitExcluded->isExcluded()
#9 /var/www/matomo/core/Tracker/Visit.php(164): Piwik\Plugins\CoreHome\Tracker\VisitRequestProcessor->processRequestParams()
#10 /var/www/matomo/core/Tracker.php(160): Piwik\Tracker\Visit->handle()
#11 /var/www/matomo/core/Tracker/Handler.php(55): Piwik\Tracker->trackRequest()
#12 /var/www/matomo/core/Tracker.php(140): Piwik\Tracker\Handler->process()
#13 /var/www/matomo/core/Tracker.php(115): Piwik\Tracker->track()
#14 /var/www/matomo/piwik.php(73): Piwik\Tracker->main()
#15 /var/www/matomo/matomo.php(13): include('...')
#16 {main}
  thrown in /var/www/matomo/plugins/UserCountry/VisitorGeolocator.php on line 143

It must not be tried to access the GeoIP database if none is configured or the plugin disabled.

tsteur commented 2 years ago

Thanks for this @MichaIng . That would only happen currently if cloud providers are blocked, and UserCountry is disabled.

We could simply adjust BlockedGeoIp::isExcludedProvider to not run if UserCountry plugin is disabled (Plugin\Manager::getInstance()->isPluginActivated('UserCountry')).

MichaIng commented 2 years ago

That would only happen currently if cloud providers are blocked, and UserCountry is disabled.

Yes that is true.

We could simply adjust BlockedGeoIp::isExcludedProvider to not run if UserCountry plugin is disabled

šŸ‘