Welcome Guest, Not a member yet? Register   Sign In
xss_clean adds semicolon to anything with an &
#19

[eluser]Unknown[/eluser]
Nice one Jerry, works for me. For clarification of the process...

Create a file named MY_Controller.php in your [codeigniter]/application/core folder,

then place the following content into it...

Code:
<?php

/**
* MY_Security Class - extends CI standard Security controller
*
* This update removes the adding of semi-colons to submitted POST
* data if the data contains an ampersand & and the word after the
* ampersand doesn't match a known HTML entity
*
* @package  CodeIgniter
*/
class MY_Security extends CI_Security {

public function __construct()
{
  parent::__construct();
}

/**
  * Validate URL entities
  *
  * Called by xss_clean()
  *
  * @param  string
  * @return  string
  */
protected function _validate_entities($str)
{
  /*
   * Protect GET variables in URLs
   */

   // 901119URL5918AMP18930PROTECT8198

  $str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str);

  /*
   * Validate standard character entities
   *
   * Add a semicolon if missing.  We do this to enable
   * the conversion of entities to ASCII later.
   *
   */
//  $str = preg_replace('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', "\\1;\\2", $str);

  // hArpanet.com: new bit coming up (in place of above line)...
  // this code prevents a ; being added to string after an & unless that string matches a known HTML entity
  // code taken from: http://ellislab.com/forums/viewreply/954778/
  $matched = preg_match_all('#(&\#?[0-9a-z]{2,})([\x00-\x20])*;?#i', $str, $matches, PREG_OFFSET_CAPTURE);
  if ($matched > 0)
  {
   foreach($matches[0] as $match)
   {
    $test_str = strtolower($match[0].';');
    foreach (get_html_translation_table(HTML_ENTITIES) as $entity)
    {
     if ($test_str == strtolower($entity))
     $str = substr_replace($str, $entity, $match[1], strlen($match[0]));
    }
   }
  }
  // hArpanet.com: end of new bit

  /*
   * Validate UTF16 two byte encoding (x00)
   *
   * Just as above, adds a semicolon if missing.
   *
   */
  $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str);

  /*
   * Un-Protect GET variables in URLs
   */
  $str = str_replace($this->xss_hash(), '&', $str);

  return $str;
}

}

NOTE: As you can see, this only updates the checks on non-UTF16 values. If you want to disable ; addition on UTF16 values then apply Jerry's code to that string also.


Messages In This Thread
xss_clean adds semicolon to anything with an & - by El Forum - 07-03-2008, 11:29 AM
xss_clean adds semicolon to anything with an & - by El Forum - 07-03-2008, 12:08 PM
xss_clean adds semicolon to anything with an & - by El Forum - 07-03-2008, 12:11 PM
xss_clean adds semicolon to anything with an & - by El Forum - 07-16-2008, 10:51 AM
xss_clean adds semicolon to anything with an & - by El Forum - 07-16-2008, 11:10 AM
xss_clean adds semicolon to anything with an & - by El Forum - 07-16-2008, 11:31 AM
xss_clean adds semicolon to anything with an & - by El Forum - 07-16-2008, 11:33 AM
xss_clean adds semicolon to anything with an & - by El Forum - 07-16-2008, 11:41 AM
xss_clean adds semicolon to anything with an & - by El Forum - 07-16-2008, 11:59 AM
xss_clean adds semicolon to anything with an & - by El Forum - 07-16-2008, 12:27 PM
xss_clean adds semicolon to anything with an & - by El Forum - 09-03-2008, 01:22 PM
xss_clean adds semicolon to anything with an & - by El Forum - 09-03-2008, 01:46 PM
xss_clean adds semicolon to anything with an & - by El Forum - 09-04-2008, 07:17 AM
xss_clean adds semicolon to anything with an & - by El Forum - 09-04-2008, 07:24 AM
xss_clean adds semicolon to anything with an & - by El Forum - 09-04-2008, 07:29 AM
xss_clean adds semicolon to anything with an & - by El Forum - 09-05-2008, 02:52 AM
xss_clean adds semicolon to anything with an & - by El Forum - 09-05-2008, 08:41 AM
xss_clean adds semicolon to anything with an & - by El Forum - 05-27-2010, 03:30 PM
xss_clean adds semicolon to anything with an & - by El Forum - 11-06-2012, 03:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB