← PHP / Laravel · Contents

PHP-072 / Intermediate

Serving uploaded SVG or HTML from the same origin

A03:2021 Injection · CWE-79 XSS · CWE-434 Unrestricted Upload

Why is this a problem?

A <script> inside an SVG executes under the site's origin.

How to fix it

php
$request->validate(['img' => 'mimes:jpg,png,webp']);   // Exclude SVG
// Serve from a separate domain or with Content-Disposition: attachment

Further reading