Support » Plugin: Wordfence Security - Firewall & Malware Scan » Wordfence “Optimize the Wordfence Firewall” bust with chroot’d FTP

  • Resolved Ronny Adsetts

    (@ronnyadsetts)


    When trying to run the “Optimize the Wordfence Firewall” procedure on a server that has chroot’d FTP access to write to the filesystem, Wordfence tries to write wordfence-waf.php using the path created by getWAFBootstrapPath. This function uses ABSPATH as the path prefix which in the case of the FTP (and SFTP I assume) with chroot is wrong.

    I can see from the FTP logs that Wordfence is trying to “PUT” the file using the full pathname.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support wfpeter

    (@wfpeter)

    Hi @ronnyadsetts, thanks for reaching out to us.

    This potentially looks like an issue that also crops up when a site is cloned where the auto_prepend_file = code in .htaccess in the root directory of your site refers to the wrong path.

    If you open your .htaccess (or .user.ini if your server is running CGI/FastCGI) with the file manager/editor of your choice and alter the auto_prepend_file path to /your/actual/path/public_html/wordfence-waf.php, then this should resolve the problem.

    If this doesn’t help, or the optimize firewall function didn’t even get as far as creating these values, to assist me in further understanding your environment, can you send a diagnostic report to wftest @ wordfence . com? You can find the link to do so at the top of the Wordfence Tools > Diagnostics page. Then click on “Send Report by Email”. Please add your forum username where indicated and respond here after you have sent it.

    Note: For the fastest response time, please make sure and add any information or questions directly to this topic and not the email address above unless asked.

    Thanks,

    Peter.

    Thread Starter Ronny Adsetts

    (@ronnyadsetts)

    Hi,

    This is starting from no auto_prepend_file set. Wordfence tries to put the wordfence-waf.php file on to the filesystem as part of the set up. It fails because it tries to use the full path over the FTP link. The full path is not valid within the FTP chroot hence the FTP server reject the write.

    I’ll send a report shortly.

    Ronny

    Thread Starter Ronny Adsetts

    (@ronnyadsetts)

    Diagnostics have been sent, however note that I’ve manually installed Wordfence using a copy from another site.

    Plugin Support wfpeter

    (@wfpeter)

    Hi @ronnyadsetts, thanks for providing the diagnostics for your site.

    Most WordPress paths are actually reporting back as “OK” on your diagnostic but I am getting a “FAIL” on writing to the plugins/wordfence folder in diagnostics. Check whether 755 is set on WordPress folders as recommended, but I don’t think this will solve the wider optimization issue.

    Whilst our developers have seen other chroot environments in the past, the paths being seen differently between FTP and the web server is not a known scenario with previous WordPress installations we’ve had close contact with.

    There may not be a way currently for Wordfence to detect that it’s different without the product being changed. I consulted a past topic for another plugin where defining an “FTP_BASE” constant looks like it might work in your case, but it would require some testing on your part to see if that’s actually the case: https://wordpress.org/support/topic/update-failed-unable-to-locate-wordpress-content-directory-wp-content/#post-11718427

    We think the quickest way to solve the issue you’re seeing would be to manually optimize the WAF. If you create the contents of wordfence-waf.php manually and set auto_prepend_file = using the path as the web server will see it. Since we very rarely need wordfence-waf.php changed, this generally won’t need to be repeated.

    You can find information about optimizing the firewall manually at: https://www.wordfence.com/help/firewall/optimizing-the-firewall/

    Let me know how you get on.

    Thanks,

    Peter.

    Thread Starter Ronny Adsetts

    (@ronnyadsetts)

    Thanks for your response Peter. The plugins/wordfence folder is intentionally not writeable by the web server process. As far as I’m aware, Wordfence doesn’t ever want to write anything to that folder via the web server process.

    I’ll verify again but I’m almost certain I tested with FTP_BASE set. I’ll report back on that.

    Note that running plugin updates from WordPress works fine despite the path difference. I wonder how their logic differs from the Wordfence logic in getWAFBootstrapPath.

    The immediate problem is solved as I have Wordfence set up and can work around the issue. Would be nice to not have to fight to get it working though.

    Also, nowhere on the manual firewall config doc does it give you what the contents of wordfence-waf.php should be. Or am I missing it?

    Plugin Support wfpeter

    (@wfpeter)

    Hi @ronnyadsetts,

    The contents of wordfence-waf.php is:

    <?php
    // Before removing this file, please verify the PHP ini setting <code>auto_prepend_file</code> does not point to this.
    
    if (file_exists('/path/to/public_html/wp-content/plugins/wordfence/waf/bootstrap.php')) {
    	define("WFWAF_LOG_PATH", '/path/to/public_html/wp-content/wflogs/');
    	include_once '/path/to/public_html/wp-content/plugins/wordfence/waf/bootstrap.php';
    }
    ?>

    Thanks,

    Peter.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Wordfence “Optimize the Wordfence Firewall” bust with chroot’d FTP’ is closed to new replies.