Cross-site Scripting when rendering error messages in laminas-form
Impact
When rendering validation error messages via the formElementErrors() view helper shipped with laminas-form, many messages will contain the submitted value. However, in vulnerable versions of laminas-form, the value was not being escaped for HTML contexts, which can potentially lead to a Reflected Cross-Site Scripting (XSS) attack.
Patches
The following versions were issued to mitigate the vulnerability:
- 2.17.1
- 3.0.2
- 3.1.1
Workarounds
At the top of a view script where you call the formElementErrors() view helper, place the following code:
use Laminas\Form\ElementInterface;
use Laminas\View\PhpRenderer;
$escapeMessages = function (ElementInterface $formOrElement, PhpRenderer $renderer): void {
$messages = $element->getMessages();
if (! $messages) {
return;
}
$escaped = [];
array_walk_recursive(
$messages,
static function (string $item) use (&$escaped, $renderer): void {
$escaped[] = $renderer->escapeHtml($item);
}
};
$element->setMessages($escaped);
};
Before calling formElementErrors() with a form, fieldset, or element, call the above closure as follows
// Usage with a form
// $this is the view renderer
$escapeMessages($form, $this);
// Usage with a fieldset
// $this is the view renderer
$escapeMessages($fieldset, $this);
// Usage with a form element
// $this is the view renderer
$escapeMessages($element, $this);
For more information
If you have any questions or comments about this advisory:
- Open an issue
- Email us at security@getlaminas.org
Affected software
Click a technology to see all vulnerabilities affecting it.
| Platform | Package | Vulnerable versions | Fixed in |
|---|---|---|---|
| Composer package | laminas/laminas-form | >= 3.1.0, < 3.1.1, >= 3.0.0, < 3.0.2, < 2.17.1 | 3.1.1, 3.0.2, 2.17.1 |
References
- https://github.com/laminas/laminas-form/security/advisories/GHSA-jq4p-mq33-w375
- https://nvd.nist.gov/vuln/detail/CVE-2022-23598
- https://github.com/laminas/laminas-form/commit/43005a3ec4c2292d4f825273768d9b884acbca37
- https://getlaminas.org/security/advisory/LP-2022-01
- https://github.com/laminas/laminas-form
- https://github.com/laminas/laminas-form/releases/tag/2.17.1
- https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/CFF6WJ5I7PSEBRF6I753WKE2BXFBGQXE
- https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/SLNABVK26CE4PFL57VLY242FW3QY4CPC
- CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N- Weakness (CWE)
CWE-79- Platform
- Composer
- Package
laminas/laminas-form- Disclosed
- 28.01.2022
- Updated
- 11.10.2026 10:22
Sources and licenses
OSV / GitHub Advisory Database - GHSA-jq4p-mq33-w375 - CC BY 4.0
Vulnerability history: laminas/laminas-form
All published vulnerabilities of this package (Composer package), newest first. Shows whether this is a one-off slip or a package that needs watching.
This is the only known vulnerability of this package.
Know which vulnerabilities affect your application
With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.