WeasyPrint v68 Has Been Released
WeasyPrint v68 has been released! Among the new features and bug fixes, the changelog contains important API changes and security information about URL fetchers.
⚠️ If you use custom URL fetchers or restrict allowed protocols, you have to upgrade WeasyPrint to avoid possible server-side request forgery (SSRF). ⚠️
New URL Fetchers
Version 68 introduces a new way to define URL fetchers.
For a very long time, WeasyPrint has offered a way to define a
url_fetcher function that is called to retrieve external
resources. This mechanism has been very useful to define a custom way to fetch
data, to add extra security check for example.
A default function, called default_url_fetcher(), was available.
This function was often called as a fallback solution in custom URL fetchers.
Unfortunately, this API had a limitation: the default URL fetcher doesn’t know
what the custom URL fetcher is, for example for redirections. It means that
HTTP redirections did not go through the custom URL fetcher, which may
lead to possible security problems.
The solution proposed to solve this problem is a new
URLFetcher class. This class provides a fetch() method
that can be overridden. This way, users can create custom URL fetchers that
inherit from the default one, and all the fetchers of the class hierarchy are
able to call the custom URL fetcher if needed.
This new API comes with two features: the allow_redirects and
fail_on_errors parameters can be set, to reject redirects and to
abort the whole rendering when HTTP errors occur.
The default_url_fetcher() function is now deprecated.
By default, for security reasons, redirects are forbidden when using it. Using
the URLFetcher class instead is safe, even for HTTP redirects.
Improve Generation of E-Invoices
A new, simpler interface has been added to generate European e-invoices.
In Europe, electronic invoices will soon be mandatory. These are PDF documents that include metadata, so that tax declaration and other accountability tasks can be done automatically. 📃
WeasyPrint provided a Python interface to generate these documents. But the feature required to write custom Python scripts, which can be complicated for some users.
The new API provided by WeasyPrint is now available from the command-line interface. Users can provide metadata that will be included into the PDF, and more easily generate invoices that respect the Factur-X / ZUGFeRD standard.
Interested in this feature? An example is provided in the documentation.
And More…
As usual, this new version of WeasyPrint comes with various improvements and 🐛 bug fixes, including:
- Support of emoji fonts based on SVG has been improved, with with better position and size of emojis, faster SVG parsing, and various crashes fixed. 😁
-
@font-facefonts can now be used in SVG CSS. - Fix various parsing errors of colors, text decoration thickness and font feature settings.
- Honor language-specific rules for uppercase, lowercase and capitalize text transformations.
What’s Next?
We hope you’ll have fun with this new version!
We’re really glad to have 6 people contributing to the repository for this version! 💜 We just reached 150 contributors from all around the world, and we’re really grateful to all the people writing code, reporting issues, and improving documentation.
Thanks to all the regular sponsors that really help us finding, solving and testing all the small issues we regularly fix in new releases 💖.
As explained in the previous article, we also work on new CSS specifications. If you’re interested in:
- layouts that cover facing pages;
- page breaks in tables, grid layouts, flex layouts;
- notes displayed on different parts of the page;
you may be interested in our future articles. Get in touch if you want to know more!
You know great designers who can create incredible design samples, but you’d like to turn them into carefully structured dynamic documents? With more than 15 years of experience creating documents in CSS, we can probably help you. We propose professional support for all kinds of companies. Send us a mail, we’ll be happy to talk to you and learn more about your needs!