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

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::Path - Path

SYNOPSIS

use Mojo::Path;

# Parse
my $path = Mojo::Path->new('/foo%2Fbar%3B/baz.html');
say $path->[0];

# Build
my $path = Mojo::Path->new('/i/♥');
push @$path, 'mojolicious';
say "$path";

DESCRIPTION

Mojo::Path is a container for paths used by Mojo::URL, based on RFC 3986.

ATTRIBUTES

Mojo::Path implements the following attributes.

charset

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

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

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

METHODS

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

canonicalize

$path = $path->canonicalize;

Canonicalize path by resolving . and .., in addition ... will be treated as . to protect from path traversal attacks.

# "/foo/baz"
Mojo::Path->new('/foo/./bar/../baz')->canonicalize;

# "/../baz"
Mojo::Path->new('/foo/../bar/../../baz')->canonicalize;

# "/foo/bar"
Mojo::Path->new('/foo/.../bar')->canonicalize;

clone

my $clone = $path->clone;

Clone path.

contains

my $bool = $path->contains('/i/♥/mojolicious');

Check if path contains given prefix.

# True
Mojo::Path->new('/foo/bar')->contains('/');
Mojo::Path->new('/foo/bar')->contains('/foo');
Mojo::Path->new('/foo/bar')->contains('/foo/bar');

# False
Mojo::Path->new('/foo/bar')->contains('/f');
Mojo::Path->new('/foo/bar')->contains('/bar');
Mojo::Path->new('/foo/bar')->contains('/whatever');

leading_slash

my $bool = $path->leading_slash;
$path    = $path->leading_slash($bool);

Path has a leading slash. Note that this method will normalize the path and that %2F will be treated as / for security reasons.

# "/foo/bar"
Mojo::Path->new('foo/bar')->leading_slash(1);

# "foo/bar"
Mojo::Path->new('/foo/bar')->leading_slash(0);

merge

$path = $path->merge('/foo/bar');
$path = $path->merge('foo/bar');
$path = $path->merge(Mojo::Path->new);

Merge paths. Note that this method will normalize both paths if necessary and that %2F will be treated as / for security reasons.

# "/baz/yada"
Mojo::Path->new('/foo/bar')->merge('/baz/yada');

# "/foo/baz/yada"
Mojo::Path->new('/foo/bar')->merge('baz/yada');

# "/foo/bar/baz/yada"
Mojo::Path->new('/foo/bar/')->merge('baz/yada');

new

my $path = Mojo::Path->new;
my $path = Mojo::Path->new('/foo%2Fbar%3B/baz.html');

Construct a new Mojo::Path object and "parse" path if necessary.

parse

$path = $path->parse('/foo%2Fbar%3B/baz.html');

Parse path.

to_abs_string

my $str = $path->to_abs_string;

Turn path into an absolute string.

# "/i/%E2%99%A5/mojolicious"
Mojo::Path->new('/i/%E2%99%A5/mojolicious')->to_abs_string;
Mojo::Path->new('i/%E2%99%A5/mojolicious')->to_abs_string;

parts

my $parts = $path->parts;
$path     = $path->parts([qw(foo bar baz)]);

The path parts. Note that this method will normalize the path and that %2F will be treated as / for security reasons.

# Part with slash
push @{$path->parts}, 'foo/bar';

to_dir

my $dir = $route->to_dir;

Clone path and remove everything after the right-most slash.

# "/i/%E2%99%A5/"
Mojo::Path->new('/i/%E2%99%A5/mojolicious')->to_dir->to_abs_string;

# "i/%E2%99%A5/"
Mojo::Path->new('i/%E2%99%A5/mojolicious')->to_dir->to_abs_string;

to_route

my $route = $path->to_route;

Turn path into a route.

# "/i/♥/mojolicious"
Mojo::Path->new('/i/%E2%99%A5/mojolicious')->to_route;
Mojo::Path->new('i/%E2%99%A5/mojolicious')->to_route;

to_string

my $str = $path->to_string;

Turn path into a string.

# "/i/%E2%99%A5/mojolicious"
Mojo::Path->new('/i/%E2%99%A5/mojolicious')->to_string;

# "i/%E2%99%A5/mojolicious"
Mojo::Path->new('i/%E2%99%A5/mojolicious')->to_string;

trailing_slash

my $bool = $path->trailing_slash;
$path    = $path->trailing_slash($bool);

Path has a trailing slash. Note that this method will normalize the path and that %2F will be treated as / for security reasons.

# "/foo/bar/"
Mojo::Path->new('/foo/bar')->trailing_slash(1);

# "/foo/bar"
Mojo::Path->new('/foo/bar/')->trailing_slash(0);

OPERATORS

Mojo::Path overloads the following operators.

array

my @parts = @$path;

Alias for "parts". Note that this will normalize the path and that %2F will be treated as / for security reasons.

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

bool

my $bool = !!$path;

Always true.

stringify

my $str = "$path";

Alias for "to_string".

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicious.org.