Repository navigation
Releases
v0.10.2
A security release for the export of the image classes to Bunny: upgrade if a Bunny API key is configured.
Security
wp pollora media thumbs export --driver=bunny(andpollora:media:thumbs:exportwith the framework) no longer lets WordPress follow the redirects of its requests to the Bunny API: WordPress sent theAccessKeyheader, and on a write the classes, to wherever a redirect led. A redirect is followed only withinhttps://api.bunny.net, up to five; any other one is reported as a refusal (since 0.6.0)
Fixed
- A write of the classes answered by a
302or a303was followed by a read and reported as applied. It is now reported as a refusal (since 0.6.0)
Upgrading with Pollora
Framework 13.37.0 to 13.43.2 do not accept 0.10.2: upgrade the framework as well (composer update pollora/framework pollora/media --with-all-dependencies). Framework 13.43.3 and later: composer update pollora/media.
v0.10.1
A security release. Every version before it is affected: upgrade, then repair what is already on the disk. Read Changed first: some behaviour changes.
Security
Upgrading changes nothing on the disk by itself. Follow Repairing media left public in the README: make each private media private again, then purge the CDN.
Private media (since 0.3.0 unless said otherwise):
- Anyone could read a private media attached to no post, and get its signed URL: over REST (
GET /wp/v2/media/{id}and the collection), on its attachment page, in its embed and feed, and in the oEmbed answer - The feed of a private media was also printed to a request that runs without themes, such as a direct one to
wp-blog-header.php - The same page, reached as a single post (
?post_type=attachment&p=N, an attached media included) or with the posts page in the query, showed the private media; when WordPress has no attachment pages, it redirected to the signed URL of the file, and otherwise to its slug - Any signed-in user, a subscriber included, could get the signed URL of a private media by asking WordPress to preview a
[gallery]shortcode (admin-ajax.php?action=parse-media-shortcode) - A private media that is not an image (PDF, archive, video, audio) was never made private on the disk, neither at upload nor by
wp pollora media visibility --private, which reported a success with no file changed - The files written after a media was made private (an edit in the media library, sizes made later, the new media the block editor saves a crop or a rotation as) were left public. They are made private when the metadata is saved, and the copy made by the editor is private
- The files WordPress keeps of an image before its edit, and its other companions (
source_image,animated_video,animated_video_poster), did not follow the visibility of the media - The sizes of a private media made at upload, when its image is edited, when its focal point moves or by
thumbs warmkept the default visibility of the disk (declared sizes, since 0.4.0) - The fallback route served the file of a declared size of a private media when that file existed, with a public cache of one year, and made or served sizes of the original a private image had before its edit (since 0.5.0)
- While the server is saturated, the fallback route could answer with a size of another media whose name starts like the one asked for, or that has the same name with another extension, private or not (since 0.5.0)
Networks:
- On a site other than the main one, no file of a private media was made private, and the files of the main site with the same names were changed instead
- Deleting a site whose uploads are the root of the library (a network created before WordPress 3.5, uploads moved out of
sites/N) deleted every file of the library (since 0.1.0) - On a site other than the main one, the declared sizes used the paths of the main site: deleting a media could delete the main site's files (since 0.4.0),
thumbs prunerun there could delete them too (since 0.4.0), and the fallback route could serve a private size of the main site (since 0.5.0)
Stream wrapper:
rmdir('pollora://.')(since 0.1.0),pollora://uploads/.and spellings with a backslash (since 0.2.0) deleted the whole media library, because the disk reads them as its root after the wrapper had taken them for a folder..segments and backslashes are now resolved by the wrapper first
Changed
Behaviour changes to check before upgrading:
- WordPress 6.2 or later is required: the database queries use the
%iplaceholder - REST: for a user without
upload_fileswho cannot edit it, a private media answers401or403on/wp/v2/media/{id}, and is left out of the collection and of_embed. A headless front-end that reads private media anonymously, or a custom role that relied on it, has to authenticate or be given the capability - Attachment page and oEmbed: for the same users, the attachment page of a private media, its embed and its feed are not found, and oEmbed answers
404. A plugin that gates a download through that page has to give its usersedit_poston the media, or serve it elsewhere - Shortcode preview:
parse-media-shortcodeis refused to a user withoutupload_fileswho names no post they can edit - Networks: a site other than the main one gets no declared size, including the images uploaded before: WordPress serves its own sizes, and the original under a declared name it has no size for. The declared size recorded in the metadata of such an image is no longer read
- Networks: on a site other than the main one, the fallback route serves nothing, and
wp pollora media thumbs prunerefuses to run - Networks: when the uploads of a deleted site are the whole library, its files stay on the disk
- Fallback route: a size whose original is no longer on the disk is a
404, even when its file exists. The route asks the database and the disk for a size already made, where it only asked the disk - Larger file list: the files of a media now include the file of a media that is not an image, the attached file when it differs from the one of the metadata, the companions WordPress records and the files kept from before an edit. Making a media private or public changes them all,
wp pollora media fileslists them, and the$pathsof thepollora/media/deletedaction (and theMediaDeletedevent of an application that relays it) holds them wp pollora media visibilitycan report new failures: a file WordPress still records for a media but that is no longer on the disk, such as one kept from before an edit, is reported as not changed, and the command then exits with1. A script that stops on a failure has to expect it- Saving the metadata of a private media sets the visibility of each of its files, one call to the disk per file
- PHPStan runs at level 10. A value without a type from WordPress, WP-CLI, a filter or a constant that is neither a scalar nor stringable now reads as
''or0 UrlReplacementand the private media lookup pass table and column names to$wpdb->prepare()as%iidentifiers
Fixed
- A file is treated as private when the database query that looks its media up fails, instead of public
- A personal data export archive that cannot be read is no longer copied to the disk as an empty file before a
TypeError:PrivacyExportFailedExceptionis thrown and the disk is left alone - A write through
pollora://no longer ends in aTypeErrorwhen the temporary directory cannot be written: the file is stored, only its local copy is given up - Development only:
antecedent/patchworkis required at commitd588654of itsmasterbranch (antecedent/patchwork#235), aliased as 2.2.6, so that Pest mutants are no longer counted as caught when tests hang. This pin is temporary until the next Patchwork release
v0.10.0
Fixed
- The three thumbnail drivers now answer the same way on the cases the adapter contract tests had listed as known deviations (#58), and
THUMBNAIL_KNOWN_DEVIATIONSis empty.PolloraThumbnailDrivergives the same file name for/a.jpganda.jpg.BunnyThumbnailDriverencodes?and#in the key of the original, sosizeOf()finds the class ofwhat?.jpgagain.PolloraThumbnailDriver::sizeOf()andImgproxyThumbnailDriver::sizeOf()answer only the name of a declared size, and the imgproxy driver no longer recognises the URL of a size it refuses (default). The names and URLs of the keys that were valid (no leading slash, no?or#) are unchanged. SizeGeometryno longer divides by zero for an original WordPress recorded with no dimensions: a scale or a contain keeps the dimensions it was given (no geometric resize) andcoverRegion()keeps the whole original, soDeclaredSizes::downsize()and the drivers'url()never throwDivisionByZeroError.
Changed
- BREAKING:
PolloraThumbnailDrivertakes the declared sizes (ImageSizes) as a third constructor argument andImgproxyThumbnailDriveras its third, before the base URL (new ImgproxyThumbnailDriver($signer, $config, $sizes, $baseUrl, $bucket)), to recognise only declared sizes asBunnyThumbnailDriveralready does.ThumbnailDrivers::make()andDeclaredSizespass them; only code that builds these drivers by hand changes.
||||||| d54194b
- The unit suite loads its stand-in for WP-CLI from
tests/bootstrap.phpinstead oftests/Pest.php, which the integration suite also loads (a real WordPress must not find aWP_CLIthat is not WP-CLI). No change to the package.
Security
- A size signature is never made with an empty key (#53). With an empty
app.key(or a blank salt) the HMAC of a file name was computable by anyone, who could then have the declared sizes made for any original.SizedFileNamenow throwsInvalidMediaConfigurationException::emptySigningKey()when the key it resolves is empty or blank, with a message that says what to set (APP_KEY, or the WordPress salts); the key is still resolved when a signature is made, so a key known late works, and an installation with a key sees no change: the file names and signatures are what they were (the signature stays cut to 12 hexadecimal digits, which a name already issued depends on).
Added
- An integration suite (
tests/Integration,composer test:integration) that runs against a real WordPress: the upload directory moved to the wrapper and the public URL, an uploaded image stored with the sizes WordPress and the module make through the real image editors, the URL of a declared size and the file made when it is first asked for, the focal point meta written over REST (an editor only, a point out of range refused) with the covers made around it, the legacy URLs replaced in the content, and the private flag read from the table. It is not part of the defaultpestrun; the harness's optionalWordPress integrationjob starts it. - A focal point per image (#18). The post meta
_pollora_focal_point({x, y}, fractions of the original from 0 to 1, kept to a thousandth) is declared withregister_post_meta()and a schema, so it is read and written over REST by a user who can edit the attachment.FocalPointvalidates it (a value that is not a point is no point),FocalPointsreads it typed, once per media ($media->focalPoints()->for($id),set(),clear()), and the newpollora/media/focal_pointfilter has the last word. With a point,SizeGeometry::coverRegion(..., $anchor, $focal)centres the region on it, clamped to the edges, instead of using the anchor; dimensions,srcsetand the sizes that do not crop are unchanged.ImageSizeSpecgets an optional$focalandfocusedOn(); the point is part offingerprint()and of the signature, and the file of a cover around one is namedphoto-card-600x400-f0250_0750-{signature}.webp, so moving the point never leaves a stale copy and the fallback route makes the file from its name alone, with no lookup. The files of a size of an image without a point keep their names. Changing or removing the point deletes the files made around the previous one and makes theeager()covers around the new one;thumbs pruneremoves the crops around a point that is not the image's any more; the files go with the media. imgproxy and Bunny cannot hold a point in a preset or a class: a cover of an image with a point is made by the module whatever the driver (so the fallback route is now registered with these drivers too), a private media stays kept from the service.ThumbnailRouteaccepts the new segment.DeclaredSizes::make(),fileFor()andexistingFiles()take an optional focal point,SizePruneran optional$focalOfclosure,SizedFileName::parse()returns the point asfocal. No editing screen yet.
v0.9.0
Security
-
A request for a size no longer gets past the name checks with a trailing newline or another control character (the
$of the patterns matched before a final newline): it is a 404 before anything reaches the storage, where it used to end in a 500. The route and the name parser now anchor withD. The guarantee that only declared, signed sizes are ever made is now locked byDeclaredSizesContractTest(SEC-06) -
The remaining name checks anchor with
Dtoo: a size declared ascardfollowed by a newline is refused (it was accepted), the size segment of an imgproxy URL, the sizes already made that stand in for one that cannot be made, and the parent lookup of an extra width ignore a name ending with a newline. The pruner compares a file signature withhash_equals()instead of!==(SEC-06) -
The id of a Bunny pull zone (it goes into the URL of the Bunny API) no longer accepts a trailing newline:
"1234\n"was accepted by/^\d+$/and is now refused before any request. The loopback host check of the thumbnail export and the multisite folder match of the uploads base anchor withDtoo, as defence in depth (a host parsed byparse_url()and a WordPressbasedircannot carry a newline today) (SEC-06)
Changed
- A media disk that cannot be built (
InvalidMediaConfigurationException), a thumbnail that cannot be made (ImageProcessingFailedException) and a Bunny request that fails (BunnyRequestFailedException) throw named exceptions instead of a bare\RuntimeException. They extend\RuntimeException, so acatch (\RuntimeException)keeps working, and the messages keep their wording, with a hint added where one was missing
v0.8.0
Added
- An anchor for
cover():ImageSize::add('portrait')->cover(400, 500, Anchor::Top).Anchorhas the nine positions ofadd_image_size()(Center,Top,Bottom,Left,Right,TopLeft,TopRight,BottomLeft,BottomRight). The region a cover keeps is placed by the anchor instead of centred (SizeGeometry::coverRegion(..., $anchor)), the dimensions do not change, and a non-centred anchor is part ofImageSizeSpec::fingerprint(), so it changes the name of the files and thevof a service URL. The fingerprint of a centred size is what it was, so no existing file or URL changes.ImageSizeSpecrefuses an anchor on a fit that is not a cover. imgproxy: the preset gets agravity(no,so,we,ea,nowe,noea,sowe,soea), checked on imgproxy 4 (a left, right, top and bottom anchor keep the part of the image they name). Bunny: a cover anchored away from the centre is refused (BunnyClasses::refusal()), reported bythumbs exportandpollora:doctor, since no parameter of a class is known to move its crop
v0.7.1
Fixed
- The
eager()sizes of an image edited in the media library (cropped, rotated, flipped, or put back by Restore image) are made, as at upload. WordPress writes the new original and its own sizes, then saves the metadata withoutwp_generate_attachment_metadata, so the sizes were only worked out in the URLs and never made: a disk served directly, with no fallback, returned broken images untilthumbs warmran.DeclaredSizes::remake()runs onwp_update_attachment_metadataand acts only when thefileof the metadata changes. The sizes of the previous original stay on the disk, where Restore image expects them, andthumbs prunekeeps them - README: the Apply changes to: thumbnail only option of the image editor is not followed by a declared size, which is always made from the original
v0.7.0
Added
--exclude=<patterns>onwp pollora media migrate(comma-separated), andMediaMigrator::migrate(exclude: [...]): paths matching a pattern (woocommerce_uploads/*,*.zip;*matches across folders) are not copied.MigrationReport::$excludedlists them, and the progress callback receivesexclude. Meant for folders of private files (protected downloads, logs, form attachments, backups) that a public disk would serve to anyone
Fixed
migratesent noCache-Controlwith the files it copied, whereas an upload does: a migrated file was served without the long cache header.MediaMigratortakes the header as its third constructor argument, andwp pollora media migratepassescache_controlmigrateignored the visibility of the source: a private file copied to a disk with a public default became public. The visibility of each file is now sent with the write, in the same request (no second call per file)
v0.6.1
Fix, found by running a real site against a real Bunny pull zone.
- The URL of a size made by a service now carries a version of the size (
?class=card&v=3f9a1c2bfor Bunny,…@webp?v=3f9a1c2bfor imgproxy). Before, after a class was changed the CDN kept serving the old variant under the same URL; a changed size is now a new URL, as it is a new file name for the default driver. Bunny and imgproxy ignorev; checked with and without forced classes. - README: Bunny can serve a size one pixel narrower than advertised (1199 for 1200) when the ratio of the original does not divide exactly; imgproxy is exact. The 0.6.0 notes overstated this.
See the CHANGELOG.
v0.6.0
Sizes made by a service.
bunnyandimgproxydrivers for the sizes (POLLORA_MEDIA_THUMBNAILS_DRIVER): the URL of a size is a Bunny image class (photo.jpg?class=card) or a signed imgproxy URL that names a preset (imgproxy 4.0.x, presets-only; source: the library URL or ans3://object). No file is made and no fallback route is registered; a private media never goes to the service.wp pollora media thumbs export --driver=bunny|imgproxy: one class or preset per declared size and per extra width. Bunny: merged by name and written with--execute(dry run otherwise); imgproxy: prints the configuration, without the key or the salt.- Checked on a real Bunny pull zone and a real imgproxy 4.0.17 (URL and S3 sources): the dimensions advertised for each size are the ones served. Bunny accepts only letters and digits in a class name (
hero-640wis the classhero640w; colliding sizes are refused) and replaces the whole list of classes it is sent, so the export merges first. - The
ThumbnailDriverport gainssizeOf()andrefusal(); thesrcsetof the extra widths is built through the driver.
See the CHANGELOG.
v0.5.0
Sizes made on demand.
- A declared size that is not
eager()is made the first time its URL is asked for, at the exact path of the URL (200,Cache-Control: public, max-age=31536000, immutable, never a redirect); the web server or the CDN serves it without PHP afterwards. - The name, the signature and the extension are checked without asking the disk; then the dimensions, the weight and the visibility of the original. A request that fails a check gets a 404.
- Per-server limits (
flocklocks): one process per file, a ceiling of simultaneous sizes, no size for a huge original, and the nearest existing size with no cache for a request that waits too long. - The files of sizes made on demand are deleted with their media. The
ThumbnailDriverport.
See the CHANGELOG.