Skip to content

Statamic's Antlers sanitizer cannot effectively sanitize malicious SVG

Moderate severity GitHub Reviewed Published Jul 5, 2023 in statamic/cms • Updated Nov 10, 2023

Package

composer statamic/cms (Composer)

Affected versions

< 4.10.0

Patched versions

4.10.0

Description

Antlers sanitizer cannot effectively sanitize malicious SVG

Summary

The SVG tag does not sanitize malicious SVG. Therefore, an attacker can exploit this vulnerability to perform XSS attacks using SVG, even when using the sanitize function.

Details

Regarding the previous discussion mentioned here, it has been identified that the default blacklist in the FilesFieldtypeController (located at this link) only blocks certain file extensions such as php, php3, php4, php5, and phtml. This allows a malicious user to upload a manipulated SVG file disguised as a social media icon, potentially triggering an XSS vulnerability.

PoC Screenshot

image

PoC

  1. Create new Global set, let's say "Settings"
  2. Create a "Grid" field in Blueprint (named: social), then add somefields Name (text), URL (text) and Icon (Assets) in the section Fields.
  3. When calling the social setting in the _footer.antlers.html, remember to sanitize
{{ settings:social }}
    <a href="{{ $url }}" class="ml-4" aria-label="{{ $name }}" rel="noopener">
        {{ svg :src="icon" class="h-6 w-6 hover:text-hot-pink" | sanitize }}
    </a>
{{ /settings:social }}
  1. Upload the malicious SVG image, here is the code:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg width="500" height="500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
   <text x="20" y="35">Statamic</text>
   <foreignObject width="500" height="500">
            <iframe xmlns="http://www.w3.org/1999/xhtml" src="javascript:confirm(document.cookie);" width="400" height="250"/>
   </foreignObject>
</svg>

Impact

Since the social media icon is displayed in the footer layout, any user can view it, potentially leading to the execution of XSS.

Suggestions to Mitigate or Resolve the Issue:

Sanitize when outputing the svg. This vulnerability caused by unsanitized File::get() when retrieving the SVG, it is crucial to sanitize the SVG when outputting it. The issue can be found in the following file: https://github.com/statamic/cms/blob/f806b6b007ddcf066082eef175653c5beaa96d60/src/Tags/Svg.php#L36-L40.

It is highly recommended to implement proper sanitization measures to ensure the security of the SVG content. One effective approach is to utilize a reliable package, such as https://github.com/darylldoyle/svg-sanitizer ,which provides comprehensive SVG sanitization capabilities.

So the code becomes:

use enshrined\svgSanitize\Sanitizer;

if (File::exists($file)) {
                
    $sanitizer = new Sanitizer();
    $dirtySVG = File::get($file);

    $svg = $sanitizer->sanitize($dirtySVG);
    break;
}

Reference

References

@jasonvarga jasonvarga published to statamic/cms Jul 5, 2023
Published by the National Vulnerability Database Jul 5, 2023
Published to the GitHub Advisory Database Jul 6, 2023
Reviewed Jul 6, 2023
Last updated Nov 10, 2023

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
High
Privileges required
Low
User interaction
Required
Scope
Changed
Confidentiality
Low
Integrity
Low
Availability
Low

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L

EPSS score

0.098%
(42nd percentile)

Weaknesses

CVE ID

CVE-2023-36828

GHSA ID

GHSA-6r5g-cq4q-327g

Source code

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.