Closed icret closed 1 year ago
At the same time, I found that I also need to filter the a tag:
if ($handle->file_src_name_ext === 'svg') {
$svg = file_get_contents($handle->file_src_pathname);
if (preg_match('/<script[\s\S]*?<\/script>/', $svg) || stripos($svg, 'href=')) {
// do something
}
}
Well, it is not really possible to parse all the files uploaded to filter out these where there may be hidden scripts. Even if we did parse some dangerous SVG, it would give a flase sense of security, since we would probably leave some other dangerous SVG through.
SVG uses XML format to define images, so script scripts can be stored internally, thus generating XSS bugs. You want to filter script code from the code side.
Add script code to svg:
Short answer filtering is illegal: