A simple but very effective PHP firewall. It enables you to easily block most SQL and XSS injections. It also includes a white-/blacklisting of IP's and throttling request using Leaky Bucket.

0.1.1 2014-07-03 05:55 UTC

This package is not auto-updated.

Last update: 2024-04-09 00:37:13 UTC


Ninja is a very simple firewall which you can configure to do awesome things. It's still in development, but it may already be used.

How to configure

Ninja uses Leaky Bucket for throttling requests. You can teach your Ninja about hazards, and block them where needed.

use \Ninja\Ninja;

    function (\Symfony\Component\HttpFoundation\Request $request) {
        return true;
        'bucket_size' => 10,
        'bucket_leak' => 1

When the hazard returns true, it means the hazard has been detected. To detect a hazard, you retrieve a Request object. You can check that for all sorts of things. Apart from the bucket_size and bucket_leak you can also specify a timeout for when attacks happen.

You should also give your Ninja something to protect.

use Ninja\Ninja;

// ...
$request = Request::createFromGlobals();

// Send the Ninjas
Ninja::prepare(__DIR__ . '/../app/config/ninja.php', $request);

$response = $kernel->handle($request);

// Inject the Ninja in the response

$kernel->terminate($request, $response);


You can find the LICENSE file in this project.