Skip to content

Releases

v0.10.2

Choose a tag to compare

@ogorzalka ogorzalka released this 04 Dec 13:44
a5eee9b

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 (and pollora:media:thumbs:export with the framework) no longer lets WordPress follow the redirects of its requests to the Bunny API: WordPress sent the AccessKey header, and on a write the classes, to wherever a redirect led. A redirect is followed only within https://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 302 or a 303 was 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

Choose a tag to compare

@ogorzalka ogorzalka released this 02 Dec 09:53
bb3f4b7

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 warm kept 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 prune run 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 %i placeholder
  • REST: for a user without upload_files who cannot edit it, a private media answers 401 or 403 on /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 users edit_post on the media, or serve it elsewhere
  • Shortcode preview: parse-media-shortcode is refused to a user without upload_files who 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 prune refuses 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 files lists them, and the $paths of the pollora/media/deleted action (and the MediaDeleted event of an application that relays it) holds them
  • wp pollora media visibility can 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 with 1. 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 '' or 0
  • UrlReplacement and the private media lookup pass table and column names to $wpdb->prepare() as %i identifiers

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: PrivacyExportFailedException is thrown and the disk is left alone
  • A write through pollora:// no longer ends in a TypeError when the temporary directory cannot be written: the file is stored, only its local copy is given up
  • Development only: antecedent/patchwork is required at commit d588654 of its master branch (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

Choose a tag to compare

@ogorzalka ogorzalka released this 24 Nov 07:52
f407e27

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_DEVIATIONS is empty. PolloraThumbnailDriver gives the same file name for /a.jpg and a.jpg. BunnyThumbnailDriver encodes ? and # in the key of the original, so sizeOf() finds the class of what?.jpg again. PolloraThumbnailDriver::sizeOf() and ImgproxyThumbnailDriver::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.
  • SizeGeometry no 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) and coverRegion() keeps the whole original, so DeclaredSizes::downsize() and the drivers' url() never throw DivisionByZeroError.

Changed

  • BREAKING: PolloraThumbnailDriver takes the declared sizes (ImageSizes) as a third constructor argument and ImgproxyThumbnailDriver as its third, before the base URL (new ImgproxyThumbnailDriver($signer, $config, $sizes, $baseUrl, $bucket)), to recognise only declared sizes as BunnyThumbnailDriver already does. ThumbnailDrivers::make() and DeclaredSizes pass them; only code that builds these drivers by hand changes.

||||||| d54194b

  • The unit suite loads its stand-in for WP-CLI from tests/bootstrap.php instead of tests/Pest.php, which the integration suite also loads (a real WordPress must not find a WP_CLI that 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. SizedFileName now throws InvalidMediaConfigurationException::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 default pest run; the harness's optional WordPress integration job 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 with register_post_meta() and a schema, so it is read and written over REST by a user who can edit the attachment. FocalPoint validates it (a value that is not a point is no point), FocalPoints reads it typed, once per media ($media->focalPoints()->for($id), set(), clear()), and the new pollora/media/focal_point filter 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, srcset and the sizes that do not crop are unchanged. ImageSizeSpec gets an optional $focal and focusedOn(); the point is part of fingerprint() and of the signature, and the file of a cover around one is named photo-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 the eager() covers around the new one; thumbs prune removes 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. ThumbnailRoute accepts the new segment. DeclaredSizes::make(), fileFor() and existingFiles() take an optional focal point, SizePruner an optional $focalOf closure, SizedFileName::parse() returns the point as focal. No editing screen yet.

v0.9.0

Choose a tag to compare

@ogorzalka ogorzalka released this 19 Nov 07:54
4cd49ed

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 with D. The guarantee that only declared, signed sizes are ever made is now locked by DeclaredSizesContractTest (SEC-06)

  • The remaining name checks anchor with D too: a size declared as card followed 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 with hash_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 with D too, as defence in depth (a host parsed by parse_url() and a WordPress basedir cannot 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 a catch (\RuntimeException) keeps working, and the messages keep their wording, with a hint added where one was missing

v0.8.0

Choose a tag to compare

@ogorzalka ogorzalka released this 20 Oct 08:49
4e103f2

Added

  • An anchor for cover(): ImageSize::add('portrait')->cover(400, 500, Anchor::Top). Anchor has the nine positions of add_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 of ImageSizeSpec::fingerprint(), so it changes the name of the files and the v of a service URL. The fingerprint of a centred size is what it was, so no existing file or URL changes. ImageSizeSpec refuses an anchor on a fit that is not a cover. imgproxy: the preset gets a gravity (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 by thumbs export and pollora:doctor, since no parameter of a class is known to move its crop

v0.7.1

Choose a tag to compare

@ogorzalka ogorzalka released this 20 Oct 08:46
0057eb8

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 without wp_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 until thumbs warm ran. DeclaredSizes::remake() runs on wp_update_attachment_metadata and acts only when the file of the metadata changes. The sizes of the previous original stay on the disk, where Restore image expects them, and thumbs prune keeps 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

Choose a tag to compare

@ogorzalka ogorzalka released this 20 Oct 08:46
08b2651

Added

  • --exclude=<patterns> on wp pollora media migrate (comma-separated), and MediaMigrator::migrate(exclude: [...]): paths matching a pattern (woocommerce_uploads/*, *.zip; * matches across folders) are not copied. MigrationReport::$excluded lists them, and the progress callback receives exclude. Meant for folders of private files (protected downloads, logs, form attachments, backups) that a public disk would serve to anyone

Fixed

  • migrate sent no Cache-Control with the files it copied, whereas an upload does: a migrated file was served without the long cache header. MediaMigrator takes the header as its third constructor argument, and wp pollora media migrate passes cache_control
  • migrate ignored 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

Choose a tag to compare

@ogorzalka ogorzalka released this 19 Oct 14:52
267f359

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=3f9a1c2b for Bunny, …@webp?v=3f9a1c2b for 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 ignore v; 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

Choose a tag to compare

@ogorzalka ogorzalka released this 19 Oct 14:16
c7cda68

Sizes made by a service.

  • bunny and imgproxy drivers 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 an s3:// 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-640w is the class hero640w; colliding sizes are refused) and replaces the whole list of classes it is sent, so the export merges first.
  • The ThumbnailDriver port gains sizeOf() and refusal(); the srcset of the extra widths is built through the driver.

See the CHANGELOG.

v0.5.0

Choose a tag to compare

@ogorzalka ogorzalka released this 19 Oct 12:30
0cf9f74

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 (flock locks): 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 ThumbnailDriver port.

See the CHANGELOG.