Skip to content

thephpleague/stack-attack

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

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