xp-forge / frontend

Web frontends
1 stars 1 forks source link

By default, use CSP to prevent XSS with SVG files #49

Open thekid opened 2 months ago

thekid commented 2 months ago

Add this to web.frontend.AssetsFrom:

+ $res->header('Content-Security-Policy', 'script-src none; object-src none');

This would prevent scripts from being executed when opening an SVG file:

Yes, user-uploaded SVG files can include JavaScript. These execute if you load that image directly (top-level navigation). Someone could be sent a link to check out a funny meme on your website, and unwittingly be running scripts in your website's context in the background [...] To safely host SVG images, you need to [...] have a Content-Security-Policy (CSP) response header set on SVG images which denies running those scripts

Source: https://stackoverflow.com/questions/10557137/are-user-uploaded-svgs-a-xss-risk-how-can-you-sterilize-an-svg


On defaulting this: I'm not aware of any usecase where we would have static assets in which we would want scripts running. Still, there could be possible scenarios - maybe we want to be able to override this like new AssetsFrom(...)->allow(['script-src' => ...])?