Skip to content

thephpleague/stack-attack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

League\StackAttack

StackAttack is a blocking & throttling middleware for StackPHP, based heavily off of Rack::Attack for Ruby. It currently allows whitelisting and blacklisting.

Install Via Composer

{
    "require": {
        "league/stack-attack": "~1.0@dev"
    }
}

Example

include_once '../vendor/autoload.php';

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use League\StackAttack\FilterCollection;

$app = new Stack\CallableHttpKernel(function (Request $request) {
    return new Response('Hello World!');
});

$filters = (new FilterCollection)
    ->blacklist('Block dev requests.', function (Request $request) {
        return strpos($request->getPathInfo(), '/dev') === 0;
    });

$config = [
    'blacklistedResponse' => function (Request $request) {
            // A 503 response makes some bots think they had a successful DDOS
            return new Response('Service Unavailable', 503);
        }
];

$app = (new Stack\Builder)
    ->push('League\\StackAttack\\Attack', $filters, $config)
    ->resolve($app);

Stack\run($app);

About

StackPHP Middleware based on Rack::Attack

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages