Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate MIME type against extensions #120

Merged
merged 10 commits into from Oct 2, 2017

Conversation

Sidsector9
Copy link
Member

@Sidsector9 Sidsector9 commented Sep 25, 2017

See #88

'wdp' => array( 'image/vnd.ms-photo' ),
'web' => array( 'application/vnd.xara' ),
'weba' => array( 'audio/webm' ),
'webapp' => array( 'application/x-web-app-manifest+j
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure this is the same check as #88 describes...

SHouldn't this check that $file_extension matches $file_mime_type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielbachhuber
I'm a bit confused 😅 ?
For example, a file can have an extension .jpeg with the following mime-types : image/jpeg, image/pjpeg, in case, the extension is modified to .png, the mime-type will still remain the same and return an error

@@ -38,3 +38,5 @@ theme-update:
check: Theme_Update
php-in-upload:
check: PHP_In_Upload
validate-mime:
check: Validate_Mime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you include a test for this check please?

'wdp' => array( 'image/vnd.ms-photo' ),
'web' => array( 'application/vnd.xara' ),
'weba' => array( 'audio/webm' ),
'webapp' => array( 'application/x-web-app-manifest+j
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't need to happen in this PR, but we should make sure the uploads directory is only iterated once for all checks, not once for each check.

See #121

Copy link
Member

@schlessera schlessera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too keen on having a large list of MIME types that we need to update and maintain over time.

I have created a Composer plugin that pulls down the list of MIME types from the Apache HTTP Server source files and parses them so you can use them in PHP.

You can find the package here: https://github.com/brightnucleus/mime-types

This way, the list of MIME types will keep itself up-to-date.

command.php Outdated
@@ -4,6 +4,8 @@
return;
}

require 'vendor/autoload.php';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to check for the existence of this file first, because the folder will not exist if the package is used as a dependency, not a root package:

$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $autoload ) ) {
	require_once $autoload;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies. I made the necessary changes.

@Sidsector9
Copy link
Member Author

@schlessera Builds are failing because

[ErrorException]                                                                                                                                     
  array_filter() expects parameter 2 to be a valid callback, cannot access protected method BrightNucleus\MimeTypes\MimeTypesPlugin::filterComments()

Not sure why it's unable to access protected method under the same class?

V0.2.0+ changes the generation code to get rid of static access to protected methods, as this seems to cause issues with Travis.

See wp-cli#120 (comment)
@schlessera
Copy link
Member

@Sidsector9 I don't understand either what the issue is. The code was tested and working, and there's no reason that I can see why it shouldn't work.

Regardless, I pushed a new version of the package that restructures the code to get rid of these protected calls, and bump the required version in your PR. Let's see how that goes...

@schlessera schlessera added this to the 0.2.0 milestone Oct 2, 2017
@schlessera schlessera merged commit 91eab40 into wp-cli:master Oct 2, 2017
@schlessera schlessera changed the title GH#88 Added feature to validate MIME type against extensions Validate MIME type against extensions Oct 2, 2017
schlessera added a commit that referenced this pull request Jan 6, 2022
V0.2.0+ changes the generation code to get rid of static access to protected methods, as this seems to cause issues with Travis.

See #120 (comment)
schlessera added a commit that referenced this pull request Jan 6, 2022
GH#88 Added feature to validate MIME type against extensions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants