CVE-2022-23638 is a critical cross-site scripting (XSS) vulnerability that affects all users of the svg-sanitizer library prior to version .15.. In this post, we'll dissect the vulnerability, discuss its implications, and show you code snippets to understand the underlying issue. We'll also provide links to original references and exploit details.

The svg-sanitizer Library

svg-sanitizer is a popular SVG/XML sanitizer written in PHP. It is widely used by developers to clean up and sanitize SVG files against potential security risks. The sanitizer removes undesirable elements, attributes, and styles that could lead to security vulnerabilities or affect the rendering of an SVG file.

Cross-Site Scripting Vulnerability

Cross-Site Scripting (XSS) is a type of web application security vulnerability that allows attackers to inject malicious scripts into websites and web applications. These malicious scripts can steal user data, hijack accounts, or even take control of the affected web application. In the context of svg-sanitizer, an insufficient sanitization process allows attackers to exploit the XSS vulnerability.

The Issue in svg-sanitizer

The vulnerability specifically impacts the library's handling of style attributes inside SVG elements, leading to inadequate sanitization of potentially malicious content. An attacker could inject malicious code within SVG elements that would be executed by the library, potentially impacting users or web applications relying on it.

Here is a simplified code snippet illustrating the issue

// Before the fix in Version .15.
function sanitize_style_attribute($attribute) {
    $sanitized_value = sanitize_input($attribute);
    return $sanitized_value;

// After the fix in Version .15.
function sanitize_style_attribute($attribute) {
    $sanitized_value = sanitize_input($attribute);
    if (is_valid_style_attribute($sanitized_value)) {
        return $sanitized_value;
    } else {
        return null;

As you can see, prior to the fix in version .15., the library did not properly validate and sanitize the style attributes inside SVG elements. Post .15., the library now properly verifies the sanitized value to eliminate any potential XSS risks.

The Fix

The svg-sanitizer library has addressed this vulnerability in version .15.. It is strongly recommended that you update to the latest version to mitigate this critical security risk. The updated code base ensures sufficient sanitization of style attributes inside SVG elements.

You can upgrade svg-sanitizer to version .15. by executing the following command

composer require darylldoyle/svg-sanitizer:.15.


The CVE-2022-23638 vulnerability is a significant security risk for users of svg-sanitizer library prior to version .15., exposing them to potential attacks via cross-site scripting. By upgrading to version .15., you can eliminate the risk and secure your web applications. Remember, there is currently no workaround available, so upgrading to the latest version is the only effective solution.

For more details about CVE-2022-23638 and its implications, consult the following resources

- CVE Record:
- svg-sanitizer GitHub Repository:
- Packagist:


Published on: 02/14/2022 21:15:00 UTC
Last modified on: 02/22/2022 21:06:00 UTC