-
Notifications
You must be signed in to change notification settings - Fork 529
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
ExifMetadataReader class fails due to unnecessary check for 'allow_url_fopen()' #859
Comments
The |
This provides a slightly more tolerant response to `allow_url_fopen` being closed on a server than throwing an exception and baling out. The proposed approach still traps for the status of the `allow_url_fopen` option, and if it is available uses the prior `data://` method. If it is not available, and the source image is not a Tiff file, it writes a low quality version of the image to a temporary file on disk, and uses this as the target for `exif_read_data()` and then once data is read deletes the temporary file. The code works in testing here. Note, this approach is a **demonstration** of an alternative approach rather than a proposal for a definitive solution, in that it uses GD2 functions and so does not handle Tiff images. But presumably if the concept is viable the code could be generalised to work with any of the image libraries supported by Imagine.
This provides a slightly more tolerant response to `allow_url_fopen` being closed on a server than throwing an exception and baling out. The proposed approach still traps for the status of the `allow_url_fopen` option, and if it is available uses the prior `data://` method. If it is not available, and the source image is not a Tiff file, it writes a low quality version of the image to a temporary file on disk, and uses this as the target for `exif_read_data()` and then once data is read deletes the temporary file. The code works in testing here. Note, this approach is a **demonstration** of an alternative approach rather than a proposal for a definitive solution, in that it uses GD2 functions and so does not handle Tiff images. But presumably if the concept is viable the code could be generalised to work with any of the image libraries supported by Imagine.
Well thanks for the additional information. Looks like this was causing problems in 2019, and is still causing problems now. This is a pity - as this choice (to use In my actual use case, suggesting to a sysadmin that they make their server less secure so that an image utility that has no actual need to contact a remote server can correct the rotation of an iPhone image (that was itself read from a local disk) seems like a request that is unlikely to be satisfied. The use of the I think the solution is, where I hope the PR might encourage a more tolerant view of this issue: moving away from the view that it is some kind of "absolute" issue that cannot be addressed. Maybe also the PR might inspire someone who can write better code to fix this issue more generically. |
I don’t think this is true. If a production server should not be able to make network connections, this should be prevented from the operating system side as But I agree that if possible, this library should not require
I don’t see this as “absolute” in any way, this can totally be addressed I think. But I also think it would be great if this gets fixed in PHP itself as well, so maybe you could add a comment with your use case there: https://bugs.php.net/bug.php?id=47336
There might be an even better solution using streams instead of |
I completely agree it is not the only thing that is, could, or should be done. Nonetheless it does appear to be widely used as part of steps to secure php servers.
Of course - but the issue has been open for 15 years and is cast as a documentation issue rather than a code issue, so I'm not expecting that it would lead to a useful code change any time soon.
That would be a very good outcome - let me know if there is anything I can do to help. |
Comment added ... https://bugs.php.net/bug.php?id=47336 |
See #861 |
Issue description
A new Imagine instance can be generated by loading the content of the image file directly.
If you try and add ExifMetadataReader to an instance created this way, and the server environment has
allow_url_fopen
set to 0, the attempt fails: even though in this instance there is no need for remote access to anything to generate the image or read the metadata.The issue is being felt on a server that has a 'locked down' security status (i.e. allow_url_fopen is set to 0, but curl is available) - even though in the specific use case no remote file access is required, if it was Curl is available and could be used. But the check carried out by ExifMetadataReader in
getUnsupportedReason()
doesn't consider either of these contexts, and throws the exception simply because of the value ofallow_url_fopen
which appears to be inappropriate....
What version of Imagine are you using?
1.3.5
What's the PHP version you are using?
8.3
What's the imaging library you are using [gd/imagick/gmagick/any]?
gd2
Minimal PHP code to reproduce the error:
Where
$source_image_raw
is the content of an image file (obtained from reading a local disk file, or from remote location).The text was updated successfully, but these errors were encountered: