Security Advisories (2)
CVE-2026-16770 (2026-08-12)

PDF::WebKit versions through 1.2 for Perl allow argument injection into wkhtmltopdf via meta tags in the source document. For an HTML string or file source, the constructor collects every <meta name="pdf-webkit-KEY" content="VALUE"> element in the document head through _pdf_webkit_meta_tags and turns each one into a wkhtmltopdf command line option. KEY is normalized to an option name matching --[a-z0-9-]+ but is not checked against an allow list, VALUE is passed through unchanged as the argument that follows it, and a VALUE of "yes" emits the option as a bare flag. BUILD merges the meta derived options last, so they also override the module defaults and the options passed to new. Switches such as --enable-local-file-access and --cookie-jar are reachable this way. The renderer is executed with an argument list rather than a shell command, so this is argument injection and not shell injection. Any caller that renders untrusted HTML lets the document choose the renderer's options and override those set by the application, including options that read local files into the resulting PDF or write to a chosen path. A URL source is not scanned, and the scan is skipped when XML::LibXML, a recommended dependency, is not installed.

CVE-2026-17431 (2026-08-12)

PDF::WebKit versions through 1.2 for Perl allow OS command injection via a 2-arg open() of the output path in to_pdf and of stylesheet paths in _style_tag_for. to_pdf reads the generated PDF back from its path argument, and _style_tag_for reads each entry of the stylesheets list, by assigning the path to a local @ARGV and reading it with the diamond operator, which opens each @ARGV element with Perl's 2-arg open(). A value that begins or ends with a pipe ("| cmd", "cmd |") is run as a command rather than opened as a file, and one that begins with a redirect ("> path", ">> path") opens that path for write or append. to_file forwards its path argument to to_pdf and reaches the same read. Any caller that forwards untrusted input as the output path or as a stylesheets entry can run a command under the process UID; with the "cmd |" form the command's output is returned in place of the PDF, and with the "> path" form the named file is truncated. Stylesheets may only be added to an HTML source, so a URL or file source exposes the output path alone.

NAME

PDF::WebKit - Use WebKit to Generate PDFs from HTML (via wkhtmltopdf)

SYNOPSIS

use PDF::WebKit;

# PDF::WebKit->new takes the HTML and any options for wkhtmltopdf
# run `wkhtmltopdf --extended-help` for a full list of options
my $kit = PDF::WebKit->new(\$html, page_size => 'Letter');
push @{ $kit->stylesheets }, "/path/to/css/file";

# Get an inline PDF
my $pdf = $kit->to_pdf;

# save the PDF to a file
my $file = $kit->to_file('/path/to/save/pdf');

# PDF::WebKit can optionally accept a URL or a File
# Stylesheets cannot be added when source is provided as a URL or File.
my $kit = PDF::WebKit->new('http://google.com');
my $kit = PDF::WebKit->new('/path/to/html');

# Add any kind of option through meta tags
my $kit = PDF::WebKit->new(\'<html><head><meta name="pdfkit-page_size" content="Letter"...');

DESCRIPTION

PDF::WebKit uses wkhtmltopdf to convert HTML documents into PDFs. It is a port of the elegant PDFKit Ruby library.

wkhtmltopdf generates beautiful PDFs by leveraging the rendering power of Qt's WebKit browser engine (used by both Apple Safari and Google Chrome browsers).

Configuration

Configuration of PDF::WebKit is configured globally by calling the PDF::WebKit->configure class method:

PDF::WebKit->configure(sub {
  # default `which wkhtmltopdf`
  $_->wkhtmltopdf('/path/to/wkhtmltopdf');

  # default 'pdf-webkit-'
  $_->meta_tag_prefix('my-prefix-');

  $_->default_options->{'--orientation'} = 'Portrait';
});

See the new method for the standard default options.

Constructor

new($SOURCE_URL,%OPTIONS)
new($SOURCE_FILENAME,%OPTIONS)
new(\$SOURCE_HTML,%OPTIONS)

Creates and returns a new instance. If the first parameter looks like a URL, it is treated as a URL and handed off to wkhtmltopdf verbatim. If it is is a reference to a scalar, it is an HTML document body. Otherwise, the parameter is interpreted as a filename.

The %OPTIONS hash is a list of name/value pairs for command-line options to wkhtmltopdf. These options can augment or override the default options. For options with no associated value, pass "YES" (case insensitive) as the value, e.g. grayscale => "YES".

The default options are:

--page-size     Letter
--margin-top    0.75in
--margin_right  0.75in
--margin_bottom 0.75in
--margin_left   0.75in
--encoding      UTF-8

Methods

command

Returns the list of command-line arguments that would be used to execute wkhtmltopdf.

to_pdf

Processes the source material and returns a PDF as a string.

to_file($PATH)

Processes the source material and creates a PDF at $PATH. Returns a filehandle opened on $PATH.

SEE ALSO

PDFKit, wkhtmltopdf, WKHTMLTOPDF (a lower-level wrapper for wkhtmltopdf).

AUTHOR

Philip Garrett <philip.garrett@icainformatics.com>

CONTRIBUTORS

Christian Walde <walde.christian@gmail.com>

CONTRIBUTING

If you'd like to contribute, just fork my repository on Github, commit your changes and send me a pull request.

http://github.com/kingpong/perl-PDF-WebKit

ACKNOWLEDGMENTS

This code is nearly a line-by-line port of Jared Pace's PDFKit. https://github.com/jdpace/PDFKit

COPYRIGHT & LICENSE

Copyright (c) 2011 by Informatics Corporation of America.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.