<?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 Security Policy

  This policy is intended for general-purpose deployments that process
  potentially untrusted images while maintaining support for common image
  formats and workflows.

  The policy balances usability and security by:

    * Limiting resource consumption (CPU time, memory, disk usage, image
      dimensions, and sequence length).
    * Blocking potentially dangerous path access methods such as indirect
      reads (@files) and pipes.
    * Preventing access to sensitive filesystem locations.
    * Restricting high-risk coders that have historically been involved in
      external content processing, scripting, or complex parsers.
    * Limiting large allocation requests that could otherwise lead to
      excessive memory consumption.

  After modifying this policy, test and validate the resulting behavior in
  your environment to ensure the restrictions are operating as intended.

  Documentation:
    https://imagemagick.org/script/security-policy.php

  Policy Evaluator:
    https://imagemagick-secevaluator.doyensec.com/
-->

<policymap>

  <!-- Maximum number of worker threads. -->
  <policy domain="resource" name="thread" value="4"/>

  <!-- Maximum execution time (seconds) before processing is terminated. -->
  <policy domain="resource" name="time" value="240"/>

  <!-- Maximum number of simultaneously open pixel cache files. -->
  <policy domain="resource" name="file" value="768"/>

  <!-- Maximum heap memory used for pixel cache data. Excess pixels are
       stored in mapped or disk-backed cache. -->
  <policy domain="resource" name="memory" value="768MiB"/>

  <!-- Maximum memory-mapped pixel cache size. Excess cache data is
       written to disk. -->
  <policy domain="resource" name="map" value="2GiB"/>

  <!-- Maximum in-memory image area before pixels are cached to disk. -->
  <policy domain="resource" name="area" value="32MP"/>

  <!-- Maximum disk space available for pixel cache operations. -->
  <policy domain="resource" name="disk" value="2GiB"/>

  <!-- Maximum number of images permitted in a sequence. -->
  <policy domain="resource" name="list-length" value="64"/>

  <!-- Maximum image width. -->
  <policy domain="resource" name="width" value="16KP"/>

  <!-- Maximum image height. -->
  <policy domain="resource" name="height" value="16KP"/>

  <!-- Optional: periodically yield CPU time to improve system responsiveness. -->
  <!-- <policy domain="resource" name="throttle" value="2"/> -->

  <!-- Optional: store temporary files in a dedicated private directory. -->
  <!-- <policy domain="resource" name="temporary-path" value="/magick/tmp/"/> -->

  <!-- Optional: force anonymous memory mapping for selected cache allocations. -->
  <!-- <policy domain="cache" name="memory-map" value="anonymous"/> -->

  <!-- Optional: fully synchronize image cache data to disk before closing. -->
  <!-- <policy domain="cache" name="synchronize" value="true"/> -->

  <!-- Optional: shared secret used by distributed pixel cache operations.
       Replace with a site-specific value if enabled. -->
  <!-- <policy domain="cache" name="shared-secret"
            value="secret-passphrase" stealth="true"/> -->

  <!-- Optional: disable execution of all delegates. -->
  <!-- <policy domain="delegate" rights="none" pattern="*"/> -->

  <!-- Optional: disable loading of all image filter modules. -->
  <!-- <policy domain="filter" rights="none" pattern="*"/> -->

  <!-- Optional: disable stdin/stdout image processing ("-"). -->
  <!-- <policy domain="path" rights="none" pattern="-"/> -->

  <!-- Prevent access to sensitive system configuration files. -->
  <policy domain="path" rights="none" pattern="/etc/*"/>

  <!-- Prevent indirect file reads using @filename syntax. -->
  <policy domain="path" rights="none" pattern="@*"/>

  <!-- Prevent use of pipes for reading or writing image data. -->
  <policy domain="path" rights="none" pattern="|*"/>

  <!--
    Restrict high-risk coders.

    Read access is denied while write access remains permitted.
    This allows ImageMagick to generate these formats without accepting
    potentially untrusted input through them.
  -->
  <policy domain="module" rights="write"
          pattern="{MSL,MVG,PDF,PS,SVG,TXT,URL,XPS}"/>

  <!-- Optional: overwrite temporary files and buffers before deletion. -->
  <!-- <policy domain="system" name="shred" value="1"/> -->

  <!-- Optional: initialize allocated memory with zeros for improved security. -->
  <!-- <policy domain="system" name="memory-map" value="anonymous"/> -->

  <!-- Maximum size of a single allocation request. -->
  <policy domain="system" name="max-memory-request" value="512MiB"/>

  <!-- Maximum size and count of an image profile. -->
  <policy domain="system" name="max-profile-size" value="16MiB"/>
  <policy domain="system" name="max-profile-count" value="16"/>

</policymap>
