Changeset 9327

Show
Ignore:
Timestamp:
03/23/07 19:50:17 (1 year ago)
Author:
gallir
Message:

Version 2.1.1 Security fix.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wp-cache/tags/release-2.1.1/wp-cache.php

    r7747 r9327  
    44Plugin URI: http://mnm.uib.es/gallir/wp-cache-2/ 
    55Description: Very fast cache module. It's composed of several modules, this plugin can configure and manage the whole system. Once enabled, go to "Options" and select "WP-Cache". 
    6 Version: 2.1 
     6Version: 2.1.1 
    77Author: Ricardo Galli Granada 
    88Author URI: http://mnm.uib.es/gallir/ 
     
    2626 
    2727/* Changelog 
     28      2007-03-23 
     29            - Version 2.1.1: Patch from Alex Concha: add control in admin pages to avoid  
     30                            possible XSS derived from CSRF attacks, if the users store 
     31                                    the form with the "injected" bad values. 
    2832      2007-01-31 
    2933            - Version 2.1: modified and tested with WP 2.1, WP 2.0, WP 1.5 and PHP 4.3 and PHP 5.2. 
     
    174178 
    175179function wp_cache_manager() { 
    176       global $wp_cache_config_file; 
    177  
     180      global $wp_cache_config_file, $valid_nonce; 
     181 
     182      $valid_nonce = wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache'); 
     183       
    178184      echo '<div class="wrap">'; 
    179185      echo "<h2>WP-Cache Manager</h2>\n"; 
    180       if(isset($_REQUEST['wp_restore_config'])) { 
     186      if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) { 
    181187            unlink($wp_cache_config_file); 
    182188            echo '<strong>Configuration file changed, some values might be wrong. Load the page again from the "Options" menu to reset them.</strong>'; 
     
    197203      } 
    198204 
    199       if(isset($_REQUEST['wp_enable'])) { 
    200             wp_cache_enable(); 
    201       } elseif (isset($_REQUEST['wp_disable'])) { 
    202             wp_cache_disable(); 
     205      if ( $valid_nonce ) { 
     206            if(isset($_REQUEST['wp_enable'])) { 
     207                  wp_cache_enable(); 
     208            } elseif (isset($_REQUEST['wp_disable'])) { 
     209                  wp_cache_disable(); 
     210            } 
    203211      } 
    204212 
     
    213221            echo '<div class="submit"><input type="submit" value="Enable it" /></div>'; 
    214222      } 
     223      wp_nonce_field('wp-cache'); 
    215224      echo "</form>\n"; 
    216225 
     
    239248      echo '<input type="hidden" name="wp_restore_config" />'; 
    240249      echo '<div class="submit"><input type="submit" id="deletepost" value="Restore default configuration" /></div>'; 
     250      wp_nonce_field('wp-cache'); 
    241251      echo "</form>\n"; 
    242252      echo '</fieldset>'; 
     
    245255 
    246256function wp_cache_edit_max_time () { 
    247       global $cache_max_time, $wp_cache_config_file
    248  
    249       if(isset($_REQUEST['wp_max_time'])) { 
     257      global $cache_max_time, $wp_cache_config_file, $valid_nonce
     258 
     259      if(isset($_REQUEST['wp_max_time']) && $valid_nonce) { 
    250260            $max_time = (int)$_REQUEST['wp_max_time']; 
    251261            if ($max_time > 0) { 
     
    258268      echo "<input type=\"text\" name=\"wp_max_time\" value=\"$cache_max_time\" />"; 
    259269      echo '<div class="submit"><input type="submit" value="Change expiration" /></div>'; 
    260       echo "</form>\n"; 
    261  
    262  
     270      wp_nonce_field('wp-cache'); 
     271      echo "</form>\n"; 
     272 
     273 
     274
     275 
     276function wp_cache_sanitize_value($text, & $array) { 
     277      $text = wp_specialchars(strip_tags($text)); 
     278      $array = preg_split("/[\s,]+/", chop($text)); 
     279      $text = var_export($array, true); 
     280      $text = preg_replace('/[\s]+/', ' ', $text); 
     281      return $text; 
    263282} 
    264283 
    265284function wp_cache_edit_rejected_ua() { 
    266       global $cache_rejected_user_agent, $wp_cache_config_file
     285      global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce
    267286 
    268287      if (!function_exists('apache_request_headers')) return; 
    269288 
    270       if(isset($_REQUEST['wp_rejected_user_agent'])) { 
    271             $array = preg_split("/[\s,]+/", chop($_REQUEST['wp_rejected_user_agent'])); 
    272             $text = var_export($array, true); 
    273             $text = preg_replace('/[\s]+/', ' ', $text); 
     289      if(isset($_REQUEST['wp_rejected_user_agent']) && $valid_nonce) { 
     290            $text = wp_cache_sanitize_value($_REQUEST['wp_rejected_user_agent'], $cache_rejected_user_agent); 
    274291            wp_cache_replace_line('^ *\$cache_rejected_user_agent', "\$cache_rejected_user_agent = $text;", $wp_cache_config_file); 
    275             $cache_rejected_user_agent = $array; 
    276292      } 
    277293 
     
    285301      echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 70%; font-size: 12px;" class="code">'; 
    286302      foreach ($cache_rejected_user_agent as $ua) { 
    287             echo "$ua\n"; 
     303            echo wp_specialchars($ua) . "\n"; 
    288304      } 
    289305      echo '</textarea> '; 
    290306      echo '<div class="submit"><input type="submit" value="Save UA strings" /></div>'; 
     307      wp_nonce_field('wp-cache'); 
    291308      echo '</form>'; 
    292309      echo "</fieldset>\n"; 
     
    295312 
    296313function wp_cache_edit_rejected() { 
    297       global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file; 
    298  
    299       if(isset($_REQUEST['wp_rejected_uri'])) { 
    300             $array = preg_split("/[\s,]+/", chop($_REQUEST['wp_rejected_uri'])); 
    301             $text = var_export($array, true); 
    302             $text = preg_replace('/[\s]+/', ' ', $text); 
     314      global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce; 
     315 
     316      if(isset($_REQUEST['wp_rejected_uri']) && $valid_nonce) { 
     317            $text = wp_cache_sanitize_value($_REQUEST['wp_rejected_uri'], $cache_rejected_uri); 
    303318            wp_cache_replace_line('^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file); 
    304             $cache_rejected_uri = $array; 
    305319      } 
    306320 
     
    311325      echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 70%; font-size: 12px;" class="code">'; 
    312326      foreach ($cache_rejected_uri as $file) { 
    313             echo "$file\n"; 
     327            echo wp_specialchars($file) . "\n"; 
    314328      } 
    315329      echo '</textarea> '; 
    316330      echo '<div class="submit"><input type="submit" value="Save strings" /></div>'; 
     331      wp_nonce_field('wp-cache'); 
    317332      echo "</form>\n"; 
    318333} 
    319334 
    320335function wp_cache_edit_accepted() { 
    321       global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file; 
    322  
    323       if(isset($_REQUEST['wp_accepted_files'])) { 
    324             $array = preg_split("/[\s,]+/", chop($_REQUEST['wp_accepted_files'])); 
    325             $text = var_export($array, true); 
    326             $text = preg_replace('/[\s]+/', ' ', $text); 
     336      global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce; 
     337 
     338      if(isset($_REQUEST['wp_accepted_files']) && $valid_nonce) { 
     339            $text = wp_cache_sanitize_value($_REQUEST['wp_accepted_files'], $cache_acceptable_files); 
    327340            wp_cache_replace_line('^ *\$cache_acceptable_files', "\$cache_acceptable_files = $text;", $wp_cache_config_file); 
    328             $cache_acceptable_files = $array; 
    329341      } 
    330342 
     
    335347      echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 70%; font-size: 12px;" class="code">'; 
    336348      foreach ($cache_acceptable_files as $file) { 
    337             echo "$file\n"; 
     349            echo wp_specialchars($file) . "\n"; 
    338350      } 
    339351      echo '</textarea> '; 
    340352      echo '<div class="submit"><input type="submit" value="Save files" /></div>'; 
     353      wp_nonce_field('wp-cache'); 
    341354      echo "</form>\n"; 
    342355} 
     
    504517 
    505518function wp_cache_files() { 
    506       global $cache_path, $file_prefix, $cache_max_time
     519      global $cache_path, $file_prefix, $cache_max_time, $valid_nonce
    507520 
    508521      if ( '/' != substr($cache_path, -1)) { 
     
    510523      } 
    511524 
    512  
    513       if(isset($_REQUEST['wp_delete_cache'])) { 
    514             wp_cache_clean_cache($file_prefix); 
    515       } 
    516       if(isset($_REQUEST['wp_delete_cache_file'])) { 
    517             wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']); 
    518       } 
    519       if(isset($_REQUEST['wp_delete_expired'])) { 
    520             wp_cache_clean_expired($file_prefix); 
     525      if ( $valid_nonce ) { 
     526            if(isset($_REQUEST['wp_delete_cache'])) { 
     527                  wp_cache_clean_cache($file_prefix); 
     528            } 
     529            if(isset($_REQUEST['wp_delete_cache_file'])) { 
     530                  wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']); 
     531            } 
     532            if(isset($_REQUEST['wp_delete_expired'])) { 
     533                  wp_cache_clean_expired($file_prefix); 
     534            } 
    521535      } 
    522536      if(isset($_REQUEST['wp_list_cache'])) { 
     
    565579                              echo '<input type="hidden" name="wp_delete_cache_file" value="'.preg_replace("/^(.*)\.meta$/", "$1", $file).'" />'; 
    566580                              echo '<div class="submit"><input id="deletepost" type="submit" value="Remove" /></div>'; 
     581                              wp_nonce_field('wp-cache'); 
    567582                              echo "</form></td></tr>\n"; 
    568583                        } 
     
    579594      echo '<input type="hidden" name="wp_list_cache" />'; 
    580595      echo '<div class="submit"><input type="submit" value="Delete expired" /></div>'; 
     596      wp_nonce_field('wp-cache'); 
    581597      echo "</form>\n"; 
    582598 
     
    585601      echo '<input type="hidden" name="wp_delete_cache" />'; 
    586602      echo '<div class="submit"><input id="deletepost" type="submit" value="Delete cache" /></div>'; 
     603      wp_nonce_field('wp-cache'); 
    587604      echo "</form>\n"; 
    588605 
  • wp-cache/trunk/wp-cache.php

    r7747 r9327  
    44Plugin URI: http://mnm.uib.es/gallir/wp-cache-2/ 
    55Description: Very fast cache module. It's composed of several modules, this plugin can configure and manage the whole system. Once enabled, go to "Options" and select "WP-Cache". 
    6 Version: 2.1 
     6Version: 2.1.1 
    77Author: Ricardo Galli Granada 
    88Author URI: http://mnm.uib.es/gallir/ 
     
    2626 
    2727/* Changelog 
     28      2007-03-23 
     29            - Version 2.1.1: Patch from Alex Concha: add control in admin pages to avoid  
     30                            possible XSS derived from CSRF attacks, if the users store 
     31                                    the form with the "injected" bad values. 
    2832      2007-01-31 
    2933            - Version 2.1: modified and tested with WP 2.1, WP 2.0, WP 1.5 and PHP 4.3 and PHP 5.2. 
     
    174178 
    175179function wp_cache_manager() { 
    176       global $wp_cache_config_file; 
    177  
     180      global $wp_cache_config_file, $valid_nonce; 
     181 
     182      $valid_nonce = wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache'); 
     183       
    178184      echo '<div class="wrap">'; 
    179185      echo "<h2>WP-Cache Manager</h2>\n"; 
    180       if(isset($_REQUEST['wp_restore_config'])) { 
     186      if(isset($_REQUEST['wp_restore_config']) && $valid_nonce) { 
    181187            unlink($wp_cache_config_file); 
    182188            echo '<strong>Configuration file changed, some values might be wrong. Load the page again from the "Options" menu to reset them.</strong>'; 
     
    197203      } 
    198204 
    199       if(isset($_REQUEST['wp_enable'])) { 
    200             wp_cache_enable(); 
    201       } elseif (isset($_REQUEST['wp_disable'])) { 
    202             wp_cache_disable(); 
     205      if ( $valid_nonce ) { 
     206            if(isset($_REQUEST['wp_enable'])) { 
     207                  wp_cache_enable(); 
     208            } elseif (isset($_REQUEST['wp_disable'])) { 
     209                  wp_cache_disable(); 
     210            } 
    203211      } 
    204212 
     
    213221            echo '<div class="submit"><input type="submit" value="Enable it" /></div>'; 
    214222      } 
     223      wp_nonce_field('wp-cache'); 
    215224      echo "</form>\n"; 
    216225 
     
    239248      echo '<input type="hidden" name="wp_restore_config" />'; 
    240249      echo '<div class="submit"><input type="submit" id="deletepost" value="Restore default configuration" /></div>'; 
     250      wp_nonce_field('wp-cache'); 
    241251      echo "</form>\n"; 
    242252      echo '</fieldset>'; 
     
    245255 
    246256function wp_cache_edit_max_time () { 
    247       global $cache_max_time, $wp_cache_config_file
    248  
    249       if(isset($_REQUEST['wp_max_time'])) { 
     257      global $cache_max_time, $wp_cache_config_file, $valid_nonce
     258 
     259      if(isset($_REQUEST['wp_max_time']) && $valid_nonce) { 
    250260            $max_time = (int)$_REQUEST['wp_max_time']; 
    251261            if ($max_time > 0) { 
     
    258268      echo "<input type=\"text\" name=\"wp_max_time\" value=\"$cache_max_time\" />"; 
    259269      echo '<div class="submit"><input type="submit" value="Change expiration" /></div>'; 
    260       echo "</form>\n"; 
    261  
    262  
     270      wp_nonce_field('wp-cache'); 
     271      echo "</form>\n"; 
     272 
     273 
     274
     275 
     276function wp_cache_sanitize_value($text, & $array) { 
     277      $text = wp_specialchars(strip_tags($text)); 
     278      $array = preg_split("/[\s,]+/", chop($text)); 
     279      $text = var_export($array, true); 
     280      $text = preg_replace('/[\s]+/', ' ', $text); 
     281      return $text; 
    263282} 
    264283 
    265284function wp_cache_edit_rejected_ua() { 
    266       global $cache_rejected_user_agent, $wp_cache_config_file
     285      global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce
    267286 
    268287      if (!function_exists('apache_request_headers')) return; 
    269288 
    270       if(isset($_REQUEST['wp_rejected_user_agent'])) { 
    271             $array = preg_split("/[\s,]+/", chop($_REQUEST['wp_rejected_user_agent'])); 
    272             $text = var_export($array, true); 
    273             $text = preg_replace('/[\s]+/', ' ', $text); 
     289      if(isset($_REQUEST['wp_rejected_user_agent']) && $valid_nonce) { 
     290            $text = wp_cache_sanitize_value($_REQUEST['wp_rejected_user_agent'], $cache_rejected_user_agent); 
    274291            wp_cache_replace_line('^ *\$cache_rejected_user_agent', "\$cache_rejected_user_agent = $text;", $wp_cache_config_file); 
    275             $cache_rejected_user_agent = $array; 
    276292      } 
    277293 
     
    285301      echo '<textarea name="wp_rejected_user_agent" cols="40" rows="4" style="width: 70%; font-size: 12px;" class="code">'; 
    286302      foreach ($cache_rejected_user_agent as $ua) { 
    287             echo "$ua\n"; 
     303            echo wp_specialchars($ua) . "\n"; 
    288304      } 
    289305      echo '</textarea> '; 
    290306      echo '<div class="submit"><input type="submit" value="Save UA strings" /></div>'; 
     307      wp_nonce_field('wp-cache'); 
    291308      echo '</form>'; 
    292309      echo "</fieldset>\n"; 
     
    295312 
    296313function wp_cache_edit_rejected() { 
    297       global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file; 
    298  
    299       if(isset($_REQUEST['wp_rejected_uri'])) { 
    300             $array = preg_split("/[\s,]+/", chop($_REQUEST['wp_rejected_uri'])); 
    301             $text = var_export($array, true); 
    302             $text = preg_replace('/[\s]+/', ' ', $text); 
     314      global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce; 
     315 
     316      if(isset($_REQUEST['wp_rejected_uri']) && $valid_nonce) { 
     317            $text = wp_cache_sanitize_value($_REQUEST['wp_rejected_uri'], $cache_rejected_uri); 
    303318            wp_cache_replace_line('^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file); 
    304             $cache_rejected_uri = $array; 
    305319      } 
    306320 
     
    311325      echo '<textarea name="wp_rejected_uri" cols="40" rows="4" style="width: 70%; font-size: 12px;" class="code">'; 
    312326      foreach ($cache_rejected_uri as $file) { 
    313             echo "$file\n"; 
     327            echo wp_specialchars($file) . "\n"; 
    314328      } 
    315329      echo '</textarea> '; 
    316330      echo '<div class="submit"><input type="submit" value="Save strings" /></div>'; 
     331      wp_nonce_field('wp-cache'); 
    317332      echo "</form>\n"; 
    318333} 
    319334 
    320335function wp_cache_edit_accepted() { 
    321       global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file; 
    322  
    323       if(isset($_REQUEST['wp_accepted_files'])) { 
    324             $array = preg_split("/[\s,]+/", chop($_REQUEST['wp_accepted_files'])); 
    325             $text = var_export($array, true); 
    326             $text = preg_replace('/[\s]+/', ' ', $text); 
     336      global $cache_acceptable_files, $cache_rejected_uri, $wp_cache_config_file, $valid_nonce; 
     337 
     338      if(isset($_REQUEST['wp_accepted_files']) && $valid_nonce) { 
     339            $text = wp_cache_sanitize_value($_REQUEST['wp_accepted_files'], $cache_acceptable_files); 
    327340            wp_cache_replace_line('^ *\$cache_acceptable_files', "\$cache_acceptable_files = $text;", $wp_cache_config_file); 
    328             $cache_acceptable_files = $array; 
    329341      } 
    330342 
     
    335347      echo '<textarea name="wp_accepted_files" cols="40" rows="8" style="width: 70%; font-size: 12px;" class="code">'; 
    336348      foreach ($cache_acceptable_files as $file) { 
    337             echo "$file\n"; 
     349            echo wp_specialchars($file) . "\n"; 
    338350      } 
    339351      echo '</textarea> '; 
    340352      echo '<div class="submit"><input type="submit" value="Save files" /></div>'; 
     353      wp_nonce_field('wp-cache'); 
    341354      echo "</form>\n"; 
    342355} 
     
    504517 
    505518function wp_cache_files() { 
    506       global $cache_path, $file_prefix, $cache_max_time
     519      global $cache_path, $file_prefix, $cache_max_time, $valid_nonce
    507520 
    508521      if ( '/' != substr($cache_path, -1)) { 
     
    510523      } 
    511524 
    512  
    513       if(isset($_REQUEST['wp_delete_cache'])) { 
    514             wp_cache_clean_cache($file_prefix); 
    515       } 
    516       if(isset($_REQUEST['wp_delete_cache_file'])) { 
    517             wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']); 
    518       } 
    519       if(isset($_REQUEST['wp_delete_expired'])) { 
    520             wp_cache_clean_expired($file_prefix); 
     525      if ( $valid_nonce ) { 
     526            if(isset($_REQUEST['wp_delete_cache'])) { 
     527                  wp_cache_clean_cache($file_prefix); 
     528            } 
     529            if(isset($_REQUEST['wp_delete_cache_file'])) { 
     530                  wp_cache_clean_cache($_REQUEST['wp_delete_cache_file']); 
     531            } 
     532            if(isset($_REQUEST['wp_delete_expired'])) { 
     533                  wp_cache_clean_expired($file_prefix); 
     534            } 
    521535      } 
    522536      if(isset($_REQUEST['wp_list_cache'])) { 
     
    565579                              echo '<input type="hidden" name="wp_delete_cache_file" value="'.preg_replace("/^(.*)\.meta$/", "$1", $file).'" />'; 
    566580                              echo '<div class="submit"><input id="deletepost" type="submit" value="Remove" /></div>'; 
     581                              wp_nonce_field('wp-cache'); 
    567582                              echo "</form></td></tr>\n"; 
    568583                        } 
     
    579594      echo '<input type="hidden" name="wp_list_cache" />'; 
    580595      echo '<div class="submit"><input type="submit" value="Delete expired" /></div>'; 
     596      wp_nonce_field('wp-cache'); 
    581597      echo "</form>\n"; 
    582598 
     
    585601      echo '<input type="hidden" name="wp_delete_cache" />'; 
    586602      echo '<div class="submit"><input id="deletepost" type="submit" value="Delete cache" /></div>'; 
     603      wp_nonce_field('wp-cache'); 
    587604      echo "</form>\n"; 
    588605