| 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/security-policy/, |
| 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 | Web-safe ImageMagick security policy: |
| 26 | |
| 27 | This security protocol designed for web-safe usage focuses on situations |
| 28 | where ImageMagick is applied in publicly accessible contexts, like websites. |
| 29 | It deactivates the capability to read from or write to any image formats |
| 30 | other than web-safe formats like GIF, JPEG, and PNG. Additionally, this |
| 31 | policy prohibits the execution of image filters and indirect reads, thereby |
| 32 | thwarting potential security breaches. By implementing these limitations, |
| 33 | the web-safe policy fortifies the safeguarding of systems accessible to |
| 34 | the public, reducing the risk of exploiting ImageMagick's capabilities |
| 35 | for potential attacks. |
| 36 | --> |
| 37 | <policymap> |
| 38 | <!-- Set maximum parallel threads. --> |
| 39 | <policy domain="resource" name="thread" value="2"/> |
| 40 | <!-- Set maximum time to live in seconds or mnemonics, e.g. "2 minutes". When |
| 41 | this limit is exceeded, an exception is thrown and processing stops. --> |
| 42 | <policy domain="resource" name="time" value="60"/> |
| 43 | <!-- Set maximum number of open pixel cache files. When this limit is |
| 44 | exceeded, any subsequent pixels cached to disk are closed and reopened |
| 45 | on demand. --> |
| 46 | <policy domain="resource" name="file" value="768"/> |
| 47 | <!-- Set maximum amount of memory in bytes to allocate for the pixel cache |
| 48 | from the heap. When this limit is exceeded, the image pixels are cached |
| 49 | to memory-mapped disk. --> |
| 50 | <policy domain="resource" name="memory" value="768MiB"/> |
| 51 | <!-- Set maximum amount of memory map in bytes to allocate for the pixel |
| 52 | cache. When this limit is exceeded, the image pixels are cached to |
| 53 | disk. --> |
| 54 | <policy domain="resource" name="map" value="2GiB"/> |
| 55 | <!-- Set the maximum width * height of an image that can reside in the pixel |
| 56 | cache memory. Images that exceed the area limit are cached to disk. --> |
| 57 | <policy domain="resource" name="area" value="8KP"/> |
| 58 | <!-- Set maximum amount of disk space in bytes permitted for use by the pixel |
| 59 | cache. When this limit is exceeded, the pixel cache is not created |
| 60 | and an exception is thrown. --> |
| 61 | <policy domain="resource" name="disk" value="2GiB"/> |
| 62 | <!-- Set the maximum length of an image sequence. When this limit is |
| 63 | exceeded, an exception is thrown. --> |
| 64 | <policy domain="resource" name="list-length" value="16"/> |
| 65 | <!-- Set the maximum width of an image. When this limit is exceeded, an |
| 66 | exception is thrown. --> |
| 67 | <policy domain="resource" name="width" value="4KP"/> |
| 68 | <!-- Set the maximum height of an image. When this limit is exceeded, an |
| 69 | exception is thrown. --> |
| 70 | <policy domain="resource" name="height" value="4KP"/> |
| 71 | <!-- Periodically yield the CPU for at least the time specified in |
| 72 | milliseconds. --> |
| 73 | <!-- <policy domain="resource" name="throttle" value="2"/> --> |
| 74 | <!-- Dynamically yield the CPU relative to the system load average. --> |
| 75 | <policy domain="resource" name="dynamic-throttle" value="true"/> |
| 76 | <!-- Do not create temporary files in the default shared directories, instead |
| 77 | specify a private area to store only ImageMagick temporary files. --> |
| 78 | <!-- <policy domain="resource" name="temporary-path" value="/magick/tmp/"/> --> |
| 79 | <!-- Force memory initialization by memory mapping select memory |
| 80 | allocations. --> |
| 81 | <policy domain="cache" name="memory-map" value="anonymous"/> |
| 82 | <!-- Ensure all image data is fully flushed and synchronized to disk. --> |
| 83 | <policy domain="cache" name="synchronize" value="true"/> |
| 84 | <!-- Replace passphrase for secure distributed processing --> |
| 85 | <!-- <policy domain="cache" name="shared-secret" value="secret-passphrase" stealth="true"/> --> |
| 86 | <!-- Do not permit any delegates to execute. --> |
| 87 | <policy domain="delegate" rights="none" pattern="*"/> |
| 88 | <!-- Do not permit any image filters to load. --> |
| 89 | <policy domain="filter" rights="none" pattern="*"/> |
| 90 | <!-- Don't read/write from/to stdin/stdout. --> |
| 91 | <policy domain="path" rights="none" pattern="-"/> |
| 92 | <policy domain="path" rights="none" pattern="[Ff][Dd]:*"/> |
| 93 | <!-- Sensitive paths are not permitted. --> |
| 94 | <policy domain="path" rights="none" pattern="/etc/*"/> |
| 95 | <!-- Relative paths are not permitted. --> |
| 96 | <policy domain="path" rights="none" pattern="*../*"/> |
| 97 | <!-- Indirect reading is not permitted. --> |
| 98 | <policy domain="path" rights="none" pattern="@*"/> |
| 99 | <!-- Deny all image modules and specifically exempt reading or writing |
| 100 | web-safe image formats. --> |
| 101 | <policy domain="module" rights="none" pattern="*" /> |
| 102 | <policy domain="module" rights="read | write" pattern="{BMP,GIF,JPEG,PNG,TIFF,WEBP}"/> |
| 103 | <policy domain="module" rights="read | write" pattern="{MPC}" stealth="true"/> |
| 104 | <policy domain="module" rights="write" pattern="{JSON,INFO,PNM,PS}"/> |
| 105 | <!-- This policy sets the number of times to replace content of certain |
| 106 | memory buffers and temporary files before they are freed or deleted. --> |
| 107 | <policy domain="system" name="shred" value="1"/> |
| 108 | <!-- Enable the initialization of buffers with zeros, resulting in a minor |
| 109 | performance penalty but with improved security. --> |
| 110 | <policy domain="system" name="memory-map" value="anonymous"/> |
| 111 | <!-- Set the maximum amount of memory in bytes that are permitted for |
| 112 | allocation requests. --> |
| 113 | <policy domain="system" name="max-memory-request" value="256MiB"/> |
| 114 | </policymap> |