GHSA-JQ4P-MQ33-W375
Vulnerability from github – Published: 2022-01-28 23:08 – Updated: 2022-02-07 21:16
VLAI?
Summary
Cross-site Scripting when rendering error messages in laminas-form
Details
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
Severity ?
6.1 (Medium)
{
"affected": [
{
"package": {
"ecosystem": "Packagist",
"name": "laminas/laminas-form"
},
"ranges": [
{
"events": [
{
"introduced": "3.1.0"
},
{
"fixed": "3.1.1"
}
],
"type": "ECOSYSTEM"
}
]
},
{
"package": {
"ecosystem": "Packagist",
"name": "laminas/laminas-form"
},
"ranges": [
{
"events": [
{
"introduced": "3.0.0"
},
{
"fixed": "3.0.2"
}
],
"type": "ECOSYSTEM"
}
]
},
{
"package": {
"ecosystem": "Packagist",
"name": "laminas/laminas-form"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "2.17.1"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2022-23598"
],
"database_specific": {
"cwe_ids": [
"CWE-79"
],
"github_reviewed": true,
"github_reviewed_at": "2022-01-28T18:49:08Z",
"nvd_published_at": "2022-01-28T22:15:00Z",
"severity": "MODERATE"
},
"details": "### Impact\n\nWhen 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.\n\n### Patches\n\nThe following versions were issued to mitigate the vulnerability:\n\n- 2.17.1\n- 3.0.2\n- 3.1.1\n\n### Workarounds\n\nAt the top of a view script where you call the `formElementErrors()` view helper, place the following code:\n\n```php\nuse Laminas\\Form\\ElementInterface;\nuse Laminas\\View\\PhpRenderer;\n\n$escapeMessages = function (ElementInterface $formOrElement, PhpRenderer $renderer): void {\n $messages = $element-\u003egetMessages();\n if (! $messages) {\n return;\n }\n\n $escaped = [];\n array_walk_recursive(\n $messages,\n static function (string $item) use (\u0026$escaped, $renderer): void {\n $escaped[] = $renderer-\u003eescapeHtml($item);\n }\n };\n\n $element-\u003esetMessages($escaped);\n};\n```\n\nBefore calling `formElementErrors()` with a form, fieldset, or element, call the above closure as follows\n\n```php\n// Usage with a form\n// $this is the view renderer\n$escapeMessages($form, $this);\n\n// Usage with a fieldset\n// $this is the view renderer\n$escapeMessages($fieldset, $this);\n\n// Usage with a form element\n// $this is the view renderer\n$escapeMessages($element, $this);\n```\n\n### For more information\n\nIf you have any questions or comments about this advisory:\n\n* [Open an issue](https://github.com/laminas/laminas-form/issues/new)\n* Email us at [security@getlaminas.org](mailto:security@getlaminas.org)",
"id": "GHSA-jq4p-mq33-w375",
"modified": "2022-02-07T21:16:31Z",
"published": "2022-01-28T23:08:29Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/laminas/laminas-form/security/advisories/GHSA-jq4p-mq33-w375"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2022-23598"
},
{
"type": "WEB",
"url": "https://github.com/laminas/laminas-form/commit/43005a3ec4c2292d4f825273768d9b884acbca37"
},
{
"type": "WEB",
"url": "https://getlaminas.org/security/advisory/LP-2022-01"
},
{
"type": "WEB",
"url": "https://github.com/laminas/laminas-form"
},
{
"type": "WEB",
"url": "https://github.com/laminas/laminas-form/releases/tag/2.17.1"
},
{
"type": "WEB",
"url": "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/CFF6WJ5I7PSEBRF6I753WKE2BXFBGQXE"
},
{
"type": "WEB",
"url": "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/SLNABVK26CE4PFL57VLY242FW3QY4CPC"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N",
"type": "CVSS_V3"
}
],
"summary": "Cross-site Scripting when rendering error messages in laminas-form"
}
Loading…
Loading…
Sightings
| Author | Source | Type | Date |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Loading…
Loading…