Debian Codegraph @

debian/patches/0007-Add-a-debian-policy.patch

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