Antlers sanitizer cannot effectively sanitize malicious SVG
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.
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.
_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 }}
<?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>
Since the social media icon is displayed in the footer layout, any user can view it, potentially leading to the execution of XSS.
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;
}
{ "nvd_published_at": "2023-07-05T22:15:10Z", "cwe_ids": [ "CWE-79" ], "severity": "MODERATE", "github_reviewed": true, "github_reviewed_at": "2023-07-06T20:56:28Z" }