Repository navigation
Media: Keep non-image uploads on the classic path - #15512
adamsilverstein wants to merge 8 commits into
Conversation
A plugin can extend the uploader's file type filter for a single frame, as page builders do for SVG and JSON. The client-side pipeline validated those files against the mime types the page was rendered with, and rejected them in the browser. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vwYjTNtbdhcmnECA2bZxP
Only route images the client-side pipeline can process (JPEG, PNG, GIF, WebP, AVIF and HEIC/HEIF) and leave every other file to plupload. The pipeline does no processing for other files, and its type check ignored the uploader's own filters, so file types a plugin allows for a single frame were rejected before reaching the server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vwYjTNtbdhcmnECA2bZxP
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| */ | ||
| function isPipelineFile( file ) { | ||
| return ( | ||
| /^image\/(?:jpeg|png|gif|webp|avif|heic|heif)$/i.test( |
There was a problem hiding this comment.
I worry a bit about hard coding this list and maintenance (eg. when we add jxl support this will need updating). That said, we already do this in several places in media. I'dd see if we can dedupe this a bit.
There was a problem hiding this comment.
I started addressing this in 1654c43 by consolidating the current core side logic. I'll follow up with a Gutenberg side Issue/PR to add something like isClientSideProcessable( file ) and then have core use that directly, that would move all the logic into one place.
There was a problem hiding this comment.
I suppose it isn't too bad to have a hard-coded list of file types that go through the client-side flow. While it requires manual updating, I imagine we'd be updating it quite infrequently?
There was a problem hiding this comment.
True, its rare we need to update these hardcoded type lists! That said, I know in the past when we added support for AVIF we forgot some places to add it and only realized when a bug report was filed. Adding the inline commenting saying where the related items need to stay in sync mostly resolves this for me, but if we can move to a single point of truth thats even better!
There was a problem hiding this comment.
Yes, agree with you there! 🙂
The formats were listed twice, once to route files to the pipeline and once to type the media frame's placeholder tiles, so adding a format (eg. JPEG XL) meant finding both. Both now read one list in media-upload-pipeline.js, exposed to media-frame-upload.js as `wp.mediaUploadPipeline.getImageSubtype()`, with a pointer to the upload-media constants it mirrors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vwYjTNtbdhcmnECA2bZxP
…mage-types Media: Keep one list of the image formats the upload pipeline takes.
andrewserong
left a comment
There was a problem hiding this comment.
Nice fix! This is testing well for me with the popular Safe SVG plugin to allow svg uploads. Regular images (e.g. jpegs, etc) continue to be processed via client-side processing, and SVGs upload correctly on their own:
LGTM!
desrosj
left a comment
There was a problem hiding this comment.
A few small comment changes. I had some small test suggestions, but I think that the tests may change based on another finding.
It seems that the same bug can still hit image types.
The root cause of this is the client-side check against allowedMimeTypes, which is captured when the page renders. That check still applies to images.
A brief summary from Claude:
Suppose a plugin allows an image type (
AVIForWebP), only for its own frame or only when a request parameter is present. It doesn't add that type toupload_mimesat render time. That upload will still fail in the browser with "not allowed to upload this file type."
Claude suggested making a file classic any time the type is not in Object.values( settings.allowedMimeTypes ). The server would then decide, which closes the whole class of bug rather than only the non-image half. I'm not sure if that's in the spirit of how the feature was intended to work, though.
Co-authored-by: Jonathan Desrosiers <359867+desrosj@users.noreply.github.com>
I'm not sure that is right, but I will check!
Those two types are already allowed, maybe JXL would be a better test case. How does it add that type, I assume using the mime_types or https://developer.wordpress.org/reference/hooks/mime_types/ or upload_mimes - https://developer.wordpress.org/reference/hooks/upload_mimes/.
when does it add it? is this a bug or a documentation gap? |
|
I'm having claude do some testing on this and research via https://veloria.dev/ on existing plugin use. I'll run tests on adding and removing mime type support to verify they are handled correctly in the client side uploader in gutenberg and the media library. |
|
Thanks @desrosj, good catch - this does reproduce, so I'm adding your suggestion to the PR. Claude tested this against real plugins, short version:
I also had Claude record some testing screencasts: 03-review-scenario-pr-head.mp405-review-scenario-suggested-fix.mp4 |
A plugin can allow an image type only for its own uploads, leaving it out of the allowed types the page was rendered with. The pipeline rejected those images in the browser before the server could decide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vwYjUDjTr7YBnLJwEFAc6
Send a file to plupload when its type is missing from the allowed types the page was rendered with, so the server decides, as it did before the pipeline. Plupload's own filter runs first, so this only affects files a plugin let through on purpose. Props desrosj. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018vwYjUDjTr7YBnLJwEFAc6
Trac ticket: https://core.trac.wordpress.org/ticket/66490
Item 2 on the ticket: page builders that allow SVG or JSON in their media frames had those uploads rejected in the browser once the frame went through the client-side pipeline.
Claude worked through this one, summary below:
AI Use
Code and description both drafted with 🤖 Claude Code from the Elementor report. I will review and test.
🤖 Generated with Claude Code
https://claude.ai/code/session_018vwYjTNtbdhcmnECA2bZxP