Skip to content

Photon: strip_image_dimensions_maybe() method prone to fail due to file_exists() #2472

@ethitter

Description

Jetpack_Photon::strip_image_dimensions_maybe() calls file_exists() without checking if the image is local and should be accessible on the filesystem:

if( file_exists( $upload_dir["basedir"] . $file_path ) )
.

If the file_exists() check is necessary, the method should first check that the image was uploaded to the current WP installation. Even then, it's problematic because it assumes uploads are locally accessible, but that isn't necessarily the case. For sites hosted on distributed hosting platforms that don't store the images locally, sites using a plugin like WP Offload S3 to store media centrally/on a CDN, or sites using Core filters to change upload locations, the check will always fail.

Ideally, the method shouldn't use file_exists() at all, but if it must, there should be more care given to whether the image can be accessed locally, and the check should be gated by a filter so that users can disable it.

Is there a way to rework the strip_image_dimensions_maybe() method to work regardless of where the image is hosted?

Introduced to fix #73.

Metadata

Assignees

No one assigned

    Labels

    [Feature] Photonaka "Image CDN". Feature developed in the Image CDN package and shipped in multiple plugins[Pri] Low[Type] EnhancementChanges to an existing feature — removing, adding, or changing parts of it

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions