Security Advisories (1)
CVE-2022-4993 (2026-08-13)

HTML::FormHandler versions through 0.40068 for Perl allow attacker selected method dispatch and resource exhaustion because _apply_actions and add_error use error message text built from request data as a Locale::Maketext bracket notation template. add_error hands its first argument to the language handle as the Locale::Maketext message key, and the default handle's lexicon sets `_AUTO`, so a string that is not a lexicon entry is compiled as a bracket notation template instead of being looked up. In a bracket group the first token names a method called on the language handle and the remaining tokens are its arguments. Three kinds of text the library did not author reach that position. _apply_actions installs a `$SIG{__WARN__}` handler that stores the warning text in `$error_message`, and a captured warning survives a successful action, so a field carrying a numeric transform turns `Argument "[sprintf,%50000000d,0]" isn't numeric` into the template; a warning quotes the submitted value verbatim, so the group is well formed and dispatches. `$error_message ||= $tobj->validate($new_value)` takes a type constraint's own failure message, which renders the rejected value through a partial dumper in bracket and comma form (Devel::PartialDump when Moose can load it, Type::Tiny's own dumper always), so a field with `apply => [ Str ]` given a parameter sent more than once, which arrives as an array, gets `Reference ["a","b"] did not pass type constraint "Str"` as its template, from a request that carries no bracket character of its own. A coercion or transform exception reaches it the same way. Beyond those, a validator whose message contains the field value puts that value in the template directly, and add_error replaces the message list with the contents of an arrayref first argument (`@message = @{$message[0]} if ref $message[0] eq 'ARRAY'`), so a value arriving as an array fills the argument slots from the same request as well. A malformed group such as `[0]` makes the compile croak, and HTML::FormHandler::I18N::maketext and add_error each re-raise that as a die, so process() throws. A well formed group naming sprintf reaches CORE::sprintf with an attacker chosen field width. Any caller that applies a type constraint or a transform to an untrusted field, or whose validator passes an untrusted field value to add_error, can be made to throw an unhandled exception out of process(), or to allocate an arbitrary amount of memory in one request, and an application whose language handle subclass defines side effecting public methods makes those callable with attacker chosen arguments. The dumped type constraint message is bounded to the exception, because both dumpers quote non-numeric elements so the method slot is never an attacker chosen name. The built-in messages pass fixed templates with the value in an argument slot, where it stays inert, and the built-in field types attach explicit message callbacks, so neither is affected.

NAME

HTML::FormHandler::Model - default model base class

VERSION

version 0.40068

SYNOPSIS

This class defines the base attributes for FormHandler model classes. It is not used directly.

DESCRIPTION

This is an empty base class that defines methods called by HTML::FormHandler to support interfacing forms with a data store such as a database.

This module provides instructions on methods to override to create a HTML::FormHandler::Model class to work with a specific object relational mapping (ORM) tool.

METHODS

item, build_item

The "item" is initialized with "build_item" the first time $form->item is called. "item" must be defined in the model class to fetch the object based on the item id. It should return the item's object. Column values are fetched and updated by calling methods on the returned object.

For example, with Class::DBI you might return:

return $self->item_class->retrieve( $self->item_id );

item_id

The id (primary key) of the item (object) that the form is updating or has just created. The model class should have a build_item method that can fetch the object from the item_class for this id.

item_class

"item_class" sets and returns a value used by the model class to access the ORM class related to a form.

For example:

has '+item_class' => ( default => 'User' );

This gives the model class a way to access the data store. If this is not a fixed value (as above) then do not define the method in your subclass and instead set the value when the form is created:

my $form = MyApp::Form::Users->new( item_class => $class );

The value can be any scalar (or object) needed by the specific ORM to access the data related to the form.

A builder for 'item_class' might be to return the class of the 'item'.

guess_field_type

Returns the guessed field type. The field name is passed as the first argument. This is only required if using "Auto" type of fields in your form classes. You could override this in your form class, for example, if you use a field naming convention that indicates the field type.

The metadata info about the columns can be used to assign types.

lookup_options

Retrieve possible options for a given select field from the database. The default method returns undef.

Returns an array reference of key/value pairs for the column passed in. These values are used for the values and labels for field types that provide a list of options to select from (e.g. Select, Multiple).

A 'Select' type field (or a field that inherits from HTML::FormHandler::Field::Select) can set a number of scalars that control how options are looked up:

label_column()          - column that holds the label
active_column()         - column that indicates if a row is acitve
sort_column()           - column used for sorting the options

The default for label_column is "name".

validate_model

Validates fields that are dependent on the model. This is called via the validation process and the model class must at least validate "unique" constraints defined in the form class.

Any errors on a field found should be set by calling the field's add_error method:

$field->add_error('Value must be unique in the database');

The default method does nothing.

clear_model

Clear out any dynamic data for persistent object

update_model

Update the model with validated fields

AUTHOR

FormHandler Contributors - see HTML::FormHandler

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Gerda Shank.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.