Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Policy case sensitivity #4235

Closed
frederikbosch opened this issue Sep 16, 2021 · 1 comment
Closed

Policy case sensitivity #4235

frederikbosch opened this issue Sep 16, 2021 · 1 comment

Comments

@frederikbosch
Copy link

frederikbosch commented Sep 16, 2021

ImageMagick version

Version: ImageMagick 7.1.0-7 Q16-HDRI x86_64 2021-09-12 https://imagemagick.org

Operating system

Linux

Operating system, version and so on

alpine 3.13 self-compiled, php 7.4 using imagick extension v3.5.1

Description

ImagickException: "attempt to perform an operation not allowed by the security policy `png' @ error/static.c/RegisterStaticModule/247"

Steps to Reproduce

Code in PHP

$imagick = new \Imagick();
$imagick->setFormat('png');

fails with the following policy

    <policy domain="delegate" rights="none" pattern="*" />
    <policy domain="module" rights="none" pattern="*" />
    <policy domain="module" rights="read | write" pattern="{GIF,JPEG,PNG,WEBP,SVG,BMP,TIFF}" />
    <policy domain="coder" rights="read | write" pattern="{GIF,JPEG,PNG,WEBP,SVG,BMP,TIFF}" />

and succeeds with the following policy.

    <policy domain="delegate" rights="none" pattern="*" />
    <policy domain="module" rights="none" pattern="*" />
    <policy domain="module" rights="read | write" pattern="{GIF,gif,JPEG,jpeg,PNG,png,WEBP,webp,SVG,svg,BMP,bmp,TIFF,tiff}" />
    <policy domain="coder" rights="read | write" pattern="{GIF,JPEG,PNG,WEBP,SVG,BMP,TIFF}" />

While the Security Policy Page states:

Policy patterns are case sensitive. To get expected behavior, coders and modules must be upper-case (e.g. "EPS" not "eps").

@urban-warrior
Copy link
Member

urban-warrior commented Sep 18, 2021

The ImageMagick security policy is behaving properly. As stated, the policy patterns are case sensitive. Internally all modules & coders are uppercase. In your example, you are setting the format in lowercase. Easy fix. Set the image format to PNG or use a case insensitive pattern in a policy: [Pp][Nn][Gg].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants