Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded images using data URIs no longer work without unsafe flag #383

Closed
stefanvdlugt opened this issue Mar 28, 2023 · 6 comments
Closed

Comments

@stefanvdlugt
Copy link

Since update 2.7.0, embedded images are ignored when converting SVG files without the unsafe flag.

The images are embedded as base64:

<image id="image" width="123" height="456" xlink:href="data:img/png;base64,BASE64STRING"></image>

As the description of the unsafe option states that it allows loading external files, we'd expect data URIs to still work. Is there an option to forbid loading external resources but allow including images using data URIs?

@joaniehollberg
Copy link

joaniehollberg commented Mar 31, 2023

We also are experiencing this issue. We are seeing images in our production environment rendering without backgrounds because of it. @liZe perhaps related to your recent changes?

@joaniehollberg
Copy link

@stefanvdlugt how were you able to get the unsafe flag to work? I got it to work via command line, but passing unsafe=True as an option into svg2png doesn't seem to work.

@stefanvdlugt
Copy link
Author

@joaniehollberg We haven't had the time to get this working yet. We are using the command line version, but we do not want to use the unsafe flag, since we only want to allow embedded resources.

The release notes of the latest version state that it is also possible to change the url_fetcher parameter in the Python module. Maybe it would be possible to let this url_fetcher only fetch embedded resources and not external ones?

@liZe
Copy link
Member

liZe commented Apr 3, 2023

We also are experiencing this issue. We are seeing images in our production environment rendering without backgrounds because of it. @liZe perhaps related to your recent changes?

Yes, accessing external resources has been disabled by default because it could lead to various security problems.

@stefanvdlugt how were you able to get the unsafe flag to work? I got it to work via command line, but passing unsafe=True as an option into svg2png doesn't seem to work.

It should work. Internally, the CLI option only sets the unsafe tag of the convert function.

We are using the command line version, but we do not want to use the unsafe flag, since we only want to allow embedded resources.

The unsafe can be set if you trust the SVG content. If you don’t, then we assumed that reaching external resources in the SVG is as dangerous as other security treats that the unsafe prevents.

Maybe it would be possible to let this url_fetcher only fetch embedded resources and not external ones?

If, for some reason, you don’t trust the SVG content but still want to reach external resources, then the url_fetcher option is the way to go.

Is there an option to forbid loading external resources but allow including images using data URIs?

We should allow data URLs, even without the unsafe option. Let’s close this issue when this feature is re-enabled.

@mlazar-endear
Copy link

We also ran into this issue using a data: URI for an embedded image. Confirming that using unsafe=True fixed it for us via the python library bindings, i.e.

cairosvg.svg2png(content, unsafe=True)

@liZe liZe closed this as completed in 2cbe306 Apr 18, 2023
@liZe
Copy link
Member

liZe commented Apr 18, 2023

This should be fixed now, tests are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants