Security Advisories (10)
CPANSA-Mojolicious-2022-03 (2022-12-10)

Mojo::DOM did not correctly parse <script> tags.

CPANSA-Mojolicious-2021-02 (2021-06-01)

Small sessions could be used as part of a brute-force attack to decode the session secret.

CVE-2021-47208 (2021-03-16)

A bug in format detection can potentially be exploited for a DoS attack.

CVE-2018-25100 (2018-02-13)

Mojo::UserAgent::CookieJar leaks old cookies because of the missing host_only flag on empty domain.

CPANSA-Mojolicious-2015-01 (2015-02-02)

Directory traversal on Windows

CPANSA-Mojolicious-2018-03 (2018-05-19)

Mojo::UserAgent was not checking peer SSL certificates by default.

CVE-2020-36829 (2020-11-10)

Mojo::Util secure_compare can leak the string length. By immediately returning when the two strings are not the same length, the function allows an attacker to guess the length of the secret string using timing attacks.

CPANSA-Mojolicious-2018-02 (2018-05-11)

GET requests with embedded backslashes can be used to access local files on Windows hosts

CPANSA-Mojolicious-2014-01 (2014-10-07)

Context sensitivity of method param could lead to parameter injection attacks.

CVE-2024-58134 (2025-05-03)

Mojolicious versions from 0.999922 for Perl uses a hard coded string, or the application's class name, as a HMAC session secret by default. These predictable default secrets can be exploited to forge session cookies. An attacker who knows or guesses the secret could compute valid HMAC signatures for the session cookie, allowing them to tamper with or hijack another user's session.

NAME

Mojo::Parameters - Parameters

SYNOPSIS

use Mojo::Parameters;

# Parse
my $params = Mojo::Parameters->new('foo=bar&baz=23');
say $params->param('baz');

# Build
my $params = Mojo::Parameters->new(foo => 'bar', baz => 23);
push @$params, i => '♥ mojolicious';
say "$params";

DESCRIPTION

Mojo::Parameters is a container for form parameters used by Mojo::URL and based on RFC 3986 as well as the HTML Living Standard.

ATTRIBUTES

Mojo::Parameters implements the following attributes.

charset

my $charset = $params->charset;
$params     = $params->charset('UTF-8');

Charset used for encoding and decoding parameters, defaults to UTF-8.

# Disable encoding and decoding
$params->charset(undef);

METHODS

Mojo::Parameters inherits all methods from Mojo::Base and implements the following new ones.

append

$params = $params->append(foo => 'ba&r');
$params = $params->append(foo => ['ba&r', 'baz']);
$params = $params->append(foo => ['bar', 'baz'], bar => 23);

Append parameters. Note that this method will normalize the parameters.

# "foo=bar&foo=baz"
Mojo::Parameters->new('foo=bar')->append(foo => 'baz');

# "foo=bar&foo=baz&foo=yada"
Mojo::Parameters->new('foo=bar')->append(foo => ['baz', 'yada']);

# "foo=bar&foo=baz&foo=yada&bar=23"
Mojo::Parameters->new('foo=bar')->append(foo => ['baz', 'yada'], bar => 23);

clone

my $params2 = $params->clone;

Clone parameters.

merge

$params = $params->merge(Mojo::Parameters->new(foo => 'b&ar', baz => 23));

Merge Mojo::Parameters objects. Note that this method will normalize the parameters.

new

my $params = Mojo::Parameters->new;
my $params = Mojo::Parameters->new('foo=b%3Bar&baz=23');
my $params = Mojo::Parameters->new(foo => 'b&ar');
my $params = Mojo::Parameters->new(foo => ['ba&r', 'baz']);
my $params = Mojo::Parameters->new(foo => ['bar', 'baz'], bar => 23);

Construct a new Mojo::Parameters object and "parse" parameters if necessary.

param

my @names       = $params->param;
my $foo         = $params->param('foo');
my @foo         = $params->param('foo');
my ($foo, $bar) = $params->param(['foo', 'bar']);
$params         = $params->param(foo => 'ba&r');
$params         = $params->param(foo => qw(ba&r baz));
$params         = $params->param(foo => ['ba;r', 'baz']);

Check and replace parameter value. Be aware that if you request a parameter by name in scalar context, you will receive only the first value for that parameter, if there are multiple values for that name. In list context you will receive all of the values for that name. Note that this method will normalize the parameters.

params

my $array = $params->params;
$params   = $params->params([foo => 'b&ar', baz => 23]);

Parsed parameters. Note that this method will normalize the parameters.

parse

$params = $params->parse('foo=b%3Bar&baz=23');

Parse parameters.

remove

$params = $params->remove('foo');

Remove parameters. Note that this method will normalize the parameters.

# "bar=yada"
Mojo::Parameters->new('foo=bar&foo=baz&bar=yada')->remove('foo');

to_hash

my $hash = $params->to_hash;

Turn parameters into a hash reference. Note that this method will normalize the parameters.

# "baz"
Mojo::Parameters->new('foo=bar&foo=baz')->to_hash->{foo}[1];

to_string

my $str = $params->to_string;

Turn parameters into a string.

OPERATORS

Mojo::Parameters overloads the following operators.

array

my @params = @$params;

Alias for "params". Note that this will normalize the parameters.

say $params->[0];
say for @$params;

bool

my $bool = !!$params;

Always true.

stringify

my $str = "$params";

Alias for "to_string".

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.