Security Policy • Environment Selection • Example Policy • Discussion • Pixel Cache Sync • Zero Config • Best Practices
ImageMagick Security Policy
Establish a security policy tailored to your environment before deploying ImageMagick. ImageMagick operates on an "everything allowed unless denied" model, where the last matching policy wins. Place broad deny rules first, followed by specific exceptions, and review rule ordering carefully to prevent unintended authorizations.
ImageMagick is intentionally open by default, a design choice optimized for controlled, sandboxed environments like Docker containers and isolated application pipelines.
Security involves balancing protection against potential vulnerabilities with practical operational needs. ImageMagick's security policy acts as the control point between strict lockdown and convenience, letting you dictate which features, coders, and operations are permitted.
A well-designed policy empowers you to:
- Limit or disable high-risk coders and external operations to minimize attack surfaces.
- Constrain resource usage to prevent denial-of-service (DoS) attacks and resource exhaustion.
- Define strict input boundaries for what file types and formats ImageMagick may process.
- Tailor defenses to your specific threat model rather than relying on a rigid, one-size-fits-all setup.
Because ImageMagick ships in an open state for easy integration into containers and automated build pipelines, administrators must tighten policies to match production requirements. The more untrusted input your application handles, the more restrictive your policy must be.
Policies are evaluated using a "last matching policy wins" model. For filesystem paths, ImageMagick evaluates canonical (fully resolved) paths and enforces canonical denies to block bypass attempts via symlinks, alternate representations, or path traversal tricks.
Selecting the Right Security Policy for Your Environment
To ensure optimal security in public-facing applications, you can restrict ImageMagick exclusively to web-safe formats like GIF, JPEG, and PNG. Alternatively, you can customize limits for memory allocation, allowed read/write paths, sequence frame counts, workflow runtime, and pixel cache disk space.
Setting resource limits protects against malicious or malformed files—such as an internet-sourced image crafted to declare 20,000×20,000 dimensions. Without limits, such files can exhaust memory and disk space, causing system slowdowns or crashes. You can configure these limits in your policy.xml file.
Environments vary wildly: a sandboxed internal service with abundant RAM has different security needs than a public web server processing user uploads. To simplify hardening, ImageMagick provides four pre-built security policies (available as of version 7.1.1-16):
open
The default profile. Ideal for secure, firewalled environments or Docker containers where broad functionality and convenience are prioritized over strict lockdown.
limited
Strikes a balance between usability and security. Disables hazardous coders (like SVG or HTTP) and applies adjustable resource constraints on memory, storage, and runtime.
secure
A rigorous profile enforcing strict resource caps, explicit read/write pathways, sequence limits, and disabled high-risk capabilities for hardened deployments.
websafe
Designed for public websites. Restricts I/O strictly to GIF, JPEG, and PNG formats while blocking image filters and indirect reads to prevent exploitation.
Under Linux, select your policy using the configure script option --with-security-policy={open,limited,secure,websafe}. Under Windows, select it during the GUI configuration app workflow.
We encourage reviewing every rule in your policy.xml. Finding the right balance ensures robust defense without breaking legitimate image processing pipelines.
Policy Evaluator: Doyensec provides a helpful interactive security policy auditor at imagemagick-secevaluator.doyensec.com.
Example Hardened Security Policy
Below is a production-ready example of a hardened security policy tailored for public-facing web applications:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policymap [
<!ELEMENT policymap (policy)*>
<!ATTLIST policymap
xmlns CDATA #FIXED ""
>
<!ELEMENT policy EMPTY>
<!ATTLIST policy
xmlns CDATA #FIXED ""
domain NMTOKEN #REQUIRED
name NMTOKEN #IMPLIED
pattern CDATA #IMPLIED
rights NMTOKEN #IMPLIED
stealth NMTOKEN #IMPLIED
value CDATA #IMPLIED
>
]>
<!--
ImageMagick Web-Safe Security Policy
This policy is intended for public-facing services that process untrusted
images. It reduces ImageMagick's attack surface while preserving support
for common raster image operations.
Security objectives:
* Limit CPU, memory, disk, and file resource consumption.
* Mitigate denial-of-service attacks through resource and runtime limits.
* Prevent access to sensitive local files and Linux virtual filesystems.
* Prevent indirect file reads via @filename expansion.
* Prevent use of stdin/stdout and file descriptor paths.
* Disable all delegates and loadable filters.
* Disable selected embedded scripting modules that provide scripting, vector
graphics processing, or URL access.
This policy does not restrict ImageMagick to a specific image format
allowlist. Additional coder or module restrictions may be added for
deployments requiring a stricter security posture.
References:
https://imagemagick.org/security-policy/
https://imagemagick-secevaluator.doyensec.com/
-->
<policymap>
<!-- ============================================================= -->
<!-- Resource Limits -->
<!-- ============================================================= -->
<!-- Limit ImageMagick to at most four worker threads. -->
<policy domain="resource" name="thread" value="4"/>
<!-- Abort operations that exceed 30 seconds of processing time. -->
<policy domain="resource" name="time" value="30"/>
<!-- Maximum number of simultaneously open pixel-cache files. -->
<policy domain="resource" name="file" value="768"/>
<!-- Maximum heap memory available to the pixel cache. -->
<policy domain="resource" name="memory" value="512MiB"/>
<!-- Maximum amount of memory-mapped pixel cache storage. -->
<policy domain="resource" name="map" value="1024MiB"/>
<!-- Images larger than 32 megapixels spill to disk-backed cache. -->
<policy domain="resource" name="area" value="32MP"/>
<!-- Limit total disk usage for pixel cache and temporary files. -->
<policy domain="resource" name="disk" value="2GiB"/>
<!-- Limit the number of images permitted in a sequence. -->
<policy domain="resource" name="list-length" value="16"/>
<!-- Reject images wider than approximately 8192 pixels. -->
<policy domain="resource" name="width" value="8KP"/>
<!-- Reject images taller than approximately 8192 pixels. -->
<policy domain="resource" name="height" value="8KP"/>
<!-- Prevent excessively large single memory allocation requests. -->
<policy domain="system" name="max-memory-request" value="512MiB"/>
<!-- Maximum size of a single image profile. -->
<policy domain="system" name="max-profile-size" value="16MiB"/>
<policy domain="system" name="max-profile-count" value="16"/>
<!-- ============================================================= -->
<!-- Path Restrictions -->
<!-- ============================================================= -->
<!-- Disallow reading from or writing to stdin/stdout via "-". -->
<policy domain="path" rights="none" pattern="-"/>
<!-- Disable indirect file reads such as @filename. -->
<policy domain="path" rights="none" pattern="@*"/>
<!-- Prevent access to file descriptors (fd:). -->
<policy domain="path" rights="none" pattern="[Ff][Dd\\]:*"/>
<!-- Prevent access to operating system configuration files. -->
<policy domain="path" rights="none" pattern="/etc/*"/>
<!-- Prevent access to Linux process and runtime information. -->
<policy domain="path" rights="none" pattern="/proc/*"/>
<!-- Prevent access to Linux kernel and device information. -->
<policy domain="path" rights="none" pattern="/sys/*"/>
<!-- Disable pipe-based I/O. -->
<policy domain="path" rights="none" pattern="|*"/>
<!-- ============================================================= -->
<!-- Feature Restrictions -->
<!-- ============================================================= -->
<!-- Disable all external delegates (Ghostscript, ffmpeg, etc.). -->
<policy domain="delegate" rights="none" pattern="*"/>
<!-- Disable all loadable image filters. -->
<policy domain="filter" rights="none" pattern="*"/>
<!--
Restrict embedded scripting coders.
Certain modules are denied, whereas, read access is denied while write
access remains permitted for others. This allows ImageMagick to generate
these formats without accepting potentially untrusted input through them.
-->
<policy domain="module" rights="none" pattern="{MSL,URL,VIDEO}"/>
<policy domain="coder" rights="write" pattern="{MVG,PDF,PS,SVG,TXT,XPS}"/>
<!-- Treat filenames with percent signs (%) as plain text rather than
formatting placeholders. -->
<policy domain="system" name="filename:literal" value="true"/>
</policymap>
Security Policy Discussion & Advanced Tuning
Starting with ImageMagick 7.0.1-8, external delegates can be globally disabled by setting the pattern to "*". Glob patterns are case-sensitive prior to version 7.1.1-16, so coders must be uppercase (e.g., "EPS") or use case-insensitive patterns like [Pp][Nn][Gg].
When restricting coders like HTTPS, attempting an unauthorized operation returns an error:
magick: attempt to perform an operation not allowed by the security policy `HTTPS'
magick: no images defined `wizard.jpg'
You can also use anonymous memory mapping and buffer shredding to enhance data hygiene:
<policy domain="cache" name="memory-map" value="anonymous"/>
<policy domain="system" name="shred" value="1"/>
To verify your active security policy configuration at any time, run:
Pixel Cache Synchronize Policy
When writing pixels to disk, ImageMagick preallocates and memory-maps files for performance. However, if disk space runs out during population, the OS may trigger a SIGBUS signal. Setting synchronize to true ensures data is flushed and synchronized immediately, preventing crashes and offering early error reporting:
Zero Configuration Security Policy
For embedded builds that prohibit external configuration files, you can embed policies directly into the source module MagickCore/policy-private.h before compilation:
"<policymap> <policy domain=\"module\" rights=\"none\" pattern=\"MVG\"/> </policymap>";
Other Security Best Practices
- Use web-safe image formats: Restrict processing strictly to trusted formats like GIF, JPEG, and PNG.
- Customize resource limits: Control memory, disk space, and runtime bounds to thwart denial-of-service attacks.
- Deploy sandboxing: Run ImageMagick inside isolated containers or restricted user namespaces.
- Disable dangerous coders: Turn off vector graphics (MVG) and remote network fetches (HTTPS) on public instances.
- Review delegates: Audit
delegates.xmland use absolute pathnames (e.g.,/usr/bin/gs) to prevent path hijacking. - Keep ImageMagick updated: Always run the latest stable release to incorporate critical security patches.