FileValidatorImage::hasBadExif()
Does given file have potential EXIF malware?
An image having malware in it doesn’t mean it’s necessarily unsafe, as something still has to execute the bad code. But I still think it’s a good idea to block images that might have it just to prevent them from spreading any further. This method just detects some common cases in the EXIF data of JPEGs, but it’s still possible for images to contain bad data elsewhere.
This protected method is for hooks to monitor and it is likely not intended to be called directly.
Internal usage
// basic internal usage
$array = $fileValidatorImage->hasBadExif(string $filename);
// internal usage with all arguments
$array = $fileValidatorImage->hasBadExif(string $filename, bool $verbose = false);Arguments
| Name | Type(s) | Description |
|---|---|---|
$filename | string | JPEG file |
$verbose (optional) | bool | Return array of found malware types? Default:false |
Return value
array bool nullReturns null if exif data not available, array if verbose requested or boolean otherwise
Hooking FileValidatorImage::hasBadExif(…)
You can add your own hook events that are executed either before or after the File method is executed. Examples of both are included below. A good place for hook code such as this is in your /site/ready.php file.
Hooking before
The 'before' hooks are called immediately before each File method call is executed. This type of hook is especially useful for modifying arguments before they are sent to the method.
$this->addHookBefore('FileValidatorImage::hasBadExif', function(HookEvent $event) {
// Get the object the event occurred on, if needed
$FileValidatorImage = $event->object;
// Get values of arguments sent to hook (and optionally modify them)
$filename = $event->arguments(0);
$verbose = $event->arguments(1);
/* Your code here, perhaps modifying arguments */
// Populate back arguments (if you have modified them)
$event->arguments(0, $filename);
$event->arguments(1, $verbose);
}); Hooking after
The 'after' hooks are called immediately after each File method call is executed. This type of hook is especially useful for modifying the value that was returned by the method call.
$this->addHookAfter('FileValidatorImage::hasBadExif', function(HookEvent $event) {
// Get the object the event occurred on, if needed
$FileValidatorImage = $event->object;
// An 'after' hook can retrieve and/or modify the return value
$return = $event->return;
// Get values of arguments sent to hook (if needed)
$filename = $event->arguments(0);
$verbose = $event->arguments(1);
/* Your code here, perhaps modifying the return value */
// Populate back return value, if you have modified it
$event->return = $return;
}); FileValidatorImage methods and properties
API reference based on ProcessWire core version 3.0.269