Skip to content

pdfkit fails with Content-Security-Policy enabled #1104

@martynasma

Description

@martynasma

Bug Report

Hey from amCharts. We're using pdfkit (indirectly via pdfmake) to export charts to PDF in our flagship dataviz lib, and running into a bit of an issue with security-conscious users.

Description of the problem

pdfkit fails with a critical security error if the page has Content-Security-Policy enabled. E.g.:

Header add Content-Security-Policy "script-src 'self'"

The above header prevents in-line script creation, which is a reasonable security measure, preventing any unauthorized JS code to be activated on the we page.

It originates in Pointer function which for some reason is using eval'ed code to generate function references:

image

The function comes from an old version of restructure used by one of pdfkit's dependencies - fontkit.

The issue has already been addressed in restructure, so it's just a matter of upgrading the whole chain of dependencies. Taking into account that all three libs are maintained by foliojs, it shouldn't be that hard? ;)

Live examples

With CSP enabled (failing, see browser console):
http://test.amcharts.com/demo/pdfkit/with-CSP/

Without CSP (working fine)
http://test.amcharts.com/demo/pdfkit/without-CSP/

Your environment

  • pdfkit version: 0.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions