Skip to content

Commit

Permalink
Uploads: Check for and verify ZIP archives.
Browse files Browse the repository at this point in the history
Props costdev, peterwilsoncc, azaozz, tykoted, johnbillion, desrosj, afragen, jorbin.


git-svn-id: https://develop.svn.wordpress.org/trunk@57388 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
aaronjorbin committed Jan 30, 2024
1 parent 3e92635 commit 9573b33
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/wp-admin/includes/class-file-upload-upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ public function __construct( $form, $urlholder ) {
wp_die( $file['error'] );
}

if ( 'pluginzip' === $form || 'themezip' === $form ) {
$archive_is_valid = false;

/** This filter is documented in wp-admin/includes/file.php */
if ( class_exists( 'ZipArchive', false ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) {
$archive = new ZipArchive();
$archive_is_valid = $archive->open( $file['file'], ZIPARCHIVE::CHECKCONS );

if ( true === $archive_is_valid ) {
$archive->close();
}
} else {
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';

$archive = new PclZip( $file['file'] );
$archive_is_valid = is_array( $archive->properties() );
}

if ( true !== $archive_is_valid ) {
wp_delete_file( $file['file'] );
wp_die( __( 'Incompatible Archive.' ) );
}
}

$this->filename = $_FILES[ $form ]['name'];
$this->package = $file['file'];

Expand Down
8 changes: 8 additions & 0 deletions src/wp-admin/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@

check_admin_referer( 'plugin-upload' );

if ( isset( $_FILES['pluginzip']['name'] ) && ! str_ends_with( strtolower( $_FILES['pluginzip']['name'] ), '.zip' ) ) {
wp_die( __( 'Only .zip archives may be uploaded.' ) );
}

$file_upload = new File_Upload_Upgrader( 'pluginzip', 'package' );

// Used in the HTML title tag.
Expand Down Expand Up @@ -302,6 +306,10 @@

check_admin_referer( 'theme-upload' );

if ( isset( $_FILES['themezip']['name'] ) && ! str_ends_with( strtolower( $_FILES['themezip']['name'] ), '.zip' ) ) {
wp_die( __( 'Only .zip archives may be uploaded.' ) );
}

$file_upload = new File_Upload_Upgrader( 'themezip', 'package' );

// Used in the HTML title tag.
Expand Down

0 comments on commit 9573b33

Please sign in to comment.