sinatra/rack-protection/README.md

100 lines
2.1 KiB
Markdown
Raw Normal View History

2016-07-25 04:23:53 +00:00
# Rack::Protection
[![Build Status](https://secure.travis-ci.org/sinatra/rack-protection.png)](http://travis-ci.org/sinatra/rack-protection)
2011-06-19 13:06:08 +00:00
This gem protects against typical web attacks.
Should work for all Rack apps, including Rails.
2011-05-23 08:07:54 +00:00
# Usage
2011-06-19 13:06:08 +00:00
Use all protections you probably want to use:
2011-05-23 08:07:54 +00:00
``` ruby
# config.ru
require 'rack/protection'
use Rack::Protection
2011-06-19 13:06:08 +00:00
run MyApp
```
Skip a single protection middleware:
``` ruby
# config.ru
require 'rack/protection'
use Rack::Protection, :except => :path_traversal
run MyApp
2011-05-23 08:07:54 +00:00
```
2011-06-19 13:06:08 +00:00
Use a single protection middleware:
``` ruby
# config.ru
require 'rack/protection'
use Rack::Protection::AuthenticityToken
run MyApp
```
# Prevented Attacks
## Cross Site Request Forgery
Prevented by:
* `Rack::Protection::AuthenticityToken` (not included by `use Rack::Protection`)
* `Rack::Protection::FormToken` (not included by `use Rack::Protection`)
2011-06-19 13:26:39 +00:00
* `Rack::Protection::JsonCsrf`
2011-06-19 13:06:08 +00:00
* `Rack::Protection::RemoteReferrer` (not included by `use Rack::Protection`)
* `Rack::Protection::RemoteToken`
2012-01-30 08:57:31 +00:00
* `Rack::Protection::HttpOrigin`
2011-06-20 14:25:32 +00:00
2011-06-19 13:06:08 +00:00
## Cross Site Scripting
Prevented by:
* `Rack::Protection::EscapedParams` (not included by `use Rack::Protection`)
* `Rack::Protection::XSSHeader` (Internet Explorer and Chrome only)
2014-02-21 11:50:44 +00:00
* `Rack::Protection::ContentSecurityPolicy`
2011-06-19 13:06:08 +00:00
## Clickjacking
Prevented by:
* `Rack::Protection::FrameOptions`
## Directory Traversal
Prevented by:
* `Rack::Protection::PathTraversal`
## Session Hijacking
Prevented by:
* `Rack::Protection::SessionHijacking`
2011-06-20 07:16:03 +00:00
## IP Spoofing
Prevented by:
* `Rack::Protection::IPSpoofing`
## Helps to protect against protocol downgrade attacks and cookie hijacking
Prevented by:
* `Rack::Protection::StrictTransport` (not included by `use Rack::Protection`)
2011-05-23 08:07:54 +00:00
# Installation
gem install rack-protection
2011-09-02 19:45:05 +00:00
2013-08-21 18:50:51 +00:00
# Instrumentation
Instrumentation is enabled by passing in an instrumenter as an option.
```
use Rack::Protection, instrumenter: ActiveSupport::Notifications
```
The instrumenter is passed a namespace (String) and environment (Hash). The namespace is 'rack.protection' and the attack type can be obtained from the environment key 'rack.protection.attack'.