Command Injection Affecting pdfkit package, versions >=0.0.0

  • Exploit Maturity

    Proof of concept

  • Attack Complexity


Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • snyk-id


  • published

    8 Sep 2022

  • disclosed

    14 Jun 2022

  • credit

    Benoit Côté-Jodoin

How to fix?

There is no fixed version for pdfkit.


Affected versions of this package are vulnerable to Command Injection where the URL is not properly sanitized.


An application could be vulnerable if they try to render a URL that contains query string parameters with user input:"{params[:name]}").to_pdf

If the provided parameter happen to contain a URL encoded character and a shell command substitution string, it will be included in the command that PDFKit executes to render the PDF:

irb(main):060:0> puts"{'%20`sleep 5`'}").command
wkhtmltopdf --quiet [...] "`sleep 5`" -
=> nil

Calling to_pdf on the instance showcases that the sleep command is indeed executing:"{'%20`sleep 5`'}").to_pdf
# 5 seconds wait...

Of course, if the user can control completely the first argument of the PDFKit constructor, they can also exploit the command injection as long as it starts with "http":"http%20`sleep 5`").to_pdf