Skip to content
WAF for WordPress 🔥 with 60+ security checks and weekly updates
PHP Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
braintree Braintree for Laravel update Oct 3, 2019
core-events Upgrade packages and fix config files Nov 17, 2019
http-analyzer Upgrade packages and fix config files Nov 17, 2019
miniban Introduce more WPCS rules Dec 6, 2017
non-wp-projects Upgrade packages and fix config files Nov 17, 2019
tests
.gitignore
.gitmodules Moving to a new repo Jul 9, 2015
README.md New phpcs rules, tiny fix and a typo Jul 24, 2019
composer.json
composer.lock Upgrade packages and fix config files Nov 17, 2019
phpcs.xml.dist Upgrade packages and fix config files Nov 17, 2019
phpstan.neon.dist Add rel=nofollow to login links Oct 6, 2019

README.md

WAF for WordPress

Stop real-life attacks on your WordPress website and trigger Fail2ban.

This WAF does not give proper HTTP responses to unusual requets. It blocks the attacking IP address instantly, the purpose of this are the following.

  1. Prevent website compromise in further requests
  2. Prevent D/DoS attacks

Shared hosting has no server-wide banning (because of trust issues) but you can still install this software without Fail2ban to stop attacks by using one of the Miniban methods.

Your WordPress - really general HTTP - security consists of:

  1. Use HTTPS
  2. Have daily backup
  3. Block known hostile networks
  4. Have Fail2ban installed (controls the firewall)
  5. Maintain your website and use strict Fail2ban filters which ban on the first suspicious request instantly
  6. Deny direct access to core WordPress files, themes and plugins
  7. Install WAF for WordPress (this project)
  8. Use Leanmail (filters Fail2ban notification emails)

See the Block WordPress attack vectors note in my other repository for an overview of the topic.

Http_Analyzer class

Examines headers in the HTTP requests and triggers Fail2ban accordingly.

To install it copy http-analyzer/waf4wordpress-http-analyzer.php beside your wp-config.php and copy these lines in top of wp-config.php:

/** Security */
require_once __DIR__ . '/waf4wordpress-http-analyzer.php';
new \Waf4WordPress\Http_Analyzer();

A better solution is to load it from the auto_prepend_file PHP directive. This time you have to copy the above code in the class file.

Core_Events class

It is an MU plugin that triggers Fail2ban on various WordPress specific attack types. Login is only logged, use Http_Analyzer class for handling that.

To install copy core-events/waf4wordpress-core-events.php into your wp-content/mu-plugins/ directory. You may have to create the mu-plugins directory. It activates automatically.

The non-wp-projects folder

Triggers Fail2ban on WordPress login probes in any project.

To install copy the fake non-wp-projects/wp-login.phpand non-wp-projects/xmlrpc.php to your non-WordPress project's document root.

WAF for WordPress is not in WordPress.org's plugin directory

After is it published on WordPress.org you can install the plugin and skip file copying.
That way it'll be installed automatically.

Support PayPal IPN, Brantree and custom entry points in poorly written plugins

Copy this into your in wp-config.php.

// Enable PayPal IPN in WooCommerce
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
    if ( '/wc-api/WC_Gateway_Paypal/' === parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) ) {
        // PayPal IPN does not send Accept: and User-Agent: headers
        $_SERVER['HTTP_ACCEPT'] = '*/*';
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 PayPal/IPN';
    }
}

// Enable Braintree Webhooks
new \Waf4WordPress\Braintree_Fix( '/braintree/webhook' );

// Enable email opens in Newsletter plugin
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
    $newsletter_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
    if ( '/wp-content/plugins/newsletter/statistics/open.php' === $newsletter_path
        || '/wp-content/plugins/newsletter/statistics/link.php' === $newsletter_path
    ) {
        // UA hack for old email clients
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 ' . $_SERVER['HTTP_USER_AGENT'];
    }
    unset( $newsletter_path );
}

// Enable email open tracking in ALO EasyMail Newsletter plugin
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
    $alo_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
    if ( '/wp-content/plugins/alo-easymail/tr.php' === $alo_path ) {
        // UA hack for old email clients
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 ' . $_SERVER['HTTP_USER_AGENT'];
    }
    unset( $alo_path );
}

Support and feature requests

Open a new issue

You can’t perform that action at this time.