CVE-2022-23598
JSON

6.1medium

Reflected XSS vulnerability when rendering error messages in laminas-form

Severity
6.1medium CVSS:3.1 by GitHub_M
Exploit likelihood
1.02% (higher than 63% of CVEs)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-jq4p-mq33-w375

Description

laminas-form is a package for validating and displaying simple and complex forms. When rendering validation error messages via the `formElementErrors()` view helper shipped with laminas-form, many messages will contain the submitted value. However, in laminas-form prior to version 3.1.1, the value was not being escaped for HTML contexts, which could potentially lead to a reflected cross-site scripting attack. Versions 3.1.1 and above contain a patch to mitigate the vulnerability. A workaround is available. One may manually place code at the top of a view script where one calls the `formElementErrors()` view helper. More information about this workaround is available on the GitHub Security Advisory.

Affected

Product or packageVersionsReported by
laminas laminas-form< 3.1.1CVE List
laminas/laminas-form (Packagist)from 3.1.0 before 3.1.1, from 3.0.0 before 3.0.2, before 2.17.1GitHub Advisory Database
getlaminas laminas-formbefore 2.17.1, from 3.0.0 before 3.0.2, 3.1.0NVD
fedoraproject fedora34, 35NVD

All scores

GitHub_M6.1medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
GitHub6.1medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
NVD6.1medium CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
NVD4.3medium CVSS:2.0AV:N/AC:M/Au:N/C:N/I:P/A:N

Classification

CWE-79

SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.

What each source says

CVE List

laminas-form is a package for validating and displaying simple and complex forms. When rendering validation error messages via the `formElementErrors()` view helper shipped with laminas-form, many messages will contain the submitted value. However, in laminas-form prior to version 3.1.1, the value was not being escaped for HTML contexts, which could potentially lead to a reflected cross-site scripting attack. Versions 3.1.1 and above contain a patch to mitigate the vulnerability. A workaround is available. One may manually place code at the top of a view script where one calls the `formElementErrors()` view helper. More information about this workaround is available on the GitHub Security Advisory.

GitHub Advisory Database
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:

NVD (es)

laminas-form es un paquete para la comprobación y visualización de formularios simples y complejos. Cuando son mostrados los mensajes de error de comprobación por medio del ayudante de vista "formElementErrors()" incluido en laminas-form, muchos mensajes contienen el valor enviado. Sin embargo, en laminas-form versiones anteriores a 3.1.1, el valor no es escapado para los contextos HTML, lo que potencialmente podía conllevar a un ataque de tipo Cross-site scripting reflejado. Las versiones 3.1.1 y superiores contienen un parche para mitigar la vulnerabilidad. Se presenta una solución disponible. Puede colocarse manualmente un código en la parte superior de un script de visualización donde es llamado al ayudante de visualización "formElementErrors()". Se presenta más información sobre esta medida de mitigación en el aviso de seguridad de GitHub

References

https://github.com/laminas/laminas-form/security/advisories/GHSA-jq4p-mq33-w375mitigation, third-party-advisory, web
https://github.com/laminas/laminas-form/commit/43005a3ec4c2292d4f825273768d9b884acbca37patch, third-party-advisory, web
https://getlaminas.org/security/advisory/LP-2022-01mitigation, third-party-advisory, web
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/SLNABVK26CE4PFL57VLY242FW3QY4CPC/vendor-advisory
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/CFF6WJ5I7PSEBRF6I753WKE2BXFBGQXE/vendor-advisory
https://nvd.nist.gov/vuln/detail/CVE-2022-23598advisory
https://github.com/laminas/laminas-formweb
https://github.com/laminas/laminas-form/releases/tag/2.17.1web
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/CFF6WJ5I7PSEBRF6I753WKE2BXFBGQXEweb
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/SLNABVK26CE4PFL57VLY242FW3QY4CPCweb

Sources

SourceRecordLicence
CVE ListCVE-2022-23598 changed 2025-04-23CVE Terms of Use
GitHub Advisory DatabaseGHSA-jq4p-mq33-w375 changed 2024-02-19CC-BY-4.0
NVDCVE-2022-23598 changed 2026-06-17Public domain