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::UserAgent::Transactor - User agent transactor

SYNOPSIS

use Mojo::UserAgent::Transactor;

# Simple GET request
my $t = Mojo::UserAgent::Transactor->new;
say $t->tx(GET => 'http://example.com')->req->to_string;

# PATCH request with "Do Not Track" header and content
say $t->tx(PATCH => 'example.com' => {DNT => 1} => 'Hi!')->req->to_string;

# POST request with form-data
say $t->tx(POST => 'example.com' => form => {a => 'b'})->req->to_string;

# PUT request with JSON data
say $t->tx(PUT => 'example.com' => json => {a => 'b'})->req->to_string;

DESCRIPTION

Mojo::UserAgent::Transactor is the transaction building and manipulation framework used by Mojo::UserAgent.

ATTRIBUTES

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

generators

my $generators = $t->generators;
$t             = $t->generators({foo => sub {...}});

Registered content generators.

METHODS

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

new

my $t = Mojo::UserAgent::Transactor->new;

Construct a new transactor and register form and json content generators.

add_generator

$t = $t->add_generator(foo => sub {...});

Register a new content generator.

endpoint

my ($proto, $host, $port) = $t->endpoint(Mojo::Transaction::HTTP->new);

Actual endpoint for transaction.

peer

my ($proto, $host, $port) = $t->peer(Mojo::Transaction::HTTP->new);

Actual peer for transaction.

proxy_connect

my $tx = $t->proxy_connect(Mojo::Transaction::HTTP->new);

Build Mojo::Transaction::HTTP proxy connect request for transaction if possible.

redirect

my $tx = $t->redirect(Mojo::Transaction::HTTP->new);

Build Mojo::Transaction::HTTP followup request for 301, 302, 303, 307 or 308 redirect response if possible.

tx

my $tx = $t->tx(GET  => 'example.com');
my $tx = $t->tx(POST => 'http://example.com');
my $tx = $t->tx(GET  => 'http://example.com' => {DNT => 1});
my $tx = $t->tx(PUT  => 'http://example.com' => 'Hi!');
my $tx = $t->tx(PUT  => 'http://example.com' => form => {a => 'b'});
my $tx = $t->tx(PUT  => 'http://example.com' => json => {a => 'b'});
my $tx = $t->tx(POST => 'http://example.com' => {DNT => 1} => 'Hi!');
my $tx = $t->tx(
  PUT  => 'http://example.com' => {DNT => 1} => form => {a => 'b'});
my $tx = $t->tx(
  PUT  => 'http://example.com' => {DNT => 1} => json => {a => 'b'});

Versatile general purpose Mojo::Transaction::HTTP transaction builder for requests, with support for content generators.

# Generate and inspect custom GET request with DNT header and content
say $t->tx(GET => 'example.com' => {DNT => 1} => 'Bye!')->req->to_string;

# Use a custom socket for processing this transaction
my $tx = $t->tx(GET => 'http://example.com');
$tx->connection($sock);

# Stream response content to STDOUT
my $tx = $t->tx(GET => 'http://example.com');
$tx->res->content->unsubscribe('read')->on(read => sub { say $_[1] });

# PUT request with content streamed from file
my $tx = $t->tx(PUT => 'http://example.com');
$tx->req->content->asset(Mojo::Asset::File->new(path => '/foo.txt'));

# GET request with query parameters
my $tx = $t->tx(GET => 'http://example.com' => form => {a => 'b'});

# POST request with "application/json" content
my $tx = $t->tx(
  POST => 'http://example.com' => json => {a => 'b', c => [1, 2, 3]});

# POST request with "application/x-www-form-urlencoded" content
my $tx = $t->tx(
  POST => 'http://example.com' => form => {a => 'b', c => 'd'});

# PUT request with UTF-8 encoded form values
my $tx = $t->tx(
  PUT => 'http://example.com' => form => {a => 'b'} => charset => 'UTF-8');

# POST request with form values sharing the same name
my $tx = $t->tx(POST => 'http://example.com' => form => {a => [qw(b c d)]});

# POST request with "multipart/form-data" content
my $tx = $t->tx(
  POST => 'http://example.com' => form => {mytext => {content => 'lala'}});

# POST request with upload streamed from file
my $tx = $t->tx(
  POST => 'http://example.com' => form => {mytext => {file => '/foo.txt'}});

# POST request with upload streamed from asset
my $asset = Mojo::Asset::Memory->new->add_chunk('lalala');
my $tx    = $t->tx(
  POST => 'http://example.com' => form => {mytext => {file => $asset}});

# POST request with multiple files sharing the same name
my $tx = $t->tx(POST => 'http://example.com' =>
  form => {mytext => [{content => 'first'}, {content => 'second'}]});

# POST request with form values and customized upload (filename and header)
my $tx = $t->tx(POST => 'http://example.com' => form => {
  a      => 'b',
  c      => 'd',
  mytext => {
    content        => 'lalala',
    filename       => 'foo.txt',
    'Content-Type' => 'text/plain'
  }
});

The form content generator will automatically use query parameters for GET/HEAD requests and the "application/x-www-form-urlencoded" content type for everything else. Both get upgraded automatically to using the "multipart/form-data" content type when necessary or when the header has been set manually.

# Force "multipart/form-data"
my $headers = {'Content-Type' => 'multipart/form-data'};
my $tx = $t->tx(POST => 'example.com' => $headers => form => {a => 'b'});

upgrade

my $tx = $t->upgrade(Mojo::Transaction::HTTP->new);

Build Mojo::Transaction::WebSocket followup transaction for WebSocket handshake if possible.

websocket

my $tx = $t->websocket('ws://example.com');
my $tx = $t->websocket('ws://example.com' => {DNT => 1} => ['v1.proto']);

Versatile Mojo::Transaction::HTTP transaction builder for WebSocket handshake requests.

SEE ALSO

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