rtCamp / nginx-helper

Nginx Helper for WordPress caching, permalinks & efficient file handling in multisite
https://wordpress.org/plugins/nginx-helper/
224 stars 117 forks source link

Fatal Error on Empty Redis Port Setting in Nginx Helper Plugin #333

Closed gagan0123 closed 2 months ago

gagan0123 commented 2 months ago

Describe the bug In the Nginx Helper plugin, enabling purge with "Redis Cache" as the "Caching Method" and saving the Redis settings with an empty port leads to a site crash. Any attempts to save settings or initiate a purge thereafter cause a fatal PHP error due to a type mismatch in the port argument.

To Reproduce Steps to reproduce the behavior:

  1. Go to the Nginx Helper plugin settings.
  2. Enable purge and select "Redis Cache" as the "Caching Method".
  3. Save the Redis settings with the port field empty.
  4. Try saving any subsequent settings or perform a purge.
  5. Observe that the site becomes inaccessible and a PHP fatal error occurs.

NOTE: The error only occurs if the redis module is enabled in PHP; otherwise, the code never reaches the PhpRedis_Purger constructor

Expected behavior The expected behavior of the plugin is that it should handle an empty port setting gracefully. Either by validating the input to ensure it's a number or by defaulting to a standard port when none is provided, thus preventing the site from crashing.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context The error reported is:

PHP Fatal error: Uncaught TypeError: Redis::connect(): Argument #2 ($port) must be of type int, string given in /app/wordpress/wp-content/plugins/nginx-helper/admin/class-phpredis-purger.php:45

This suggests that there's a type-check issue in the code handling the Redis port settings, which could be mitigated by additional input validation or setting default values.

gagan0123 commented 2 months ago

Fixed in version 2.2.5