Opened 3 years ago
Last modified 10 months ago
#11946 reopened defect (bug)
Ensure image MIME type matches extension
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Upload | Version: | 3.0 |
| Severity: | minor | Keywords: | needs-refresh |
| Cc: | ShaneF |
Description
Take a bitmap (BMP) and rename it to .png. WordPress will say it's an image/png everywhere you look. This can cause issues if you're trying to manipulate it (thumbnail it, etc.).
We should either fix the extension or reject it.
Attachments (4)
Change History (33)
comment:1
Viper007Bond — 3 years ago
- Version set to 3.0
Viper007Bond — 3 years ago
comment:2
Viper007Bond — 3 years ago
- Summary changed from Ensure MIME type matches extension to Ensure image MIME type matches extension
Above patch fixes the extension. Tested and seems to work great.
comment:3
Viper007Bond — 3 years ago
- Keywords has-patch needs-testing added
- Milestone changed from Unassigned to Future Release
comment:4
Viper007Bond — 3 years ago
This patch requires GD and should therefore be wrapped in if ( function_exists('getimagesize') ) {. The patch is just a preliminary one though, so I won't bother updating it yet.
- Cc ShaneF added
- Keywords tested added; needs-testing removed
I took a "png" renamed it to "gif" (with patch). Uploaded. File was changed to the correct format, but in the editor it still says "File type: image/gif". Perhaps override the file type as well?
- Milestone changed from Future Release to 2.9.2
This is a potential security problem. Recommending 2.9.2 release fix.
comment:7
in reply to:
↑ 6
Viper007Bond — 3 years ago
Replying to ShaneF:
This is a potential security problem. Recommending 2.9.2 release fix.
I can't think of a way to validate other extensions though, i.e. say a EXE uploaded as an AVI.
Don't we have an array already in there that is offering mime-types per extension? I think it's adviseable to use the same datasource here therein the patch as well instead offering duplicate data.
comment:9
in reply to:
↑ 8
;
follow-up:
↓ 10
Viper007Bond — 3 years ago
Replying to hakre:
Don't we have an array already in there that is offering mime-types per extension? I think it's adviseable to use the same datasource here therein the patch as well instead offering duplicate data.
That array (in get_allowed_mime_types()) is a list of allowed MIMEs that's filterable. It also has multiple extensions to one common MIME. Yes, I guess I could array_flip() it and then pop off the first extension, however I didn't think this was reliable enough due to the filter.
comment:10
in reply to:
↑ 9
Viper007Bond — 3 years ago
Replying to Viper007Bond:
That array (in get_allowed_mime_types()) is a list of allowed MIMEs that's filterable. It also has multiple extensions to one common MIME. Yes, I guess I could array_flip() it and then pop off the first extension, however I didn't think this was reliable enough due to the filter.
Actually, I take that back, it could work now that I think of it.
comment:11
hakre — 3 years ago
Well I did not say that it is fitting per-se, but worth to take a look into it. I mean why duplicate data here? But no idea if it is available in the location you would like to use it. We might need to introduce another filter here (or isn't there already one?!). Might make sense in the one or other way.
comment:12
Viper007Bond — 3 years ago
Now I remember why I just made a new array -- it's the list of image types that the function can identify. No point in using the other array.
comment:13
nacin — 3 years ago
- Milestone changed from 2.9.3 to 3.0
comment:14
nacin — 3 years ago
- Resolution set to fixed
- Status changed from new to closed
comment:15
Viper007Bond — 3 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Should be moved to a helper function and added to the other upload functions (sideload and the bits one).
comment:16
nacin — 3 years ago
- Keywords needs-patch added; has-patch tested removed
comment:17
westi — 3 years ago
- Priority changed from lowest to normal
Bumping the need for a patch up the importance radar
comment:18
Viper007Bond — 3 years ago
- Owner set to Viper007Bond
- Status changed from reopened to assigned
comment:19
Viper007Bond — 3 years ago
- Keywords has-patch needs-testing added; needs-patch removed
- Status changed from assigned to accepted
11946.4.patch introduces wp_check_filetype_and_ext() which does what wp_check_filetype() does, but then goes on to attempt to validate the type and extension. If it determines that the extension doesn't match what the type truly is, then it'll return proper_filename as a part of it's returned array.
I've modified the standard upload function, the sideload function, and the bits function to make use of this new function.
I have only tested this using the standard upload process, not sideload or bits.
comment:20
nacin — 3 years ago
comment:21
nacin — 3 years ago
- Milestone changed from 3.0 to 3.1
Viper007Bond and I have thoroughly tested this for sideloads and uploads. Weary about bits, so going to handle that no sooner than 3.1.
comment:22
hakre — 3 years ago
3.1 now on shedule. maybe optionally support fileinfo?
comment:23
nacin — 3 years ago
- Milestone changed from Awaiting Triage to 3.1
Just need to get the existing patch working for bits. Probably would be good for Joseph to take a look.
comment:24
hakre — 3 years ago
- Keywords needs-patch added; has-patch needs-testing removed
Patch is broken.
comment:25
nacin — 3 years ago
- Keywords needs-refresh added; needs-patch removed
comment:26
ryan — 2 years ago
- Resolution set to fixed
- Status changed from accepted to closed
comment:27
nacin — 2 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Last bit is needed.
comment:28
nacin — 2 years ago
- Milestone changed from 3.1 to Future Release
comment:29
markoheijnen — 10 months ago
Added a fix for wp_upload_bits at ticket #21292

Potential solution