PHPackages                             terrylinooo/shieldon - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. terrylinooo/shieldon

Abandoned → [https://github.com/terrylinooo/shieldon](/?search=https%3A%2F%2Fgithub.com%2Fterrylinooo%2Fshieldon)Library[Security](/categories/security)

terrylinooo/shieldon
====================

Web application firewall for PHP.

2.04(2y ago)874184106MITPHPPHP &gt;=7.1.0CI passing

Since Mar 10Pushed 2y ago25 watchersCompare

[ Source](https://github.com/terrylinooo/shieldon)[ Packagist](https://packagist.org/packages/terrylinooo/shieldon)[ Docs](https://github.com/terrylinooo/shieldon)[ RSS](/packages/terrylinooo-shieldon/feed)WikiDiscussions 2.x Synced 2d ago

READMEChangelog (10)Dependencies (8)Versions (16)Used By (0)

Web Application Firewall ⚡ `PHP`
================================

[](#web-application-firewall-zap-php)

Shieldon is a Web Application Firewall (WAF) for PHP, with a beautiful and useful control panel that helps you easily manage the firewall rules and security settings.

[![Shieldon - Web Application Firewall for PHP](https://camo.githubusercontent.com/34d2c57c09c173ae314f721e81b1751f657c95dad64817c1e811af075ab49297/68747470733a2f2f692e696d6775722e636f6d2f473478707567422e706e67)](https://camo.githubusercontent.com/34d2c57c09c173ae314f721e81b1751f657c95dad64817c1e811af075ab49297/68747470733a2f2f692e696d6775722e636f6d2f473478707567422e706e67)

[![build](https://github.com/terrylinooo/shieldon/workflows/build/badge.svg)](https://github.com/terrylinooo/shieldon/workflows/build/badge.svg) [![codecov](https://camo.githubusercontent.com/9288f7fec073b420609181ff12aa2062c986d96b3364182f51afc6df83d64d7b/68747470733a2f2f636f6465636f762e696f2f67682f74657272796c696e6f6f6f2f736869656c646f6e2f6272616e63682f322e782f67726170682f62616467652e7376673f763d323032303038323031)](https://codecov.io/gh/terrylinooo/shieldon) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/aa5289b4a85df37f00ff2c2825b14e98c6ceb72e6a6577bd243c5f845a53e1c9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74657272796c696e6f6f6f2f736869656c646f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d322e78)](https://scrutinizer-ci.com/g/terrylinooo/shieldon/?branch=2.x) [![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://opensource.org/licenses/MIT)

- Website: [https://shieldon.io](https://shieldon.io/)
- Wiki:
- GitHub repository:
- WordPress plugin:

Demo
----

[](#demo)

- Before you installing Shieldon, you can try the online [DEMO](https://shieldon.io/demo/) of the firewall control panel, the user and password both are `demo`.
- Try temporarily blocked by Shieldon, refreshing serveral times on [shieldon.io](https://shieldon.io/), then you will see a dialog asking you for solving Google ReCaptcha to get unblocked.

Installation
------------

[](#installation)

Install via PHP Composer.

```
composer require shieldon/shieldon ^2
```

This will also install dependencies built for Shieldon:

packagedescription[shieldon/psr-http](https://github.com/terrylinooo/psr-http)PSR-7, 15, 17 Implementation with full documented and well tested.[shieldon/event-dispatcher](https://github.com/terrylinooo/event-dispatcher)Simple event dispatcher.[shieldon/web-security](https://github.com/terrylinooo/web-security)Collection of functions about web security.[shieldon/messenger](https://github.com/terrylinooo/messenger)Collection of modules of sending message to third-party API or service, such as Telegram, Line, RocketChat, Slack, SendGrid, MailGun and more...Concepts
--------

[](#concepts)

This is basic concepts about how Shieldon works.

[![](https://camo.githubusercontent.com/8c2fa6c0e29411f8f977ee348f1f7830fdec67ae518912209b7bb864af5d2a9b/68747470733a2f2f692e696d6775722e636f6d2f705262493767672e706e67)](https://camo.githubusercontent.com/8c2fa6c0e29411f8f977ee348f1f7830fdec67ae518912209b7bb864af5d2a9b/68747470733a2f2f692e696d6775722e636f6d2f705262493767672e706e67)

- The network-layer firewall such as CloudFlare.
- The system-layer firewall such as iptables module.
- To use firewall software in the Web application layer, you can implement Shieldon in a very early stage of your APP, mostly just after Composer autoloader, or at the first place of middleware-pipeline.
- Shieldon analyzes all your HTTP and HTTPS requests.
- Once Shieldon has detected strange behaviors of a request, blocking and prompting them CAPTCHA to unblock. [![Firewall Dialog 1](https://camo.githubusercontent.com/b1ff35ed800e6a88b35a3f23451d907c4dac0c4a075440bb126379714fda6674/68747470733a2f2f692e696d6775722e636f6d2f726c73457753472e706e67)](https://camo.githubusercontent.com/b1ff35ed800e6a88b35a3f23451d907c4dac0c4a075440bb126379714fda6674/68747470733a2f2f692e696d6775722e636f6d2f726c73457753472e706e67)
- If a request fails in a row many times (depends on your setting), they will be permanently banned in current data circle. [![Firewall Dialog 2](https://camo.githubusercontent.com/7b7e434cbd697329ee093101a86fb05d34b7bbbf27fb20a10cd88b04f22410a5/68747470733a2f2f692e696d6775722e636f6d2f517931734144772e706e67)](https://camo.githubusercontent.com/7b7e434cbd697329ee093101a86fb05d34b7bbbf27fb20a10cd88b04f22410a5/68747470733a2f2f692e696d6775722e636f6d2f517931734144772e706e67)
- If a request has been permanently banned, but they still access your page, drop them in System-layer firewall - iptables. (You have to set up iptables bridge correctly)

How to Use
----------

[](#how-to-use)

### Integration with Frameworks

[](#integration-with-frameworks)

There are some step-by-step installation guides that lead you implementing Shieldon firewall on your PHP application. Choose a framework you are using.

[![Firewall in Laravel](https://camo.githubusercontent.com/a7f2d0bc46413bc62b3596142dd8a6ef89a94e9b8b05f6b7e68fb2259d0ac59b/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f6c61726176656c2d6672616d65776f726b2d6669726577616c6c2e706e67)](https://camo.githubusercontent.com/a7f2d0bc46413bc62b3596142dd8a6ef89a94e9b8b05f6b7e68fb2259d0ac59b/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f6c61726176656c2d6672616d65776f726b2d6669726577616c6c2e706e67)[![Firewall in CakePHP](https://camo.githubusercontent.com/1a656fe30b063d9b850ca5a76baf59dbc632271955f635826fbae5cf9bcb118e/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f63616b657068702d6672616d65776f726b2d6669726577616c6c2e706e67)](https://camo.githubusercontent.com/1a656fe30b063d9b850ca5a76baf59dbc632271955f635826fbae5cf9bcb118e/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f63616b657068702d6672616d65776f726b2d6669726577616c6c2e706e67)[![Firewall in Symfony](https://camo.githubusercontent.com/78f4b7f0bae56fdbc220c8530879b159903cbf8dd45e2a4cfd700ef8f92f99ec/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f73796d666f6e792d6672616d65776f726b2d6669726577616c6c2e706e67)](https://camo.githubusercontent.com/78f4b7f0bae56fdbc220c8530879b159903cbf8dd45e2a4cfd700ef8f92f99ec/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f73796d666f6e792d6672616d65776f726b2d6669726577616c6c2e706e67)[![Firewall in PHPixie](https://camo.githubusercontent.com/d2acba419296b9f27dfce7a20d0d51fd1a50569f1db12defe418d63bb16fa792/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f706870697869652d6672616d65776f726b2d6669726577616c6c2e706e67)](https://camo.githubusercontent.com/d2acba419296b9f27dfce7a20d0d51fd1a50569f1db12defe418d63bb16fa792/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f706870697869652d6672616d65776f726b2d6669726577616c6c2e706e67)[Laravel](https://github.com/terrylinooo/shieldon/wiki/Laravel-Framework)[CakePHP 3](https://github.com/terrylinooo/shieldon/wiki/CakePHP-Framework)[Symfony](https://github.com/terrylinooo/shieldon/wiki/Symfony-Framework)[PHPixie](https://github.com/terrylinooo/shieldon/wiki/PHPixie-Framework)[![Firewall in FatFree](https://camo.githubusercontent.com/bbf08d498e8012f282bccfa0b975df3ed40f112cccdf0405f604192b6fdf3f0f/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f666174667265652d6672616d65776f726b2d6669726577616c6c2e706e67)](https://camo.githubusercontent.com/bbf08d498e8012f282bccfa0b975df3ed40f112cccdf0405f604192b6fdf3f0f/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f666174667265652d6672616d65776f726b2d6669726577616c6c2e706e67)[![Firewall in CodeIgniterr](https://camo.githubusercontent.com/ac41e3430acc4e2234913988574f8ce2bffc1a709c3292bcbb337113052732ef/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f636f646569676e697465722d6672616d65776f726b2d6669726577616c6c2e706e67)](https://camo.githubusercontent.com/ac41e3430acc4e2234913988574f8ce2bffc1a709c3292bcbb337113052732ef/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f636f646569676e697465722d6672616d65776f726b2d6669726577616c6c2e706e67)[![Firewall in Yii Framework](https://camo.githubusercontent.com/df6beb364856c80daa7ac774c12102c4c8b8ef699c48ee8612ab01ccbe411c28/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f7969692d6672616d65776f726b2d6669726577616c6c2e706e67)](https://camo.githubusercontent.com/df6beb364856c80daa7ac774c12102c4c8b8ef699c48ee8612ab01ccbe411c28/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f7969692d6672616d65776f726b2d6669726577616c6c2e706e67)[![Firewall in Zend](https://camo.githubusercontent.com/c574c7c5a489e0effbd7ecb18bbaf54df8652f7e99c4d0708d544331212231c4/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f7a656e642d6672616d65776f726b2d6669726577616c6c2e706e67)](https://camo.githubusercontent.com/c574c7c5a489e0effbd7ecb18bbaf54df8652f7e99c4d0708d544331212231c4/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f7a656e642d6672616d65776f726b2d6669726577616c6c2e706e67)[FatFree](https://github.com/terrylinooo/shieldon/wiki/FatFree-Framework)[CodeIgniter 3](https://github.com/terrylinooo/shieldon/wiki/CodeIgniter-3-Framework)
[CodeIgniter 4](https://github.com/terrylinooo/shieldon/wiki/CodeIgniter-4-Framework)[Yii 2](https://github.com/terrylinooo/shieldon/wiki/Yii-2-Framework)[Zend MVC](https://github.com/terrylinooo/shieldon/wiki/Zend-Framework-MVC)
[Zend Expressive](https://github.com/terrylinooo/shieldon/wiki/Zend-Framework-Expressive)[![Firewall in Slim](https://camo.githubusercontent.com/75346af175cfe7334cfbc973666b1c629fc6c5fbdf9aec50d4d72d53bcffa57a/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f736c696d2d6672616d65776f726b2d6669726577616c6c2e706e67)](https://camo.githubusercontent.com/75346af175cfe7334cfbc973666b1c629fc6c5fbdf9aec50d4d72d53bcffa57a/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f736c696d2d6672616d65776f726b2d6669726577616c6c2e706e67)[![Firewall in Fuel](https://camo.githubusercontent.com/23ce245e9eab57cef676ec72b11285b257add32451c0d44ac237bd4db949c5c9/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f6675656c2d6672616d65776f726b2d6669726577616c6c2e706e67)](https://camo.githubusercontent.com/23ce245e9eab57cef676ec72b11285b257add32451c0d44ac237bd4db949c5c9/68747470733a2f2f736869656c646f6e2e696f2f696d616765732f686f6d652f6675656c2d6672616d65776f726b2d6669726577616c6c2e706e67)-[Slim 3](https://github.com/terrylinooo/shieldon/wiki/Slim-3-Framework)
[Slim 4](https://github.com/terrylinooo/shieldon/wiki/Slim-3-Framework)[Fuel](https://github.com/terrylinooo/shieldon/wiki/Fuel-Framework)[Pure PHP project](https://github.com/terrylinooo/shieldon/wiki/Pure-PHP-Project)Listed frameworks: [Laravel](https://shieldon.io/en/guide/laravel.html), [Symfony](https://shieldon.io/en/guide/symfony.html), [CodeIgniter](https://shieldon.io/en/guide/codeigniter.html), [CakePHP](https://shieldon.io/en/guide/cakephp.html), [Yii](https://shieldon.io/en/guide/yii.html), [Zend](https://shieldon.io/en/guide/zend.html), [Slim](https://shieldon.io/en/guide/slim.html), [Fat-Free](https://shieldon.io/en/guide/fatfree.html), [Fuel](https://shieldon.io/en/guide/fuel.html), [PHPixie](https://shieldon.io/en/guide/phpixie.html). Can't find the documentation of the framework you are using?

There are three ways you can choose to use Shieldon on your application.

- Implement Shieldon as a *`PSR-15 middleware`*.
- Implement Shieldon in the *`bootstrap stage`* of your application.
- Implement Shieldon in the *`parent controller`* extended by the other controllers.

Shieldon `2.x` implements PSR-7 so that it could be compatible with modern frameworks such as Laravel, Symfony, Slim, Yii and so on.

### PSR-15 Middleware

[](#psr-15-middleware)

#### `Example: Slim 4 framework`

[](#example-slim-4-framework)

In this example, I will give you some tips on how to implement Shieldon as a PSR-15 middleware.

I use Slim 4 framwork for demonstration. This way can be used on any framework supporting PSR-15 too, just with a bit modification.

#### (1) Create a firewall middleware.

[](#1-create-a-firewall-middleware)

```
class FirewallMiddleware
{
    /**
     * Example middleware invokable class
     *
     * @param ServerRequest  $request PSR-7 request
     * @param RequestHandler $handler PSR-15 request handler
     *
     * @return Response
     */
    public function __invoke(Request $request, RequestHandler $handler): Response
    {
        $response = $handler->handle($request);

        $firewall = new \Shieldon\Firewall\Firewall($request, $response);

        // The directory in where Shieldon Firewall will place its files.
        $firewall->configure(__DIR__ . '/../cache/shieldon_firewall');

        // The base url for the control panel.
        $firewall->controlPanel('/firewall/panel/');

        $response = $firewall->run();

        if ($response->getStatusCode() !== 200) {
            $httpResolver = new \Shieldon\Firewall\HttpResolver();
            $httpResolver($response);
        }

        return $response;
    }
}
```

#### (2) Add the firewall middleware in your application.

[](#2-add-the-firewall-middleware-in-your-application)

For example, if you are using Slim 4 framework, the code should look like this.

```
$app->add(new FirewallMiddleware());
```

#### (3) Create a route for control panel.

[](#3-create-a-route-for-control-panel)

For example, if you are using Slim 4 framework, the code should look like this. Then you can access the URL `https://yourwebsite.com/firewall/panel` to login to control panel.

```
$app->any('/firewall/panel[/{params:.*}]', function (Request $request, Response $response, $args) {
    $firewall = new \Shieldon\Firewall\Firewall($request, $response);

    // The directory in where Shieldon Firewall will place its files.
    // Must be the same as firewallMiddleware.
    $firewall->configure(__DIR__ . '/../cache/shieldon_firewall');

    $panel = new \Shieldon\Firewall\Panel();
    $panel->entry();
});
```

Note:

- The HTTP method `POST` and `GET` both should be applied to your website.
- `POST` method is needed for solving CAPTCHA by users who were temporarily blocked.

### Bootstrap Stage

[](#bootstrap-stage)

#### `Example: Laravel 6 framework`

[](#example-laravel-6-framework)

Initialize Shieldon in the bootstrap stage of your application, mostly in just right after composer autoloader has been included.

In this example, I use Laravel 6 for demonstration.

#### (1) Before Initializing the $app

[](#1-before-initializing-the-app)

In your `bootstrap/app.php`, after `
