Stars: 115
Forks: 22
Pull Requests: 1
Issues: 10
Watchers: 18
Last Updated: 2023-08-04 07:33:52
WAF for WordPress 🔥 with 60+ security checks and weekly updates
License: MIT License
Languages: PHP
Stop real-life attacks on your WordPress website and trigger Fail2Ban.
💡 Before using this WAF you have to clean your website, get rid of even tiny errors. See your access and error logs daily and run this WAF without Fail2ban for a week.
This WAF does not give proper HTTP responses to unusual requests. It blocks the attacking IP address instantly, the purpose of this are the following.
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.
Please consider sponsoring me monthly if you use my packages in an agency.
Your WordPress - really general HTTP - security consists of the followings.
See the Block WordPress attack vectors note in my other repository for an overview of the topic.
Technically this is not a WordPress plugin nor an MU plugin. WAF for WordPress is distributed and autoloaded as a Composer package.
composer require szepeviktor/waf4wordpress
commandvendor/autoload.php
from your wp-config
SzepeViktor\WordPress\Waf\HttpAnalyzer
class early in wp-config
require dirname(__DIR__) . '/vendor/autoload.php';
new SzepeViktor\WordPress\Waf\HttpAnalyzer();
wp-content/mu-plugins/waf4wordpress.php
<?php
/*
* Plugin Name: WAF for WordPress (MU)
*/
if (! function_exists('add_filter')) {
exit;
}
new SzepeViktor\WordPress\Waf\CoreEvents();
💡 Please see Composer-managed WordPress for managing WordPress with Composer.
Technically this is not a WordPress plugin nor an MU plugin.
waf/
SzepeViktor\WordPress\Waf\HttpAnalyzer
class early in wp-config
require_once __DIR__ . '/waf/src/HttpAnalyzer.php';
require_once __DIR__ . '/waf/src/CoreEvents.php';
new SzepeViktor\WordPress\Waf\HttpAnalyzer();
wp-content/mu-plugins/waf4wordpress.php
<?php
/*
* Plugin Name: WAF for WordPress (MU)
*/
if (! function_exists('add_filter')) {
exit;
}
new SzepeViktor\WordPress\Waf\CoreEvents();
WAF for WordPress is configured in source code
before class instantiation. in wp-config
.
Create custom filters for Fail2Ban catching these PHP messages.
Malicious traffic detected:
may be banned after 6 attempts per 10 minutesBreak-in attempt detected:
may be banned instantlyCopy 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 );
}
/backup/
/blog/
/cms/
/demo/
/dev/
/home/
/main/
/new/
/old/
/portal/
/site/
/test/
/tmp/
/web/
/wordpress/
/wp/
Best not to create these directories to avoid lengthy log excerpts.