NAME
Plack::Middleware::CSRFBlock - CSRF are never propageted to app
SYNOPSIS
use Plack::Builder;
my $app = sub { ... }
builder {
enable 'Session';
enable 'CSRFBlock';
$app;
}
DESCRIPTION
This middleware blocks CSRF. You can use this middleware without any
modifications to your application, in most cases. Here is the strategy:
output filter
When the application response content-type is "text/html" or
"application/xhtml+xml", this inserts hidden input tag that contains
token string into "form"s in the response body. For example, the
application response body is:
input form
this becomes:
input form
This affects "form" tags with "method="post"", case insensitive.
input check
For every POST requests, this module checks input parameters contain
the collect token parameter. If not found, throws 403 Forbidden by
default.
Supports "application/x-www-form-urlencoded" and
"multipart/form-data".
OPTIONS
parameter_name (default:"SEC")
Name of the input tag for the token.
token_length (default:16);
Length of the token string. Max value is 40.
session_key (default:"csrfblock.token")
This middleware uses Plack::Middleware::Session for token storage.
this is the session key for that.
blocked (default:403 response)
The application called when CSRF is detected.
Note: This application can read posted data, but DO NOT use them!
onetime (default:FALSE)
If this is true, this middleware uses onetime token, that is,
whenever client sent collect token and this middleware detect that,
token string is regenerated.
This makes your applications more secure, but in many cases, is too
strict.
CAVEATS
This middleware doesn't work with pure Ajax POST request, because it
cannot insert the token parameter to the request. We suggest, for
example, to use jQuery Form Plugin like: