Making WordPress.org

Changeset 13135


Ignore:
Timestamp:
01/22/2024 05:16:48 AM (15 months ago)
Author:
dd32
Message:

Plugin Directory: Upload: Reject submissions containing unexpected / invalid directories and file types.

Fixes #7415.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php

    r13132 r13135  
    101101            $this->plugin      = $plugin_data;
    102102            $this->plugin_root = dirname( $plugin_data['PluginFile'] );
     103        }
     104
     105        /*
     106         * Validate the contents of the ZIP seems reasonable.
     107         *
     108         * We don't want Version Control direcories, or compressed/executable files.
     109         */
     110        $unexpected_files = array_merge(
     111            Filesystem::list( $this->plugin_dir, 'directories', true, '!/\.(git|svn|hg|bzr)$!i' ),
     112            Filesystem::list( $this->plugin_dir, 'files', true, '!\.(phar|sh|zip|gz|tgz|rar|tar|7z)$!i' )
     113        );
     114
     115        if ( $unexpected_files ) {
     116            $unexpected_files = array_map( 'basename', $unexpected_files );
     117
     118            $error = __( 'Error: The plugin contains unexpected files.', 'wporg-plugins' );
     119            return new WP_Error( 'unexpected_files', $error . ' ' . sprintf(
     120                /* translators: %s: Filenames */
     121                __( 'The following files are not permitted in plugins: %s. Please remove them and upload the plugin again.', 'wporg-plugins' ),
     122                '<code>' . implode( '</code>, <code>', $unexpected_files ) . '</code>'
     123            ) );
    103124        }
    104125
Note: See TracChangeset for help on using the changeset viewer.