Opened 8 years ago
Closed 8 years ago
#40193 closed defect (bug) (fixed)
wp_ajax_crop_image capability checks too strict
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 4.3 |
Component: | Media | Keywords: | has-patch needs-testing |
Focuses: | administration | Cc: |
Description
This function wp_ajax_crop_image()
has two issues, on these two lines:
https://github.com/WordPress/WordPress/blob/62061bab5658386d0bbfbfeb3f89be883fd75ec4/wp-admin/includes/ajax-actions.php#L3166-L3167
Line 3167 (capability):
It checks for user capability customize
.
I believe this should be upload_files
.
This is because the function has a default handler for $context
, which therefore can be used outside of the Customizer feature.
Line 3166 (referer):
It checks for image_editor- . $attachment_id
nonce.
This nonce is created only if the user can edit the file.
Because this function creates a new image from the old without actually editing or removing the old image, this is also too strict.
Conclusions:
- The function works neatly outside of the Customizer, aside from the capability and "referer" restrictions.
- The function has too strict capabilities.
- Function
wp_prepare_attachment_for_js
requires an additional nonce (e.g.{crop-image-$id}
) based on theupload_files
capability.
Attachments (1)
Change History (8)
#3
@
8 years ago
- Focuses javascript removed
- Keywords has-patch reporter-feedback needs-testing added
#4
@
8 years ago
@johnbillion I'm personally building some simple UI for quickly changing the origin of the crop. And I'd like to quickly be able to regenerate the image after the user made that change. Having that ajax action at our disposal is very handy!
Looks like the patch is just enough, yes.
#5
@
8 years ago
- Keywords reporter-feedback removed
@johnbillion Here are two scenarios I could quickly think of:
- Setting a social image for Open Graph/Twitter.
- Setting a page header image (or any other layout part).
I believe the change is sufficient for most scenarios plugin/theme authors will encounter.
If you'd also like to cover scenarios outside of post editing, then upload_files
would be a better fit (as per original comment).
@Cybr Thanks for the report. What's the use case for a user being able to generated a crop of an image if they cannot edit the attachment?
I think 40193.diff should be sufficient, but there may well be a use case that I'm unaware of. Let me know!