policy.xml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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/.
  20. Open ImageMagick security policy:
  21. The default policy for ImageMagick installations is the open security
  22. policy. This policy is designed for usage in secure settings like those
  23. protected by firewalls or within Docker containers. Within this framework,
  24. ImageMagick enjoys broad access to resources and functionalities. This policy
  25. provides convenient and adaptable options for image manipulation. However,
  26. it's important to note that it might present security vulnerabilities in
  27. less regulated conditions. Thus, organizations should thoroughly assess
  28. the appropriateness of the open policy according to their particular use
  29. case and security prerequisites.
  30. ImageMagick security policies in a nutshell:
  31. Domains include system, delegate, coder, filter, module, path, or resource.
  32. Rights include none, read, write, execute and all. Use | to combine them,
  33. for example: "read | write" to permit read from, or write to, a path.
  34. Use a glob expression as a pattern.
  35. Suppose we do not want users to process MPEG video images, use this policy:
  36. <policy domain="delegate" rights="none" pattern="mpeg:decode" />
  37. Here we do not want users reading images from HTTP:
  38. <policy domain="coder" rights="none" pattern="HTTP" />
  39. The /repository file system is restricted to read only. We use a glob
  40. expression to match all paths that start with /repository:
  41. <policy domain="path" rights="read" pattern="/repository/*" />
  42. Prevent users from executing any image filters:
  43. <policy domain="filter" rights="none" pattern="*" />
  44. Cache large images to disk rather than memory:
  45. <policy domain="resource" name="area" value="1GP"/>
  46. Use the default system font unless overridden by the application:
  47. <policy domain="system" name="font" value="/usr/share/fonts/favorite.ttf"/>
  48. Define arguments for the memory, map, area, width, height and disk resources
  49. with SI prefixes (.e.g 100MB). In addition, resource policies are maximums
  50. for each instance of ImageMagick (e.g. policy memory limit 1GB, -limit 2GB
  51. exceeds policy maximum so memory limit is 1GB).
  52. Rules are processed in order. Here we want to restrict ImageMagick to only
  53. read or write a small subset of proven web-safe image types:
  54. <policy domain="delegate" rights="none" pattern="*" />
  55. <policy domain="filter" rights="none" pattern="*" />
  56. <policy domain="coder" rights="none" pattern="*" />
  57. <policy domain="coder" rights="read|write" pattern="{GIF,JPEG,PNG,WEBP}" />
  58. See https://imagemagick.org/script/security-policy.php for a deeper
  59. understanding of ImageMagick security policies.
  60. -->
  61. <policymap>
  62. <policy domain="Undefined" rights="none"/>
  63. <!-- Set maximum parallel threads. -->
  64. <!-- <policy domain="resource" name="thread" value="2"/> -->
  65. <!-- Set maximum time to live in seconds or mnemonics, e.g. "2 minutes". When
  66. this limit is exceeded, an exception is thrown and processing stops. -->
  67. <!-- <policy domain="resource" name="time" value="120"/> -->
  68. <!-- Set maximum number of open pixel cache files. When this limit is
  69. exceeded, any subsequent pixels cached to disk are closed and reopened
  70. on demand. -->
  71. <!-- <policy domain="resource" name="file" value="768"/> -->
  72. <!-- Set maximum amount of memory in bytes to allocate for the pixel cache
  73. from the heap. When this limit is exceeded, the image pixels are cached
  74. to memory-mapped disk. -->
  75. <!-- <policy domain="resource" name="memory" value="256MiB"/> -->
  76. <!-- Set maximum amount of memory map in bytes to allocate for the pixel
  77. cache. When this limit is exceeded, the image pixels are cached to
  78. disk. -->
  79. <!-- <policy domain="resource" name="map" value="512MiB"/> -->
  80. <!-- Set the maximum width * height of an image that can reside in the pixel
  81. cache memory. Images that exceed the area limit are cached to disk. -->
  82. <!-- <policy domain="resource" name="area" value="16KP"/> -->
  83. <!-- Set maximum amount of disk space in bytes permitted for use by the pixel
  84. cache. When this limit is exceeded, the pixel cache is not be created
  85. and an exception is thrown. -->
  86. <!-- <policy domain="resource" name="disk" value="1GiB"/> -->
  87. <!-- Set the maximum length of an image sequence. When this limit is
  88. exceeded, an exception is thrown. -->
  89. <!-- <policy domain="resource" name="list-length" value="32"/> -->
  90. <!-- Set the maximum width of an image. When this limit is exceeded, an
  91. exception is thrown. -->
  92. <!-- <policy domain="resource" name="width" value="8KP"/> -->
  93. <!-- Set the maximum height of an image. When this limit is exceeded, an
  94. exception is thrown. -->
  95. <!-- <policy domain="resource" name="height" value="8KP"/> -->
  96. <!-- Periodically yield the CPU for at least the time specified in
  97. milliseconds. -->
  98. <!-- <policy domain="resource" name="throttle" value="2"/> -->
  99. <!-- Do not create temporary files in the default shared directories, instead
  100. specify a private area to store only ImageMagick temporary files. -->
  101. <!-- <policy domain="resource" name="temporary-path" value="/magick/tmp/"/> -->
  102. <!-- Force memory initialization by memory mapping select memory
  103. allocations. -->
  104. <!-- <policy domain="cache" name="memory-map" value="anonymous"/> -->
  105. <!-- Ensure all image data is fully flushed and synchronized to disk. -->
  106. <!-- <policy domain="cache" name="synchronize" value="true"/> -->
  107. <!-- Replace passphrase for secure distributed processing -->
  108. <!-- <policy domain="cache" name="shared-secret" value="secret-passphrase" stealth="true"/> -->
  109. <!-- Do not permit any delegates to execute. -->
  110. <!-- <policy domain="delegate" rights="none" pattern="*"/> -->
  111. <!-- Do not permit any image filters to load. -->
  112. <!-- <policy domain="filter" rights="none" pattern="*"/> -->
  113. <!-- Don't read/write from/to stdin/stdout. -->
  114. <!-- <policy domain="path" rights="none" pattern="-"/> -->
  115. <!-- don't read sensitive paths. -->
  116. <!-- <policy domain="path" rights="none" pattern="/etc/*"/> -->
  117. <!-- Indirect reads are not permitted. -->
  118. <!-- <policy domain="path" rights="none" pattern="@*"/> -->
  119. <!-- These image types are security risks on read, but write is fine -->
  120. <!-- <policy domain="module" rights="write" pattern="{MSL,MVG,PS,SVG,URL,XPS}"/> -->
  121. <!-- This policy sets the number of times to replace content of certain
  122. memory buffers and temporary files before they are freed or deleted. -->
  123. <!-- <policy domain="system" name="shred" value="1"/> -->
  124. <!-- Enable the initialization of buffers with zeros, resulting in a minor
  125. performance penalty but with improved security. -->
  126. <!-- <policy domain="system" name="memory-map" value="anonymous"/> -->
  127. <!-- Set the maximum amount of memory in bytes that are permitted for
  128. allocation requests. -->
  129. <!-- <policy domain="system" name="max-memory-request" value="256MiB"/> -->
  130. </policymap>