Security Advisories (3)
CPANSA-Plack-2015-0202 (2015-02-02)

Fixed a possible directory traversal with Plack::App::File on Win32.

CPANSA-Plack-2014-0801 (2014-08-01)

Plack::App::File would previously strip trailing slashes off provided paths. This in combination with the common pattern of serving files with Plack::Middleware::Static could allow an attacker to bypass a whitelist of generated files

CPANSA-Plack-2013-0131 (2013-01-31)

Fixed directory traversal bug in Plack::App::File on win32 environments

NAME

Plack::Middleware::Conditional - Conditional wrapper for Plack middleware

SYNOPSIS

use Plack::Builder;

builder {
    enable_if { $_[0]->{REMOTE_ADDR} eq '127.0.0.1' } 'StackTrace';
    $app;
};

# Or more raw version of it
$app = Plack::Middleware::Conditional->wrap(
    $app,
    condition  => sub { my $env = shift; $env->{HTTP_USER_AGENT} =~ /WebKit/ },
    builder => sub { Plack::Middleware::SuperAdminConsole->wrap($_[0], @args) },
);

DESCRIPTION

Plack::Middleware::Conditional is a piece of meta-middleware, to run a specific middleware component under the runtime condition. The goal of this middleware is to avoid baking runtime configuration options in individual middleware components, and rather share them as another middleware component.

EXAMPLES

Note that some of the middleware component names are just made up for the explanation and might not exist.

# Minify JavaScript if the browser is Firefox
enable_if { $_[0]->{HTTP_USER_AGENT} =~ /Firefox/ } 'JavaScriptMinifier';

# Enable Stacktrace when being accessed from the local network
enable_if { $_[0]->{REMOTE_ADDR} =~ /^10\.0\.1\.*/ } 'StackTrace';

# Work with other conditional setter middleware:
# Transcode Jpeg on the fly for mobile clients
builder {
    enable 'MobileDetector';
    enable_if { $_[0]->{'psgix.mobile_detected'} }
      'TranscodeJpeg', max_size => 30_000;
    $app;
};

Note that in the last example MobileDetector should come first because the conditional check runs in pre-run condition, which is from outer to inner and that is from the top to the bottom in the Builder DSL code.

AUTHOR

Tatsuhiko Miyagawa

Steve Cook

SEE ALSO

Plack::Builder