Security Advisories (4)
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

CVE-2026-7381 (2026-04-29)

Plack::Middleware::XSendfile versions through 1.0053 for Perl can allow client-controlled path rewriting. Plack::Middleware::XSendfile allows the variation setting (sendfile type) to be set by the client via the X-Sendfile-Type header, if it is not considered in the middleware constructor or the Plack environment. A malicious client can set the X-Sendfile-Type header to "X-Accel-Redirect" to services running behind nginx reverse proxies, and then set the X-Accel-Mapping to map the path to an arbitrary file on the server. Since 1.0053, Plack::Middleware::XSendfile is deprecated and will be removed from future releases of Plack. This is similar to CVE-2025-61780 for Rack::Sendfile, although Plack::Middleware::XSendfile has some mitigations that disallow regular expressions to be used in the mapping, and only apply the mapping for the "X-Accel-Redirect" type.

NAME

Plack::Response - Portable HTTP Response object for PSGI response

SYNOPSIS

use Plack::Response;

sub psgi_handler {
    my $env = shift;

    my $res = Plack::Response->new(200);
    $res->content_type('text/html');
    $res->body("Hello World");

    return $res->finalize;
}

DESCRIPTION

Plack::Response allows you a way to create PSGI response array ref through a simple API.

METHODS

new
$res = Plack::Response->new;
$res = Plack::Response->new($status);
$res = Plack::Response->new($status, $headers);
$res = Plack::Response->new($status, $headers, $body);

Creates a new Plack::Response object.

status
$res->status(200);
$status = $res->status;

Sets and gets HTTP status code. code is an alias.

headers
$headers = $res->headers;
$res->headers([ 'Content-Type' => 'text/html' ]);
$res->headers({ 'Content-Type' => 'text/html' });
$res->headers( HTTP::Headers->new );

Sets and gets HTTP headers of the response. Setter can take either an array ref, a hash ref or HTTP::Headers object containing a list of headers.

body
$res->body($body_str);
$res->body([ "Hello", "World" ]);
$res->body($io);

Gets and sets HTTP response body. Setter can take either a string, an array ref, or an IO::Handle-like object. content is an alias.

$res->header('X-Foo' => 'bar');
my $val = $res->header('X-Foo');

Shortcut for $res->headers->header.

content_type, content_length, content_encoding
$res->content_type('text/plain');
$res->content_length(123);
$res->content_encoding('gzip');

Shortcut for the equivalent get/set methods in $res->headers.

redirect
$res->redirect($url);
$res->redirect($url, 301);

Sets redirect URL with an optional status code, which defaults to 302.

location

Gets and sets Location header.

cookies
$res->cookies->{foo} = 123;
$res->cookies->{foo} = { value => '123' };

Returns a hash reference containing cookies to be set in the response. The keys of the hash are the cookies' names, and their corresponding values are a plain string (for value with everything else defaults) or a hash reference that can contain keys such as value, domain, expires, path, httponly, secure.

expires can take a string or an integer (as an epoch time) and does not convert string formats such as +3M.

$res->cookies->{foo} = {
    value => 'test',
    path  => "/",
    domain => '.example.com',
    expires => time + 24 * 60 * 60,
};

AUTHOR

Tokuhiro Matsuno

Tatsuhiko Miyagawa

SEE ALSO

Plack::Request