Security
Turning on the firewall safely, and the recovery switches
How the firewall is installed, how to start in learning mode, and how to switch protection off from outside wp-admin if you are ever locked out.
How the firewall runs
The firewall inspects each request before WordPress, your plugins or your theme load. It does this with PHP's auto_prepend_file setting, which tells PHP to run one small file first.
| How your host runs PHP | What Swiftkeep changes |
|---|---|
| Apache with mod_php, or LiteSpeed | One line in the site's .htaccess, wrapped so it cannot cause a server error |
| CGI, FastCGI or PHP-FPM | One line in .user.ini |
| Neither is possible | The firewall runs when the plugin loads instead. It still protects WordPress, a little later in the request |
PHP is pointed at a small loader file, swiftkeep-waf.php, in your WordPress folder. That file still exists and does nothing if the plugin is deleted, so removing the plugin can never leave PHP looking for a missing file.
Changes to .user.ini are not instant
PHP re-reads .user.ini on a timer, usually every five minutes. On those hosts, allow a few minutes after switching the firewall on or off.
It fails open
If the firewall hits an error, finds its configuration missing or damaged, or takes too long, it lets the request through untouched. A firewall fault can make the site less protected for a moment. It cannot take the site down.
Turn it on
- 1
Take a backup first
Any change to how requests reach your site deserves a backup you have verified.
- 2
Open Security, then Firewall
Switch the firewall on. Swiftkeep works out how your host runs PHP and makes the change shown in the table above.
- 3
Start in learning mode
In learning mode the firewall records the requests its rules would block, and lets them through. Your own block list, country blocks and rate limits still apply. Use your site normally for a few days: log in, edit a page, place a test order.
- 4
Review what was recorded
If your own normal activity was recorded, add an exception for it. Requests you do not recognise are the ones the firewall is there for.
- 5
Switch to protecting
Now the firewall blocks what it matches.
Sites behind Cloudflare or another proxy
Rate limits, blocks and sign-in lockouts apply to each visitor's address. Behind a proxy, every request arrives from the proxy, so the visitor's own address has to come from a header the proxy adds. Anyone can type a header, so the firewall only reads one when the request really comes from that proxy.
| Under Security, Firewall, Addresses and countries | What it does |
|---|---|
| Detect automatically (the default) | When a request comes from one of Cloudflare's published addresses, the visitor's address is read from Cloudflare's CF-Connecting-IP header. Any other request uses the connection's own address |
| Cloudflare | Always reads CF-Connecting-IP from Cloudflare. Cloudflare's addresses are built in. List another proxy only if one sits between Cloudflare and your site |
| X-Forwarded-For or X-Real-IP | For other proxies and load balancers. The header is only read from a proxy you list as trusted |
| The connection itself | Ignores every header |
A site on Cloudflare needs no setup. The same screen says when it has detected Cloudflare. An address taken from a header must be a public one: a private or loopback address in a header is ignored.
Behind Cloudflare with visitor detection off
If the chosen setting reads Cloudflare's own address instead of the visitor's, for example the connection itself, or X-Forwarded-For with no proxy listed, every visitor looks like one of Cloudflare's addresses, shared by everyone Cloudflare routes through it. The screen warns you, and until you choose Detect automatically the firewall softens what it does to that shared address: rate limits slow it down instead of blocking it, and failed sign-ins, including wrong two-step codes, lock only the account being tried. Many failed sign-ins across several accounts, ten times the allowed attempts or at least 50 in the counting period, pause sign-in from that address for the base lockout time. That pause never lengthens on repeats, because real visitors share the address.
Recovery switches
Each protection that could keep you out of your own site has a switch that works without wp-admin. You need access to the site's files, through SFTP, your host's file manager or SSH.
Switch the firewall off
Either add this line to wp-config.php, above the line that says to stop editing:
define( 'SWIFTKEEP_WAF_DISABLED', true );Or create an empty file with this exact name. No editing of PHP is needed:
wp-content/swiftkeep-waf-offRemove the line or delete the file to switch the firewall back on.
Switch login protection off
define( 'SWIFTKEEP_LOGIN_PROTECTION_DISABLED', true );This switches off the CAPTCHA, the custom login address and the rule that makes two-step sign-in compulsory for a role. Lockouts after failed sign-ins do not need a switch: they always expire by themselves.
Switch hardening off
define( 'SWIFTKEEP_HARDENING_DISABLED', true );Take the switch out again
These lines turn protection off. Once you are back in and have fixed the cause, remove them.
Removing the firewall
Switching the firewall off, or deactivating the plugin, removes the line it added to .htaccess or .user.ini. If your licence lapses, the firewall keeps working.
Written for Swiftkeep 2.1.6. Under white label, the plugin shows your agency's name where this guide says Swiftkeep.