mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.54k stars 645 forks source link

Azure image not rendered on Heroku, but it is rendered locally #766

Closed SalvesTestservices closed 6 years ago

SalvesTestservices commented 6 years ago

In my PDF I want to show an image, which is stored in an Azure blob. I have added this:

image_tag("https://myblob.blob.core.windows.net/foldername/image.jpg")

When I generate the PDF on my local environment it works fine, but when I generate the same PDF in production (Heroku), it doesn't show the image. Also wicked_pdf_image_tag is not working. What could be the problem?

It cannot be the access rights, because when I enter the image URL in a browser it shows the image.

unixmonkey commented 6 years ago

It might still be access rights. How does your app authorize this, or is it open to the world?

Create an html file on your filesystem with this:

<!doctype html>
<html>
  <head><title>test</title></head>
  <body>
    <h1>test</h1>
    <img src="https://myblob.blob.core.windows.net/foldername/image.jpg">
  </body>
</html>

Does it still work?

SalvesTestservices commented 6 years ago

Yes that does work, these images are open to the world.

unixmonkey commented 6 years ago

Would you mind sharing one such image that definitely doesn't PDF for you, and what versions of wicked_pdf and wkhtmltopdf you are using?

The only thing I can think of right now, is maybe they are being served over SSLv3, and you are on a somewhat out-of-date wkhtmltopdf. You can see this thread for more details on that if you want to go down that debugging path.

SalvesTestservices commented 6 years ago

The wicked_pdf version is 1.1.0. I'm not sure which version of wkhtmltopdf is being used on Heroku, I don't know ho to get that version number.

unixmonkey commented 6 years ago

Are you using wkhtmltopdf-heroku or wkhtmltopdf-binary-edge or something like that in your Gemfile/Gemfile.lock? What version of that are you using? If you can't find out that way (custom binary added to a buildpack), then you should be able to run wkhtmltopdf --version to find out.

SalvesTestservices commented 6 years ago

I forgot to use these gems, so I did that and deployed to Heroku, but still the images are not rendered. I use these gems:

wkhtmltopdf-binary-edge (0.12.5.0)
wkhtmltopdf-heroku (2.12.2.4)

Maybe a buildpack I should be using on Heroku?

SalvesTestservices commented 6 years ago

Sorry, closed it by accident :-)

SalvesTestservices commented 6 years ago

For me at the moment this solves the issue, as found in #344:

<%= image_tag image_url.gsub('https', 'http') %>

unixmonkey commented 6 years ago

This makes me fairly certain it's one of these 2 things:

  1. The server you are requesting images from is sending over SSLv3, which is susceptible to the POODLE attack, so they are untrusted by wkhtmltopdf.

  2. There may be a certificate issue with the HTTPS. If you need to supply your own cert there are flags you can pass wkhtmltopdf to supply your own.

If you must request your content over http, I would suggest a small change to your fix:

image_url.gsub(/\Ahttps/, 'http')

That regex anchors the replacement to the beginning of the string, so if there's somehow an https somewhere in the middle of your image_url, it won't replace them all, just the one on the beginning.