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

Fail to reder pdf because of recursive rendering image resource in html content #467

Open
h2nguyen opened this issue Apr 21, 2020 · 3 comments

Comments

@h2nguyen
Copy link

Hi Dan,

Something I encountered lately when playing around with openhtmltopdf lib. I don't know if this a known (if so sorry for this duplicate ticket) or even an issue. Following scenario example: I am rendering HTML content to a PDF file. In the HTML content there is an image tag, with <img src="https://image-creating.server>". One of the cool feature openhtmltopdf provided, it loads the image and renders the image source into the PDF as well. So far so good. Looking at the image providing server, the source example aforementioned, the server just returns an image as byte[] and shows the image directly under the requested URI.

Now the interesting part, the image providing server is the same server that generates the PDF/Image file using the same HTML content, which also contains the same image mentioned above. With the request the application server runs into a recursive never-ending state:
-> com.openhtmltopdf.load -> com.openhtmltopdf.match -> com.openhtmltopdf.load -> com.openhtmltopdf.match ...

This is happening because the scenario looks like it tries to load image/pdf into image/pdf recursively.

The question is, should openhtmltopdf detects this recursive call and catch with an exception or is this something the service application needs to handle?

image

@syjer
Copy link
Contributor

syjer commented Apr 27, 2020

hi @h2nguyen , I think it should be handled by the library, as it can be considered a denial of service.

@h2nguyen
Copy link
Author

@syjer yes one can solve this with your mentioned approach

danfickle added a commit that referenced this issue Dec 19, 2020
+ With test.
+ Cleanup of CSS code.
+ Removed stylesheet cache.
@danfickle
Copy link
Owner

I thought about this and I don't think there is any simple way to solve. We allow PDF stamping so even validating images as images would not be enough. Has anyone got any ideas?

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

3 participants