Web : ImagickException: attempt to perform an operation not allowed by the security policy `PDF’

By | September 21, 2020

After updating ImageMagick to version 6.9.10.23+ from an earlier version, the following behavior occur :

  • Thumbnails generation from PDF, XPS, PS, and EPS does not work anymore
  • The following output can be found in the Web server error log :
PHP Fatal error: Uncaught ImagickException: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408 in /path/to//pdfThumb.php:7\nStack trace:\n#0 /path/to/pdfThumb.php(7): Imagick->__construct('../files/9984/C...')\n#1 {main}\n thrown in /path/to/pdfThumb.php on line 7, referer: https://hostname.domain.tld

This is due to the addition of a policy in the newer version that disable ghostscript formats.

1. Edit the ImageMagick policy file :

/etc/ImageMagick-6/policy.xml

2. Locate the following lines (usually at the very bottom of the file, around lines 89 to 95) :

<!-- disable ghostscript format types -->
  <policy domain="coder" rights="none" pattern="PS" />
  <policy domain="coder" rights="none" pattern="PS2" />
  <policy domain="coder" rights="none" pattern="PS3" />
  <policy domain="coder" rights="none" pattern="EPS" />
  <policy domain="coder" rights="none" pattern="PDF" />
  <policy domain="coder" rights="none" pattern="XPS" />

3. Comment or remove those entries and restart the Web server service.