Skip to content

Commit 53a8c14

Browse files
authored
Merge pull request #465 from axa-group/slallemand/fix/imagemagick-policy
fix for the new behaviour in ImageMagick in baseimage
2 parents 9ba94a3 + fe1189f commit 53a8c14

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

.drone.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ steps:
2828
image: plugins/docker
2929
settings:
3030
repo: axarev/parsr-base
31-
context: .
31+
context: docker/parsr-base
3232
dockerfile: docker/parsr-base/Dockerfile
3333
username:
3434
from_secret: registry_user

docker/parsr-base/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ RUN apt-get update && \
1919
pip install PyPDF2 && \
2020
pip3 install ghostscript PyPDF2 camelot-py[cv] numpy pillow sklearn tabula-py
2121

22+
ADD policy.xml /etc/ImageMagick-6/policy.xml
23+
2224
WORKDIR /opt/app-root/src
25+
2326
RUN chown 1001:0 /opt/app-root/src
2427

2528
ENV PATH $PATH:/opt/app-root/src/node_modules/.bin

docker/parsr-base/policy.xml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 '' domain NMTOKEN #REQUIRED
7+
name NMTOKEN #IMPLIED pattern CDATA #IMPLIED rights NMTOKEN #IMPLIED
8+
stealth NMTOKEN #IMPLIED value CDATA #IMPLIED>
9+
]>
10+
<!--
11+
Configure ImageMagick policies.
12+
13+
Domains include system, delegate, coder, filter, path, or resource.
14+
15+
Rights include none, read, write, execute and all. Use | to combine them,
16+
for example: "read | write" to permit read from, or write to, a path.
17+
18+
Use a glob expression as a pattern.
19+
20+
Suppose we do not want users to process MPEG video images:
21+
22+
<policy domain="delegate" rights="none" pattern="mpeg:decode" />
23+
24+
Here we do not want users reading images from HTTP:
25+
26+
<policy domain="coder" rights="none" pattern="HTTP" />
27+
28+
The /repository file system is restricted to read only. We use a glob
29+
expression to match all paths that start with /repository:
30+
31+
<policy domain="path" rights="read" pattern="/repository/*" />
32+
33+
Lets prevent users from executing any image filters:
34+
35+
<policy domain="filter" rights="none" pattern="*" />
36+
37+
Any large image is cached to disk rather than memory:
38+
39+
<policy domain="resource" name="area" value="1GP"/>
40+
41+
Define arguments for the memory, map, area, width, height and disk resources
42+
with SI prefixes (.e.g 100MB). In addition, resource policies are maximums
43+
for each instance of ImageMagick (e.g. policy memory limit 1GB, -limit 2GB
44+
exceeds policy maximum so memory limit is 1GB).
45+
46+
Rules are processed in order. Here we want to restrict ImageMagick to only
47+
read or write a small subset of proven web-safe image types:
48+
49+
<policy domain="delegate" rights="none" pattern="*" />
50+
<policy domain="filter" rights="none" pattern="*" />
51+
<policy domain="coder" rights="none" pattern="*" />
52+
<policy domain="coder" rights="read|write" pattern="{GIF,JPEG,PNG,WEBP}" />
53+
-->
54+
<policymap>
55+
<!-- <policy domain="system" name="shred" value="2"/> -->
56+
<!-- <policy domain="system" name="precision" value="6"/> -->
57+
<!-- <policy domain="system" name="memory-map" value="anonymous"/> -->
58+
<!-- <policy domain="system" name="max-memory-request" value="256MiB"/> -->
59+
<!-- <policy domain="resource" name="temporary-path" value="/tmp"/> -->
60+
<policy domain="resource" name="memory" value="256MiB"/>
61+
<policy domain="resource" name="map" value="512MiB"/>
62+
<policy domain="resource" name="width" value="16KP"/>
63+
<policy domain="resource" name="height" value="16KP"/>
64+
<!-- <policy domain="resource" name="list-length" value="128"/> -->
65+
<policy domain="resource" name="area" value="128MB"/>
66+
<policy domain="resource" name="disk" value="1GiB"/>
67+
<!-- <policy domain="resource" name="file" value="768"/> -->
68+
<!-- <policy domain="resource" name="thread" value="4"/> -->
69+
<!-- <policy domain="resource" name="throttle" value="0"/> -->
70+
<!-- <policy domain="resource" name="time" value="3600"/> -->
71+
<!-- <policy domain="coder" rights="none" pattern="MVG" /> -->
72+
<!-- <policy domain="module" rights="none" pattern="{PS,PDF,XPS}" /> -->
73+
<!-- <policy domain="delegate" rights="none" pattern="HTTPS" /> -->
74+
<!-- <policy domain="path" rights="none" pattern="@*" /> -->
75+
<!-- <policy domain="cache" name="memory-map" value="anonymous"/> -->
76+
<!-- <policy domain="cache" name="synchronize" value="True"/> -->
77+
<!-- <policy domain="cache" name="shared-secret" value="passphrase" stealth="true"/> -->
78+
<!-- <policy domain="system" name="pixel-cache-memory" value="anonymous"/> -->
79+
<!-- <policy domain="system" name="shred" value="2"/> -->
80+
<!-- <policy domain="system" name="precision" value="6"/> -->
81+
<!-- not needed due to the need to use explicitly by mvg: -->
82+
<!-- <policy domain="delegate" rights="none" pattern="MVG" /> -->
83+
<!-- use curl -->
84+
<policy domain="delegate" rights="none" pattern="URL" />
85+
<policy domain="delegate" rights="none" pattern="HTTPS" />
86+
<policy domain="delegate" rights="none" pattern="HTTP" />
87+
<!-- in order to avoid to get image with password text -->
88+
<policy domain="path" rights="none" pattern="@*"/>
89+
</policymap>

0 commit comments

Comments
 (0)