Solutions: ImagickExceptions in nextcloud.log

You are in trouble with previews and/or with thumbnails within your Nextcloud?

You found errors like “ImagickException: not authorized…” in your Nextcloud logfile (/var/nc_data/nextcloud.log)?

Just follow these instructions in your terminal session (e.g. ssh) and solve these “Imagick” issues yourself:


Error messages e.g.:

tail -f /var/nc_data/nextcloud.log | grep -i imagickexception
...
...ImagickException: not authorized `/upload_tmp/oc_tmp_zCg8T6-.d1539116135' @ error/constitute.c/ReadImage/412
...ImagickException: not authorized `/upload_tmp/oc_tmp_BiLdF7-.pdf' @ error/constitute.c/ReadImage/412
...

Solution 1:

sudo -s (or su -)
apt install ghostscript -y
ln -s /usr/local/bin/gs /usr/bin/gs
cp /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml.bak
sed -i "s/rights\=\"none\" pattern\=\"PS\"/rights\=\"read\|write\" pattern\=\"PS\"/" /etc/ImageMagick-6/policy.xml
sed -i "s/rights\=\"none\" pattern\=\"EPI\"/rights\=\"read\|write\" pattern\=\"EPI\"/" /etc/ImageMagick-6/policy.xml
sed -i "s/rights\=\"none\" pattern\=\"PDF\"/rights\=\"read\|write\" pattern\=\"PDF\"/" /etc/ImageMagick-6/policy.xml
sed -i "s/rights\=\"none\" pattern\=\"XPS\"/rights\=\"read\|write\" pattern\=\"XPS\"/" /etc/ImageMagick-6/policy.xml
service php7.2-fpm restart && service nginx restart

Solution 2 (necessary on DEBIAN 9.5 only so far?!):

su -
apt install ghostscript -y
ln -s /usr/local/bin/gs /usr/bin/gs
cp /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml.bak && vi /etc/ImageMagick-6/policy.xml

add the following four rows to the end of the file before the </policymap>:

[...]
<policy domain="coder" rights="read|write" pattern="PS" />
<policy domain="coder" rights="read|write" pattern="EPI" />
<policy domain="coder" rights="read|write" pattern="PDF" />
<policy domain="coder" rights="read|write" pattern="XPS" />
</policymap>

Then restart all services:

service php7.2-fpm restart && service nginx restart

Enjoy your personal data in your secured and hardened Nextcloud.

Don’t forget to backup your Nextcloud

Find more instructions here: Nextcloud Backup and Restore



Carsten Rieger

Carsten Rieger

Carsten Rieger is a senior system engineer in full-time and also working as an IT freelancer. He is working with linux environments for more than 13 years, an Open Source enthusiast and highly motivated on linux installation and troubleshooting. Mostly working with Debian/Ubuntu Linux, Nginx and Apache web server, MariaDB/MySQL/PostgreSQL, PHP, Cloud infrastructure (e.g. Nextcloud) and other open source projects (e.g. Roundcube) and in voluntary work for the Dr. Michael & Angela Jacobi Stiftung for more than 6 years.

3 Responses

  1. Matthias says:

    Thanks for the solution. Is this a bug that should be reported to Nextcloud?

Leave a Reply

Your email address will not be published. Required fields are marked *