10up/restricted-site-access

PHP Fatal Error when using IP restriction

pablojmarti opened this issue · 1 comments

Describe the bug
It seems that when the site is configured to restrict access to IPs and the IP trying to access the site is not in the list, we will get a PHP Fatal error.

Steps to Reproduce

  1. Install restricted-site-access and activate
  2. From the Settings -> Reading page configure Site visibility to "Restrict site access to visitors who are logged in or allowed by IP address"
  3. Configure Handle Restricted visitors to "Send them to the WordPress login screen"

Expected behavior
When trying to access the site from a restricted IP address we should be redirected to the wp-login.php page and instead, we see an error page. In the logs I can see the following error when this happens:

PHP Fatal error:  Uncaught Error: Class 'IPLib\Factory' not found in /var/app/current/wp-content/plugins/restricted-site-access/restricted_site_access.php:1512
Stack trace:
#0 /var/app/current/wp-content/plugins/restricted-site-access/restricted_site_access.php(377): Restricted_Site_Access::ip_in_range('24.161.13.165', '208.38.246.107')
#1 /var/app/current/wp-content/plugins/restricted-site-access/restricted_site_access.php(313): Restricted_Site_Access::restrict_access_check(Object(WP))
#2 /var/app/current/wp-includes/class-wp-hook.php(307): Restricted_Site_Access::restrict_access(Object(WP))
#3 /var/app/current/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array)
#4 /var/app/current/wp-includes/plugin.php(524): WP_Hook->do_action(Array)
#5 /var/app/current/wp-includes/class-wp.php(398): do_action_ref_array('parse_request', Array)
#6 /var/app/current/wp-includes/class-wp.php(770): WP->parse_request('')
#7 /var/app/current/wp-includes/functions.php(1330): WP->main('')
#8 /var/app/current/wp-blog-header.php(16): in /var/app/current/wp-content/plugins/restricted-site-access/restricted_site_access.php on line 1512

Environment information

  • Server OS: Amazon Linux 2/3.5.1
  • PHP Version: 7.4.30
  • Restricted Site Access version: 7.3.4

@pablojmarti Thanks for the report. I was not able to reproduce this myself but there is a potential scenario I'm thinking of that could cause problems. Would you be able to provide me with a list of plugins that you're using?

The error you're seeing is related to the IPLib dependency that we recently added. If you're using a plugin that also uses that same dependency, there's potential for conflicts there. There's a few ways for us to fix that but wanted to be able to fully reproduce that first.