Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/codepeople-post-map/codepeople-post-map.php
+++ b/codepeople-post-map/codepeople-post-map.php
@@ -2,7 +2,7 @@
/*
Plugin Name: CodePeople Post Map for Google Maps
Text Domain: codepeople-post-map
-Version: 1.3.0
+Version: 1.3.1
Author: CodePeople
Author URI: http://wordpress.dwbooster.com/content-tools/codepeople-post-map
Plugin URI: http://wordpress.dwbooster.com/content-tools/codepeople-post-map
@@ -152,11 +152,11 @@
add_menu_page( 'CodePeople Post Map for Google Maps', 'CodePeople Post Map for Google Maps', 'manage_options', $slug, array(&$cpm_master_obj, 'settings_page'), 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiBmaWxsPSJjdXJyZW50Q29sb3IiPg0KICA8cGF0aCBkPSJNMTIgMmMzLjE5NiAwIDYgMi42MTggNiA1LjYwMiAwIDMuMDkzLTIuNDkzIDcuMTMyLTYgMTIuNTkxLTMuNTA3LTUuNDU5LTYtOS40OTgtNi0xMi41OTFDNiA0LjYxOCA4LjgwNCAyIDEyIDJ6bTAgNGEyIDIgMCAxIDAgMCA0IDIgMiAwIDAgMCAwLTR6Ii8+DQo8L3N2Zz4=' );
- add_submenu_page( $slug, 'Online Help', 'Online Help', 'read', 'google_maps_cp_help', array(&$cpm_master_obj, 'settings_page') );
+ add_submenu_page( $slug, 'Online Help', 'Online Help', 'read', 'google_maps_cp_help', array(&$cpm_master_obj, 'help_page') );
- add_submenu_page( $slug, 'I've a Question', 'I've a Question', 'read', 'google_maps_cp_question', array(&$cpm_master_obj, 'settings_page') );
+ add_submenu_page( $slug, 'I've a Question', 'I've a Question', 'read', 'google_maps_cp_question', array(&$cpm_master_obj, 'question_page') );
- add_submenu_page( $slug, 'Upgrade', 'Upgrade', 'read', 'google_maps_cp_upgrade', array(&$cpm_master_obj, 'settings_page') );
+ add_submenu_page( $slug, 'Upgrade', 'Upgrade', 'read', 'google_maps_cp_upgrade', array(&$cpm_master_obj, 'upgrade_page') );
}
}
}
--- a/codepeople-post-map/include/functions.php
+++ b/codepeople-post-map/include/functions.php
@@ -109,6 +109,17 @@
return wp_kses_post( $v );
} // End sanitize_description
+ function sanitize_api_key( $v )
+ {
+ if ( ! is_string( $v ) ) return '';
+ $v = trim( $v );
+ if ( '' === $v ) return '';
+ // Google Maps API keys contain only letters, digits, dashes and underscores.
+ // Removing every other character guarantees the value can never carry
+ // markup into the admin JavaScript.
+ return preg_replace( '/[^A-Za-z0-9_-]/', '', $v );
+ } // End sanitize_api_key
+
//---------- CREATE MAP ----------
/**
@@ -937,7 +948,7 @@
$api_key = $this->get_configuration_option( 'api_key' );
if( !empty( $api_key ) )
{
- $cpm_global[ 'api_key' ] = trim($api_key);
+ $cpm_global[ 'api_key' ] = $this->sanitize_api_key( $api_key );
}
wp_localize_script('admin_cpm_script', 'cpm_global', $cpm_global);
} // End load_admin_resources
@@ -992,34 +1003,37 @@
echo '<style>.cpm-map img{ max-width: none !important;box-shadow:none !important;}</style>';
} // End load_header_resources
+ function help_page(){
+ echo("Redirecting to documentation...<script type='text/javascript'>document.location='http://wordpress.dwbooster.com/content-tools/codepeople-post-map?acode=18517';</script>");
+ exit;
+ }
+
+ function question_page(){
+ echo("Redirecting to documentation...<script type='text/javascript'>document.location='https://wordpress.org/support/plugin/codepeople-post-map/#new-post';</script>");
+ exit;
+ }
+
+ function upgrade_page(){
+ echo("Redirecting to upgrade page...<script type='text/javascript'>document.location='http://wordpress.dwbooster.com/content-tools/codepeople-post-map?acode=18517#download';</script>");
+ exit;
+ }
+
/**
* Print the settings page for entering the general setting's data of maps
*/
function settings_page(){
- if (isset($_GET["page"]))
- {
- if( $_GET["page"] == 'google_maps_cp_upgrade' )
- {
- echo("Redirecting to upgrade page...<script type='text/javascript'>document.location='http://wordpress.dwbooster.com/content-tools/codepeople-post-map?acode=18517#download';</script>");
- exit;
- }
- elseif( $_GET["page"] == 'google_maps_cp_help')
- {
- echo("Redirecting to documentation...<script type='text/javascript'>document.location='http://wordpress.dwbooster.com/content-tools/codepeople-post-map?acode=18517';</script>");
- exit;
- }
- elseif( $_GET["page"] == 'google_maps_cp_question')
- {
- echo("Redirecting to documentation...<script type='text/javascript'>document.location='https://wordpress.org/support/plugin/codepeople-post-map/#new-post';</script>");
- exit;
- }
-
- }
+ if ( ! current_user_can( 'manage_options' ) ){
+ wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'codepeople-post-map'), 403 );
+ }
// Check if post exists and save the configuraton options
- if (isset($_POST['cpm_map_noncename']) && wp_verify_nonce($_POST['cpm_map_noncename'],__FILE__)){
+ if (
+ isset( $_POST['cpm_map_noncename'] ) &&
+ wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cpm_map_noncename'] ) ), __FILE__ )
+ ){
$options = $_POST['cpm_map'];
$options = $this->array_map_recursive('sanitize_text_field', $options);
+ $options['api_key'] = $this->sanitize_api_key( isset($options['api_key']) ? $options['api_key'] : '' );
$options['drag_map'] = ( isset( $options[ 'drag_map' ] ) ) ? true : false;
$options['windowhtml'] = $this->get_configuration_option('windowhtml');
update_option('cpm_config', $options);
@@ -1525,7 +1539,7 @@
$output .= 'var cpm_language = {"lng":' . wp_json_encode( $default_language ) . '};';
$api_key = $this->get_configuration_option( 'api_key' );
- $output .= 'var cpm_api_key = ' . wp_json_encode( (!empty( $api_key )) ? trim($api_key) : '' ) . ";n";
+ $output .= 'var cpm_api_key = ' . wp_json_encode( (!empty( $api_key )) ? $this->sanitize_api_key( $api_key ) : '' ) . ";n";
$output .= "var cpm_global = cpm_global || {};n";
$output .= "cpm_global[" . $map_id_json . "] = {}; n";