Skip to content
Advertisement

Content-Security-Policy (CSP): how to allow svg image in object

I am using the js plugin that adds inside itself SVG images. I have added CSP policy to my website, but I can’t configure it to allow plugin’s code.

Its code looks like:

JavaScript

I am looking for a configuration that allows SVG image that is rendered in the object. I am tried different options from there – CSP: object-src.

But I am alway get error like next:

JavaScript

How to configure CSP correct in this case?

Advertisement

Answer

That SVG image is provided by a data: URL, so your policy must be updated to allow that.

You don’t show your current policy or where you’re setting it, but assuming you’re setting it with the Content-Security-Policy header and it currently has object-src 'unsafe-eval', then you can allow data: URLs there by updating that part of the policy to look like this:

JavaScript

That shows just the relevant part of the current policy in the Content-Security-Policy header. Whatever other directives you currently have in that header value, you’d want to preserve as-is.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement