| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
<!DOCTYPE policymap [ |
| 3 |
<!ELEMENT policymap (policy)*> |
| 4 |
<!ATTLIST policymap xmlns CDATA #FIXED ""> |
| 5 |
<!ELEMENT policy EMPTY> |
| 6 |
<!ATTLIST policy xmlns CDATA #FIXED ""> |
| 7 |
<!ATTLIST policy domain NMTOKEN #REQUIRED> |
| 8 |
<!ATTLIST policy name NMTOKEN #IMPLIED> |
| 9 |
<!ATTLIST policy pattern CDATA #IMPLIED> |
| 10 |
<!ATTLIST policy rights NMTOKEN #IMPLIED> |
| 11 |
<!ATTLIST policy stealth NMTOKEN #IMPLIED> |
| 12 |
<!ATTLIST policy value CDATA #IMPLIED> |
| 13 |
]> |
| 14 |
<!-- |
| 15 |
Creating a security policy that fits your specific local environment |
| 16 |
before making use of ImageMagick is highly advised. You can find guidance on |
| 17 |
setting up this policy at https://imagemagick.org/script/security-policy.php, |
| 18 |
and it's important to verify your policy using the validation tool located |
| 19 |
at https://imagemagick-secevaluator.doyensec.com/. We also strongly |
| 20 |
recommend that all users validate their security assumptions by testing their configurations after making any policy changes. This helps ensure that the |
| 21 |
intended restrictions are functioning as expected in their specific |
| 22 |
deployment environment. |
| 23 |
|
| 24 |
|
| 25 |
Open ImageMagick security policy: |
| 26 |
|
| 27 |
The default policy for ImageMagick installations is the open security |
| 28 |
policy. This policy is designed for usage in secure settings like those |
| 29 |
protected by firewalls or within Docker containers. Within this framework, |
| 30 |
ImageMagick enjoys broad access to resources and functionalities. This policy |
| 31 |
provides convenient and adaptable options for image manipulation. However, |
| 32 |
it's important to note that it might present security vulnerabilities in |
| 33 |
less regulated conditions. Thus, organizations should thoroughly assess |
| 34 |
the appropriateness of the open policy according to their particular use |
| 35 |
case and security prerequisites. |
| 36 |
|
| 37 |
ImageMagick security policies in a nutshell: |
| 38 |
|
| 39 |
Domains include system, delegate, coder, filter, module, path, or resource. |
| 40 |
|
| 41 |
Rights include none, read, write, execute and all. Use | to combine them, |
| 42 |
for example: "read | write" to permit read from, or write to, a path. |
| 43 |
|
| 44 |
Use a glob expression as a pattern. |
| 45 |
|
| 46 |
Suppose we do not want users to process MPEG video images, use this policy: |
| 47 |
|
| 48 |
<policy domain="module" rights="none" pattern="video" /> |
| 49 |
|
| 50 |
Here we do not want users reading images from HTTP: |
| 51 |
|
| 52 |
<policy domain="coder" rights="none" pattern="HTTP" /> |
| 53 |
|
| 54 |
The /repository file system is restricted to read only. We use a glob |
| 55 |
expression to match all paths that start with /repository: |
| 56 |
|
| 57 |
<policy domain="path" rights="read" pattern="/repository/*" /> |
| 58 |
|
| 59 |
Prevent users from executing any image filters: |
| 60 |
|
| 61 |
<policy domain="filter" rights="none" pattern="*" /> |
| 62 |
|
| 63 |
Cache large images to disk rather than memory: |
| 64 |
|
| 65 |
<policy domain="resource" name="area" value="1GP"/> |
| 66 |
|
| 67 |
Use the default system font unless overridden by the application: |
| 68 |
|
| 69 |
<policy domain="system" name="font" value="/usr/share/fonts/favorite.ttf"/> |
| 70 |
|
| 71 |
Define arguments for the memory, map, area, width, height and disk resources |
| 72 |
with SI prefixes (.e.g 100MB). In addition, resource policies are maximums |
| 73 |
for each instance of ImageMagick (e.g. policy memory limit 1GB, -limit 2GB |
| 74 |
exceeds policy maximum so memory limit is 1GB). |
| 75 |
|
| 76 |
Rules are processed in order. Here we want to restrict ImageMagick to only |
| 77 |
read or write a small subset of proven web-safe image types: |
| 78 |
|
| 79 |
<policy domain="delegate" rights="none" pattern="*" /> |
| 80 |
<policy domain="filter" rights="none" pattern="*" /> |
| 81 |
<policy domain="coder" rights="none" pattern="*" /> |
| 82 |
<policy domain="coder" rights="read|write" pattern="{GIF,JPEG,PNG,WEBP}" /> |
| 83 |
|
| 84 |
See https://imagemagick.org/script/security-policy.php for a deeper |
| 85 |
understanding of ImageMagick security policies. |
| 86 |
--> |
| 87 |
<policymap> |
| 88 |
<policy domain="Undefined" rights="none"/> |
| 89 |
<!-- Set maximum parallel threads. --> |
| 90 |
<!-- <policy domain="resource" name="thread" value="2"/> --> |
| 91 |
<!-- Set maximum time to live in seconds or mnemonics, e.g. "2 minutes". When |
| 92 |
this limit is exceeded, an exception is thrown and processing stops. --> |
| 93 |
<!-- <policy domain="resource" name="time" value="120"/> --> |
| 94 |
<!-- Set maximum number of open pixel cache files. When this limit is |
| 95 |
exceeded, any subsequent pixels cached to disk are closed and reopened |
| 96 |
on demand. --> |
| 97 |
<!-- <policy domain="resource" name="file" value="768"/> --> |
| 98 |
<!-- Set maximum amount of memory in bytes to allocate for the pixel cache |
| 99 |
from the heap. When this limit is exceeded, the image pixels are cached |
| 100 |
to memory-mapped disk. --> |
| 101 |
<!-- <policy domain="resource" name="memory" value="256MiB"/> --> |
| 102 |
<!-- Set maximum amount of memory map in bytes to allocate for the pixel |
| 103 |
cache. When this limit is exceeded, the image pixels are cached to |
| 104 |
disk. --> |
| 105 |
<!-- <policy domain="resource" name="map" value="512MiB"/> --> |
| 106 |
<!-- Set the maximum width * height of an image that can reside in the pixel |
| 107 |
cache memory. Images that exceed the area limit are cached to disk. --> |
| 108 |
<!-- <policy domain="resource" name="area" value="16KP"/> --> |
| 109 |
<!-- Set maximum amount of disk space in bytes permitted for use by the pixel |
| 110 |
cache. When this limit is exceeded, the pixel cache is not created |
| 111 |
and an exception is thrown. --> |
| 112 |
<!-- <policy domain="resource" name="disk" value="1GiB"/> --> |
| 113 |
<!-- Set the maximum length of an image sequence. When this limit is |
| 114 |
exceeded, an exception is thrown. --> |
| 115 |
<!-- <policy domain="resource" name="list-length" value="32"/> --> |
| 116 |
<!-- Set the maximum width of an image. When this limit is exceeded, an |
| 117 |
exception is thrown. --> |
| 118 |
<!-- <policy domain="resource" name="width" value="8KP"/> --> |
| 119 |
<!-- Set the maximum height of an image. When this limit is exceeded, an |
| 120 |
exception is thrown. --> |
| 121 |
<!-- <policy domain="resource" name="height" value="8KP"/> --> |
| 122 |
<!-- Periodically yield the CPU for at least the time specified in |
| 123 |
milliseconds. --> |
| 124 |
<!-- <policy domain="resource" name="throttle" value="2"/> --> |
| 125 |
<!-- Do not create temporary files in the default shared directories, instead |
| 126 |
specify a private area to store only ImageMagick temporary files. --> |
| 127 |
<!-- <policy domain="resource" name="temporary-path" value="/magick/tmp/"/> --> |
| 128 |
<!-- Force memory initialization by memory mapping select memory |
| 129 |
allocations. --> |
| 130 |
<!-- <policy domain="cache" name="memory-map" value="anonymous"/> --> |
| 131 |
<!-- Ensure all image data is fully flushed and synchronized to disk. --> |
| 132 |
<!-- <policy domain="cache" name="synchronize" value="true"/> --> |
| 133 |
<!-- Replace passphrase for secure distributed processing --> |
| 134 |
<!-- <policy domain="cache" name="shared-secret" value="secret-passphrase" stealth="true"/> --> |
| 135 |
<!-- Do not permit any delegates to execute. --> |
| 136 |
<!-- <policy domain="delegate" rights="none" pattern="*"/> --> |
| 137 |
<!-- Do not permit any image filters to load. --> |
| 138 |
<!-- <policy domain="filter" rights="none" pattern="*"/> --> |
| 139 |
<!-- Don't read/write from/to stdin/stdout. --> |
| 140 |
<!-- <policy domain="path" rights="none" pattern="-"/> --> |
| 141 |
<!-- don't read sensitive paths. --> |
| 142 |
<!-- <policy domain="path" rights="none" pattern="/etc/*"/> --> |
| 143 |
<!-- Indirect reads are not permitted. --> |
| 144 |
<!-- <policy domain="path" rights="none" pattern="@*"/> --> |
| 145 |
<!-- These image types are security risks on read, but write is fine --> |
| 146 |
<!-- <policy domain="module" rights="write" pattern="{MSL,MVG,PS,SVG,TXT,URL,XPS}"/> --> |
| 147 |
<!-- This policy sets the number of times to replace content of certain |
| 148 |
memory buffers and temporary files before they are freed or deleted. --> |
| 149 |
<!-- <policy domain="system" name="shred" value="1"/> --> |
| 150 |
<!-- Enable the initialization of buffers with zeros, resulting in a minor |
| 151 |
performance penalty but with improved security. --> |
| 152 |
<!-- <policy domain="system" name="memory-map" value="anonymous"/> --> |
| 153 |
<!-- Set the maximum amount of memory in bytes that are permitted for |
| 154 |
allocation requests. --> |
| 155 |
<!-- <policy domain="system" name="max-memory-request" value="256MiB"/> --> |
| 156 |
<!-- If the basename of path is a symbolic link, the open fails --> |
| 157 |
<!-- <policy domain="system" name="symlink" rights="none" pattern="follow"/> --> |
| 158 |
<!-- Blocks all SVG entity‑substitution attempts by denying the svg:substitute-entities define --> |
| 159 |
<!-- <policy domain="system" name="svg" rights="none" pattern="substitute-entities"/> --> |
| 160 |
<!-- Set the maximum distributed pixel cache clients --> |
| 161 |
<!-- <policy domain="cache" name="max-dpc-clients" value="128"/> --> |
| 162 |
<!-- Set the maximum distributed pixel cache unauthenticated clients --> |
| 163 |
<!-- <policy domain="cache" name="max-dpc-unauthenticated-clients" value="16"/> --> |
| 164 |
</policymap> |