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

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

Mojolicious versions from 7.28 for Perl may generate weak HMAC session secrets. When creating a default app 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::EventEmitter - Event emitter base class

SYNOPSIS

package Cat;
use Mojo::Base 'Mojo::EventEmitter', -signatures;

# Emit events
sub poke ($self) { $self->emit(roar => 3) }

package main;

# Subscribe to events
my $tiger = Cat->new;
$tiger->on(roar => sub ($tiger, $times) { say 'RAWR!' for 1 .. $times });
$tiger->poke;

DESCRIPTION

Mojo::EventEmitter is a simple base class for event emitting objects.

EVENTS

Mojo::EventEmitter can emit the following events.

error

$e->on(error => sub ($e, $err) {...});

This is a special event for errors, it will not be emitted directly by this class, but is fatal if unhandled. Subclasses may choose to emit it, but are not required to do so.

$e->on(error => sub ($e, $err) { say "This looks bad: $err" });

METHODS

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

catch

$e = $e->catch(sub {...});

Subscribe to "error" event.

# Longer version
$e->on(error => sub {...});

emit

$e = $e->emit('foo');
$e = $e->emit('foo', 123);

Emit event.

has_subscribers

my $bool = $e->has_subscribers('foo');

Check if event has subscribers.

on

my $cb = $e->on(foo => sub {...});

Subscribe to event.

$e->on(foo => sub ($e, @args) {...});

once

my $cb = $e->once(foo => sub {...});

Subscribe to event and unsubscribe again after it has been emitted once.

$e->once(foo => sub ($e, @args) {...});

subscribers

my $subscribers = $e->subscribers('foo');

All subscribers for event.

# Unsubscribe last subscriber
$e->unsubscribe(foo => $e->subscribers('foo')->[-1]);

# Change order of subscribers
@{$e->subscribers('foo')} = reverse @{$e->subscribers('foo')};

unsubscribe

$e = $e->unsubscribe('foo');
$e = $e->unsubscribe(foo => $cb);

Unsubscribe from event.

DEBUGGING

You can set the MOJO_EVENTEMITTER_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.

MOJO_EVENTEMITTER_DEBUG=1

SEE ALSO

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