0.0
Low commit activity in last 3 years
Plugin for rack-attack to block and unblock evil requests
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 6.6.0
 Project Readme

Gem Version build

Shield

Rack::Shield

Simple frontend to block and unblock evil requests with Rack::Attack

Installation

In your Gemfile:

gem 'rack-attack-shield'

Usage

Check whether request is evil:

Rack::Shield.evil?(request)

With Rack::Attack::Fail2Ban:

# After one blocked request in 10 minutes, block all requests from that IP for 5 minutes.
Rack::Attack.blocklist('fail2ban pentesters') do |req|
  Rack::Attack::Fail2Ban.filter("pentesters-#{req.ip}", maxretry: 1, findtime: 10.minutes, bantime: 5.minutes) do
    Rack::Shield.evil?(req)
  end
end

Configuration

Adding to path matchers:

# Regexp will be matched
Rack::Shield.paths << /\.sql\z/

# String will be checked for inclusion
Rack::Shield.paths << '/wp-admin'

Defaults are defined in Rack::Shield::DEFAULT_EVIL_PATHS.

Blocked response

By default, the blocked response is generated automatically:

# default
Rack::Shield.response = Rack::Shield::Response

It can be set to any callable object which conforms to the Rack interface:

Rack::Shield.response = ->(env) { [403, { 'Content-Type' => 'text/html' }, ["Blocked!\n"]]

In Rails apps, the blocked response will be generated from app/views/layouts/shield.html.