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

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 an HMAC session cookie secret by default. These predictable default secrets can be exploited by an attacker 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.

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

Mojolicious versions from 7.28 for Perl will generate weak HMAC session cookie secrets via "mojo generate app" by default When creating a default app skeleton with the "mojo generate app" tool, a weak secret is written to the application's configuration file using the insecure rand() function, and used for authenticating and protecting the integrity of the application's sessions. This may allow an attacker to brute force the application's session keys.

NAME

Mojo::UserAgent::CookieJar - Cookie jar for HTTP user agents

SYNOPSIS

use Mojo::UserAgent::CookieJar;

# Add response cookies
my $jar = Mojo::UserAgent::CookieJar->new;
$jar->add(
  Mojo::Cookie::Response->new(
    name   => 'foo',
    value  => 'bar',
    domain => 'localhost',
    path   => '/test'
  )
);

# Find request cookies
for my $cookie (@{$jar->find(Mojo::URL->new('http://localhost/test'))}) {
  say $cookie->name;
  say $cookie->value;
}

DESCRIPTION

Mojo::UserAgent::CookieJar is a minimalistic and relaxed cookie jar used by Mojo::UserAgent, based on RFC 6265.

ATTRIBUTES

Mojo::UserAgent::CookieJar implements the following attributes.

ignore

my $ignore = $jar->ignore;
$jar       = $jar->ignore(sub {...});

A callback used to decide if a cookie should be ignored by "collect".

# Ignore all cookies
$jar->ignore(sub { 1 });

# Ignore cookies for domains "com", "net" and "org"
$jar->ignore(sub {
  my $cookie = shift;
  return undef unless my $domain = $cookie->domain;
  return $domain eq 'com' || $domain eq 'net' || $domain eq 'org';
});
my $size = $jar->max_cookie_size;
$jar     = $jar->max_cookie_size(4096);

Maximum cookie size in bytes, defaults to 4096 (4KiB).

METHODS

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

add

$jar = $jar->add(@cookies);

Add multiple Mojo::Cookie::Response objects to the jar.

all

my $cookies = $jar->all;

Return all Mojo::Cookie::Response objects that are currently stored in the jar.

# Names of all cookies
say $_->name for @{$jar->all};

collect

$jar->collect(Mojo::Transaction::HTTP->new);

Collect response cookies from transaction.

empty

$jar->empty;

Empty the jar.

find

my $cookies = $jar->find(Mojo::URL->new);

Find Mojo::Cookie::Request objects in the jar for Mojo::URL object.

# Names of all cookies found
say $_->name for @{$jar->find(Mojo::URL->new('http://example.com/foo'))};

prepare

$jar->prepare(Mojo::Transaction::HTTP->new);

Prepare request cookies for transaction.

SEE ALSO

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