• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2
3
4
5<!DOCTYPE html>
6<html lang="en">
7<head>
8  <meta charset="utf-8"  />
9  <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1,shrink-to-fit=no"  />
10  <title>ImageMagick - Security Policy</title>
11  <meta name="application-name" content="ImageMagick" />
12  <meta name="description" content="Use ImageMagick® to create, edit, compose, and convert bitmap images. Resize an image, crop it, change its shades and colors, add captions, and more." />
13  <meta name="application-url" content="https://imagemagick.org" />
14  <meta name="generator" content="PHP" />
15  <meta name="keywords" content="security, policy, ImageMagick, PerlMagick, image processing, image, photo, software, Magick++, OpenMP, convert" />
16  <meta name="rating" content="GENERAL" />
17  <meta name="robots" content="INDEX, FOLLOW" />
18  <meta name="generator" content="ImageMagick Studio LLC" />
19  <meta name="author" content="ImageMagick Studio LLC" />
20  <meta name="revisit-after" content="2 DAYS" />
21  <meta name="resource-type" content="document" />
22  <meta name="copyright" content="Copyright (c) 1999-2020 ImageMagick Studio LLC" />
23  <meta name="distribution" content="Global" />
24  <meta name="magick-serial" content="P131-S030410-R485315270133-P82224-A6668-G1245-1" />
25  <meta property='og:url' content='../' />
26  <meta property='og:title' content='ImageMagick' />
27  <meta property='og:image' content='../images/logo.png' />
28  <meta property='og:type' content='website' />
29  <meta property='og:site_name' content='ImageMagick' />
30  <meta property='og:description' content="Convert, Edit, or Compose Bitmap Images" />
31  <meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4" />
32  <link href="../www/security-policy.html" rel="canonical" />
33  <link href="../images/wand.png" rel="icon" />
34  <link href="../images/wand.ico" rel="shortcut icon" />
35  <link href="assets/magick.css" rel="stylesheet" />
36</head>
37<body>
38  <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
39    <a class="navbar-brand" href="../index.html"><img class="d-block" id="icon" alt="ImageMagick" width="32" height="32" src="../images/wand.ico"/></a>
40    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsMagick" aria-controls="navbarsMagick" aria-expanded="false" aria-label="Toggle navigation">
41      <span class="navbar-toggler-icon"></span>
42    </button>
43
44    <div class="navbar-collapse collapse" id="navbarsMagick" style="">
45    <ul class="navbar-nav mr-auto">
46      <li class="nav-item ">
47        <a class="nav-link" href="../index.html">Home <span class="sr-only">(current)</span></a>
48      </li>
49      <li class="nav-item ">
50        <a class="nav-link" href="download.html">Download</a>
51      </li>
52      <li class="nav-item ">
53        <a class="nav-link" href="command-line-tools.html">Tools</a>
54      </li>
55      <li class="nav-item ">
56        <a class="nav-link" href="command-line-processing.html">Command-line</a>
57      </li>
58      <li class="nav-item ">
59        <a class="nav-link" href="resources.html">Resources</a>
60      </li>
61      <li class="nav-item ">
62        <a class="nav-link" href="develop.html">Develop</a>
63      </li>
64      <li class="nav-item">
65        <a class="nav-link" target="_blank" href="https://imagemagick.org/discourse-server/">Community</a>
66      </li>
67    </ul>
68    <form class="form-inline my-2 my-lg-0" action="https://imagemagick.org/script/search.php">
69      <input class="form-control mr-sm-2" type="text" name="q" placeholder="Search" aria-label="Search">
70      <button class="btn btn-outline-success my-2 my-sm-0" type="submit" name="sa">Search</button>
71    </form>
72    </div>
73  </nav>
74  <div class="container">
75   <script async="async" src="http://localhost/pagead/js/adsbygoogle.js"></script>    <ins class="adsbygoogle"
76         style="display:block"
77         data-ad-client="ca-pub-3129977114552745"
78         data-ad-slot="6345125851"
79         data-full-width-responsive="true"
80         data-ad-format="horizontal"></ins>
81    <script>
82      (adsbygoogle = window.adsbygoogle || []).push({});
83    </script>
84
85  </div>
86
87  <main class="container">
88    <div class="magick-template">
89<div class="magick-header">
90<p class="text-center"><a href="security-policy.html#policy">Security Policy </a> • <a href="security-policy.html#synchronize">Pixel Cache Synchronize Policy</a> • <a href="security-policy.html#zero-configuration">Zero Configuration Security Policy</a> • <a href="security-policy.html#other">Other Security Considerations</a></p>
91
92
93<p class="lead magick-description">ImageMagick best practices strongly encourages you to configure a security <a href="https://imagemagick.org/source/policy.xml">policy.xml</a> that suits your local environment.  The policy is open by default.  This affords maximum utility for ImageMagick installations that run in a sandboxed environment, perhaps in a Docker instance, or behind a firewall where security risks are greatly diminished as opposed to a public website.</p>
94
95<p>Security is a trade-off between a secure environment and convenience. If you want ImageMagick to be optimally secure, you could, for example, limit ImageMagick to only read or write web safe images (e.g. GIF, JPEG, PNG).   However, ImageMagick provides for a more secure option by adjusting the security policy per the requirements of your local environment or organizational policies. The security policy covers areas such as memory, which paths to read or write, how many images are permitted in an image sequence, how long a workflow can run, how much disk the image pixels can consume, a secret passphrase for remote connections, which coders are permitted or denied, and others. These policies should provide robust coverage to not only secure your environment per your requirements but also ensure ImageMagick remains a good citizen (e.g. prevent thrashing with large images) in your local environment.</p>
96
97<p>As an example, suppose you download an image from the internet and unbeknownst to you its been crafted to generate a 20000 by 20000 pixel image. ImageMagick attempts to allocate enough resources (memory, disk) and your system will likely deny the resource request and exit. However, its also possible that your computer might be temporarily sluggish or unavailable or ImageMagick may abort. To prevent such a scenario, you can set limits in the <code>policy.xml</code> configuration file. You might wonder why ImageMagick does not already include reasonable limits? Simply because what is reasonable in your environment, might not be reasonable to someone else. For example, you may have ImageMagick sandboxed where security is not a concern, whereas another user may use ImageMagick to process images on their publically accessible website.  Or ImageMagick runs on a host with 1TB of memory whereas another ImageMagick instance runs on an iPhone. By policy, permitting giga-pixel image processing on the large memory host makes sense, not so much for the resource constrained iPhone. If you utilize ImageMagick from a public website, you may want to increase security by preventing usage of the MVG or HTTPS coders. Only you can decide what are reasonable limits taking in consideration your environment. We provide this policy with reasonable limits and encourage you to modify it to suit your local environment:</p>
98
99<pre class="pre-scrollable"><code>&lt;policymap>
100  &lt;!-- temporary path must be a preexisting writable directory -->
101  &lt;policy domain="resource" name="temporary-path" value="/tmp"/>
102  &lt;policy domain="resource" name="memory" value="256MiB"/>
103  &lt;policy domain="resource" name="map" value="512MiB"/>
104  &lt;policy domain="resource" name="width" value="8KP"/>
105  &lt;policy domain="resource" name="height" value="8KP"/>
106  &lt;policy domain="resource" name="area" value="16KP"/>
107  &lt;policy domain="resource" name="disk" value="1GiB"/>
108  &lt;policy domain="resource" name="file" value="768"/>
109  &lt;policy domain="resource" name="thread" value="2"/>
110  &lt;policy domain="resource" name="throttle" value="0"/>
111  &lt;policy domain="resource" name="time" value="120"/>
112  &lt;policy domain="resource" name="list-length" value="128"/>
113  &lt;policy domain="system" name="precision" value="6"/>
114  &lt;policy domain="cache" name="shared-secret" stealth="true" value="replace with your secret phrase"/>
115  &lt;policy domain="coder" rights="none" pattern="MVG" />
116  &lt;policy domain="coder" rights="none" pattern="EPS" />
117  &lt;policy domain="coder" rights="none" pattern="PS" />
118  &lt;policy domain="coder" rights="none" pattern="PS2" />
119  &lt;policy domain="coder" rights="none" pattern="PS3" />
120  &lt;policy domain="coder" rights="none" pattern="PDF" />
121  &lt;policy domain="coder" rights="none" pattern="XPS" />
122  &lt;policy domain="filter" rights="none" pattern="*" />
123  &lt;policy domain="delegate" rights="none" pattern="HTTPS" />  <!--  prevent 'curl' program from reading HTTPS URL's -->
124  &lt;policy domain="delegate" rights="none" pattern="SHOW" />
125  &lt;policy domain="delegate" rights="none" pattern="WIN" />
126  &lt;policy domain="path" rights="none" pattern="@*"/>  <!-- indirect reads not permitted -->
127&lt;/policymap></code></pre>
128
129<p>Since we process multiple simultaneous sessions, we do not want any one session consuming all the available memory. With this policy, large images are cached to disk. If the image is too large and exceeds the pixel cache disk limit, the program exits. In addition, we place a time limit to prevent any run-away processing tasks. If any one image has a width or height that exceeds 8192 pixels or if an image sequence exceeds 128 frames, an exception is thrown and processing stops. As of ImageMagick 7.0.1-8 and 6.9.4-6, you can prevent the use of any delegate or all delegates (set the pattern to "*"). Note, prior to these releases, use a domain of <code>coder</code> to prevent delegate usage (e.g. <code>domain="coder" rights="none" pattern="HTTPS"</code>). We prevent users from executing any image filters.  The policy also prevents indirect reads. If you want to, for example, read text from a file (e.g. <code>caption:@myCaption.txt</code>), you'll need to disable the <code>path</code> policy.</p>
130
131<p>Policy patterns are <em>case sensitive</em>.  To get expected behavior, coders and modules must be upper-case (e.g. "EPS" not "eps").</p>
132
133<p>Here is what you can expect when you restrict the HTTPS coder, for example:</p>
134
135<pre class="highlight">-> convert ../images/wizard.png wizard.jpg
136convert: attempt to perform an operation not allowed by the security policy `HTTPS'
137convert: unable to open file: No such file or directory
138convert: no images defined `wizard.jpg'</pre>
139
140<p>As of ImageMagick version 7.0.4-7, you can conveniently deny access to all delegates and coders except for a small subset of proven web-safe image types.  For example,</p>
141
142<pre class="highlight"><code>&lt;policy domain="delegate" rights="none" pattern="*" />
143&lt;policy domain="module" rights="none" pattern="*" />
144&lt;policy domain="module" rights="read | write" pattern="{GIF,JPEG,PNG,WEBP}" /></code></pre>
145
146<p>Here we disable just a few Postscript related formats:</p>
147<pre class="highlight"><code>&lt;policy domain="module" rights="none" pattern="{PDF,PS,PS2,PS3,XPS}" /></code></pre>
148
149<p>As of ImageMagick 7.0.7-0, you can allocate the pixel cache and some internal buffers with anonymous memory mapping rather than from heap.  As a consequence, the pixels are initialized to zero.  You can also securely delete any temporary files for increased security.  The value is the number of times to shred (replace its content with random data) before deleting a temporary file.  For example,</p>
150<pre class="highlight"><code>&lt;policy domain="system" name="memory-map" value="anonymous"/>
151&lt;policy domain="cache" name="memory-map" value="anonymous"/>
152&lt;policy domain="system" name="shred" value="1"/></code></pre>
153
154<p>Some image processing algorithms (e.g. wavelet transform) might consume a substantial amount of memory to complete.  ImageMagick maintains a separate memory pool for these large resource requests and as of 7.0.6-1 permits you to set a maximum request limit.  If the limit is exceeded, the allocation is instead memory-mapped on disk.  Here we limit the maximum memory request by policy:</p>
155<pre class="highlight"><code>&lt;policy domain="system" name="max-memory-request" value="256MiB"/> </code></pre>
156
157<p>As of ImageMagick version 7.0.4-23, you can limit the maximum number of images in a sequence.  For example, to limit an image sequence to 64 frames, use:</p>
158<pre class="highlight"><code>&lt;policy domain="resource" name="list-length" value="64"/></code></pre>
159
160<p>You can verify your policy changes are in effect with this command:</p>
161
162<pre class="pre-scrollable">-> identify -list policy
163Path: ImageMagick/policy.xml
164  Policy: Resource
165    name: time
166    value: 120
167  Policy: Resource
168    name: throttle
169    value: 0
170  Policy: Resource
171    name: thread
172    value: 2
173  Policy: Resource
174    name: file
175    value: 768
176  Policy: Resource
177    name: disk
178    value: 1GiB
179  Policy: Resource
180    name: map
181    value: 512MiB
182  Policy: Resource
183    name: memory
184    value: 256MiB
185  Policy: Resource
186    name: area
187    value: 16KP
188  Policy: Resource
189    name: height
190    value: 8KP
191  Policy: Resource
192    name: width
193    value: 8KP
194  Policy: Resource
195    name: temporary-path
196    value: /tmp
197  Policy: System
198    name: precision
199    value: 6
200  Policy: Path
201    rights: None
202    pattern: @*
203
204Path: [built-in]
205  Policy: Undefined
206    rights: None</pre>
207<p>Notice the <code>Cache</code> policy is not listed due to the <code>stealth</code> property.</p>
208
209<p>As of ImageMagick 7.0.6-0, you can programmatically set the ImageMagick security policy with SetMagickSecurityPolicy() (MagickCore) or MagickSetSecurityPolicy() (MagickWand).</p>
210
211<p>As of ImageMagick version 7.0.8-11, you can set a module security policy.  For example, to prevent Postscript or PDF interpretation, use:</p>
212<pre class="highlight"><code>&lt;policy domain="module" rights="none" pattern="{ps,pdf,xps}/></code></pre>
213
214<p>For additional details about resource limits and the policy configuration file, read <a href="resources.html">Resources</a> and <a href="architecture.html">Architecture</a>.</p>
215
216<h2><a class="anchor" id="synchronize"></a>Pixel Cache Synchronize Policy</h2>
217
218<p>When writing image pixels to disk, ImageMagick firsts preallocates the disk file, which is much faster than fully populating the file with zeros.  To further increase performance, we memory-map the file on disk.  With memory-mapping, we get an increase in performance (up to 5x), however, there remains a possibility that as the disk file is populated, it may run out of free space.  The OS then throws a SIGBUS signal which prevents ImageMagick from continuing.  To prevent a SIGBUS, use this security policy:
219
220<pre class="highlight">
221&lt;policy domain="cache" name="synchronize" value="True"/>
222</pre>
223
224<p>Set to True to ensure all image data is fully flushed and synchronized to disk. There is a performance penalty, however, the benefits include ensuring a valid image file in the event of a system crash and early reporting if there is not enough disk space for the image pixel cache.</p>
225
226<h2><a class="anchor" id="zero-configuration"></a>Zero Configuration Security Policy</h2>
227
228<p>A zero configuration build of ImageMagick does not permit external configuration files.  To define your security policy, you must instead edit the <code>MagickCore/policy-private.h</code> source module, add your policy statements, and then build the ImageMagick distribution.  Here is an example zero configuration security policy:</p>
229
230<pre class="highlight"><code>static const char
231  *ZeroConfigurationPolicy = \
232"&lt;policymap> \
233  &lt;policy domain=\"coder\" rights=\"none\" pattern=\"MVG\"/> \
234&lt;/policymap>";</code></pre>
235
236<h2><a class="anchor" id="other"></a>Other Security Considerations</h2>
237
238<p>If you spot a security flaw in ImageMagick, post your concern as an issue to
239<a href="https://github.com/ImageMagick/ImageMagick/issues">GitHub</a>.  Be sure to include how to reproduce the security flaw and a link to any images needed to reproduce the flaw.  Alternatively, <a href="https://imagemagick.org/script/contact.php">contact us</a> and select Security Issue as the issue.</p>
240
241<p>In addition to the security policy, you can make ImageMagick safer by ...</p>
242<ul>
243<li>keeping ImageMagick up-to-date.  The latest releases have fixes for any security flaws we discovered in the past;</li>
244<li>sanitizing any filenames or command line options you pass to ImageMagick;</li>
245<li>running ImageMagick in a sanitized software container such as Docker;</li>
246<li>running ImageMagick as the least-privileged user (e.g. 'nobody');</li>
247<li>explicitly setting the image file type.  For example, use the filename <code>png:image.png</code> rather than <code>image.png</code>.  Without an explicit image type in the filename, ImageMagick guesses the image type.</li>
248</ul>
249
250</div>
251    </div>
252  </main><!-- /.container -->
253  <footer class="magick-footer">
254    <p><a href="security-policy.html">Security</a> •
255    <a href="architecture.html">Architecture</a>
256
257    <a href="security-policy.html#"><img class="d-inline" id="wand" alt="And Now a Touch of Magick" width="16" height="16" src="../images/wand.ico"/></a>
258
259    <a href="links.html">Related</a> •
260     <a href="sitemap.html">Sitemap</a>
261    <br/>
262    <a href="support.html">Donate</a> •
263    <a href="http://pgp.mit.edu/pks/lookup?op=get&amp;search=0x89AB63D48277377A">Public Key</a> •
264    <a href="https://imagemagick.org/script/contact.php">Contact Us</a>
265    <br/>
266    <small>© 1999-2020 ImageMagick Studio LLC</small></p>
267  </footer>
268
269  <!-- Javascript assets -->
270  <script src="assets/magick.js" crossorigin="anonymous"></script>
271  <script>window.jQuery || document.write('<script src="https://localhost/ajax/libs/jquery/3.4.1/jquery.min.js"><\/script>')</script>
272</body>
273</html>
274<!-- Magick Cache 5th January 2020 11:35 -->