Really-Simple-Plugins / really-simple-ssl

Easily improve site security with WordPress Hardening, Two-Factor Authentication (2FA), Login Protection, Vulnerability Detection and SSL certificate generation.
https://really-simple-ssl.com
Other
144 stars 43 forks source link

find_wp_config_path() causes fatal error with alternative wp-config.php setup #596

Closed MaxKnoblich closed 1 year ago

MaxKnoblich commented 1 year ago

Hi,

currently, when I try to access the settings of the Really Simple SSL plugin, I get a fatal error, preventing me from accessing the setting screen:

Fatal error: Uncaught ValueError: Path cannot be empty in /home/ttjmje9t14qp/public_html/content/plugins/really-simple-ssl/class-admin.php:2803 Stack trace: #0 /home/ttjmje9t14qp/public_html/content/plugins/really-simple-ssl/class-admin.php(2803): file_get_contents() #1 /home/ttjmje9t14qp/public_html/cms/wp-includes/class-wp-hook.php(308): rsssl_admin->insert_secure_cookie_settings() #2 /home/ttjmje9t14qp/public_html/cms/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters() #3 /home/ttjmje9t14qp/public_html/cms/wp-includes/plugin.php(517): WP_Hook->do_action() #4 /home/ttjmje9t14qp/public_html/cms/wp-admin/admin.php(175): do_action() #5 /home/ttjmje9t14qp/public_html/cms/wp-admin/options-general.php(10): require_once('/home/ttjmje9t1...') #6 {main} thrown in /home/ttjmje9t14qp/public_html/content/plugins/really-simple-ssl/class-admin.php on line 2803

I have looked into it and it seems that the find_wp_config_path() function expects to find the wp-config.php in a parent folder of the plugin's folder.

However, I have a nonstandard WordPress setup, where I separate the WordPress files and the content folder. So, my setup looks roughly like this: website/index.php <- Root index.php of my website, references website/wordpress/wp-blog-header.php website/wordpress/ <- Contains wp-admin, wp-includes and wp-config.php. wp-config.php defines WP_CONTENT_DIR and WP_CONTENT_URL to be: website/content/ <- Contains themes, plugins, etc.

Since my wp-config.php is in a sibling directory of the content folder, the find_wp_config_path() never finds it and returns null, causing the Fatal Error above.

Can the plugin use a different method of finding the wp-config.php that can handle alternative setups like this? Alternatively, can the plugin implement a hook that allows me to feed the actual location of the wp-config.php into the plugin?

rlankhorst commented 1 year ago

Hi @MaxKnoblich,

Thanks for reporting the issue. There are two issues here:

Looking at the WordPress code, it just looks in the ABSPATH directory, or the one above it. Assuming that all custom setups will work with that, checking that should be sufficient.

I have created a branch with both these versions included. https://github.com/Really-Simple-Plugins/really-simple-ssl/tree/wp-config-path-fixes

Let me know if that resolves your issue!

MaxKnoblich commented 1 year ago

Hi @rlankhorst,

thank you for your quick response! I've finally found the time to test your solution. I've downloaded the plugin version from the branch and installed it on my WordPress page.

As far as I can see, it works like a charm! I can access the settings page of the plugin again and so far, I haven't received any fatal errors.

Thank you!