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::Asset::File - File storage for HTTP content

SYNOPSIS

use Mojo::Asset::File;

# Temporary file
my $file = Mojo::Asset::File->new;
$file->add_chunk('foo bar baz');
say 'File contains "bar"' if $file->contains('bar') >= 0;
say $file->slurp;

# Existing file
my $file = Mojo::Asset::File->new(path => '/home/sri/foo.txt');
$file->move_to('/yada.txt');
say $file->slurp;

DESCRIPTION

Mojo::Asset::File is a file storage backend for HTTP content.

EVENTS

Mojo::Asset::File inherits all events from Mojo::Asset.

ATTRIBUTES

Mojo::Asset::File inherits all attributes from Mojo::Asset and implements the following new ones.

cleanup

my $bool = $file->cleanup;
$file    = $file->cleanup($bool);

Delete "path" automatically once the file is not used anymore.

handle

my $handle = $file->handle;
$file      = $file->handle(IO::File->new);

Filehandle, created on demand for "path", which can be generated automatically and safely based on "tmpdir".

path

my $path = $file->path;
$file    = $file->path('/home/sri/foo.txt');

File path used to create "handle".

tmpdir

my $tmpdir = $file->tmpdir;
$file      = $file->tmpdir('/tmp');

Temporary directory used to generate "path", defaults to the value of the MOJO_TMPDIR environment variable or auto-detection.

METHODS

Mojo::Asset::File inherits all methods from Mojo::Asset and implements the following new ones.

add_chunk

$file = $file->add_chunk('foo bar baz');

Add chunk of data.

contains

my $position = $file->contains('bar');

Check if asset contains a specific string.

get_chunk

my $bytes = $file->get_chunk($offset);
my $bytes = $file->get_chunk($offset, $max);

Get chunk of data starting from a specific position, defaults to a maximum chunk size of 131072 bytes (128KiB).

is_file

my $bool = $file->is_file;

True, this is a Mojo::Asset::File object.

move_to

$file = $file->move_to('/home/sri/bar.txt');

Move asset data into a specific file and disable "cleanup".

mtime

my $mtime = $file->mtime;

Modification time of asset.

new

my $file = Mojo::Asset::File->new;
my $file = Mojo::Asset::File->new(path => '/home/sri/test.txt');
my $file = Mojo::Asset::File->new({path => '/home/sri/test.txt'});

Construct a new Mojo::Asset::File object.

size

my $size = $file->size;

Size of asset data in bytes.

slurp

my $bytes = $file->slurp;

Read all asset data at once.

to_file

$file = $file->to_file;

Does nothing but return the invocant, since we already have a Mojo::Asset::File object.

SEE ALSO

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