1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
\r
5 * An open source application development framework for PHP 4.3.2 or newer
\r
7 * @package CodeIgniter
\r
8 * @author ExpressionEngine Dev Team
\r
9 * @copyright Copyright (c) 2008, EllisLab, Inc.
\r
10 * @license http://codeigniter.com/user_guide/license.html
\r
11 * @link http://codeigniter.com
\r
12 * @since Version 1.0
\r
16 // ------------------------------------------------------------------------
\r
21 * Pre-processes global input data for security
\r
23 * @package CodeIgniter
\r
24 * @subpackage Libraries
\r
26 * @author ExpressionEngine Dev Team
\r
27 * @link http://codeigniter.com/user_guide/libraries/input.html
\r
30 var $use_xss_clean = FALSE;
\r
32 var $ip_address = FALSE;
\r
33 var $user_agent = FALSE;
\r
34 var $allow_get_array = FALSE;
\r
36 /* never allowed, string replacement */
\r
37 var $never_allowed_str = array(
\r
38 'document.cookie' => '[removed]',
\r
39 'document.write' => '[removed]',
\r
40 '.parentNode' => '[removed]',
\r
41 '.innerHTML' => '[removed]',
\r
42 'window.location' => '[removed]',
\r
43 '-moz-binding' => '[removed]',
\r
44 '<!--' => '<!--',
\r
46 '<![CDATA[' => '<![CDATA['
\r
48 /* never allowed, regex replacement */
\r
49 var $never_allowed_regex = array(
\r
50 "javascript\s*:" => '[removed]',
\r
51 "expression\s*\(" => '[removed]', // CSS and IE
\r
52 "Redirect\s+302" => '[removed]'
\r
58 * Sets whether to globally enable the XSS processing
\r
59 * and whether to allow the $_GET array
\r
65 log_message('debug', "Input Class Initialized");
\r
67 $CFG =& load_class('Config');
\r
68 $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE;
\r
69 $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE;
\r
70 $this->_sanitize_globals();
\r
73 // --------------------------------------------------------------------
\r
78 * This function does the following:
\r
80 * Unsets $_GET data (if query strings are not enabled)
\r
82 * Unsets all globals if register_globals is enabled
\r
84 * Standardizes newline characters to \n
\r
89 function _sanitize_globals()
\r
91 // Would kind of be "wrong" to unset any of these GLOBALS
\r
92 $protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA',
\r
93 'system_folder', 'application_folder', 'BM', 'EXT', 'CFG', 'URI', 'RTR', 'OUT', 'IN');
\r
95 // Unset globals for security.
\r
96 // This is effectively the same as register_globals = off
\r
97 foreach (array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION) && is_array($_SESSION)) ? $_SESSION : array()) as $global)
\r
99 if ( ! is_array($global))
\r
101 if ( ! in_array($global, $protected))
\r
103 unset($GLOBALS[$global]);
\r
108 foreach ($global as $key => $val)
\r
110 if ( ! in_array($key, $protected))
\r
112 unset($GLOBALS[$key]);
\r
115 if (is_array($val))
\r
117 foreach($val as $k => $v)
\r
119 if ( ! in_array($k, $protected))
\r
121 unset($GLOBALS[$k]);
\r
129 // Is $_GET data allowed? If not we'll set the $_GET to an empty array
\r
130 if ($this->allow_get_array == FALSE)
\r
136 $_GET = $this->_clean_input_data($_GET);
\r
139 // Clean $_POST Data
\r
140 $_POST = $this->_clean_input_data($_POST);
\r
142 // Clean $_COOKIE Data
\r
143 // Also get rid of specially treated cookies that might be set by a server
\r
144 // or silly application, that are of no use to a CI application anyway
\r
145 // but that when present will trip our 'Disallowed Key Characters' alarm
\r
146 // http://www.ietf.org/rfc/rfc2109.txt
\r
147 // note that the key names below are single quoted strings, and are not PHP variables
\r
148 unset($_COOKIE['$Version']);
\r
149 unset($_COOKIE['$Path']);
\r
150 unset($_COOKIE['$Domain']);
\r
151 $_COOKIE = $this->_clean_input_data($_COOKIE);
\r
153 log_message('debug', "Global POST and COOKIE data sanitized");
\r
156 // --------------------------------------------------------------------
\r
161 * This is a helper function. It escapes data and
\r
162 * standardizes newline characters to \n
\r
168 function _clean_input_data($str)
\r
170 if (is_array($str))
\r
172 $new_array = array();
\r
173 foreach ($str as $key => $val)
\r
175 $new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
\r
180 // We strip slashes if magic quotes is on to keep things consistent
\r
181 if (get_magic_quotes_gpc())
\r
183 $str = stripslashes($str);
\r
186 // Should we filter the input data?
\r
187 if ($this->use_xss_clean === TRUE)
\r
189 $str = $this->xss_clean($str);
\r
192 // Standardize newlines
\r
193 if (strpos($str, "\r") !== FALSE)
\r
195 $str = str_replace(array("\r\n", "\r"), "\n", $str);
\r
201 // --------------------------------------------------------------------
\r
206 * This is a helper function. To prevent malicious users
\r
207 * from trying to exploit keys we make sure that keys are
\r
208 * only named with alpha-numeric text and a few other items.
\r
214 function _clean_input_keys($str)
\r
216 if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
\r
218 exit('Disallowed Key Characters.');
\r
224 // --------------------------------------------------------------------
\r
229 * This is a helper function to retrieve values from global arrays
\r
237 function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
\r
239 if ( ! isset($array[$index]))
\r
244 if ($xss_clean === TRUE)
\r
246 return $this->xss_clean($array[$index]);
\r
249 return $array[$index];
\r
252 // --------------------------------------------------------------------
\r
255 * Fetch an item from the GET array
\r
262 function get($index = '', $xss_clean = FALSE)
\r
264 return $this->_fetch_from_array($_GET, $index, $xss_clean);
\r
267 // --------------------------------------------------------------------
\r
270 * Fetch an item from the POST array
\r
277 function post($index = '', $xss_clean = FALSE)
\r
279 return $this->_fetch_from_array($_POST, $index, $xss_clean);
\r
282 // --------------------------------------------------------------------
\r
285 * Fetch an item from either the GET array or the POST
\r
288 * @param string The index key
\r
289 * @param bool XSS cleaning
\r
292 function get_post($index = '', $xss_clean = FALSE)
\r
294 if ( ! isset($_POST[$index]) )
\r
296 return $this->get($index, $xss_clean);
\r
300 return $this->post($index, $xss_clean);
\r
304 // --------------------------------------------------------------------
\r
307 * Fetch an item from the COOKIE array
\r
314 function cookie($index = '', $xss_clean = FALSE)
\r
316 return $this->_fetch_from_array($_COOKIE, $index, $xss_clean);
\r
319 // --------------------------------------------------------------------
\r
322 * Fetch an item from the SERVER array
\r
329 function server($index = '', $xss_clean = FALSE)
\r
331 return $this->_fetch_from_array($_SERVER, $index, $xss_clean);
\r
334 // --------------------------------------------------------------------
\r
337 * Fetch the IP Address
\r
342 function ip_address()
\r
344 if ($this->ip_address !== FALSE)
\r
346 return $this->ip_address;
\r
349 if ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP'))
\r
351 $this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
\r
353 elseif ($this->server('REMOTE_ADDR'))
\r
355 $this->ip_address = $_SERVER['REMOTE_ADDR'];
\r
357 elseif ($this->server('HTTP_CLIENT_IP'))
\r
359 $this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
\r
361 elseif ($this->server('HTTP_X_FORWARDED_FOR'))
\r
363 $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
\r
366 if ($this->ip_address === FALSE)
\r
368 $this->ip_address = '0.0.0.0';
\r
369 return $this->ip_address;
\r
372 if (strstr($this->ip_address, ','))
\r
374 $x = explode(',', $this->ip_address);
\r
375 $this->ip_address = end($x);
\r
378 if ( ! $this->valid_ip($this->ip_address))
\r
380 $this->ip_address = '0.0.0.0';
\r
383 return $this->ip_address;
\r
386 // --------------------------------------------------------------------
\r
389 * Validate IP Address
\r
391 * Updated version suggested by Geert De Deckere
\r
397 function valid_ip($ip)
\r
399 $ip_segments = explode('.', $ip);
\r
401 // Always 4 segments needed
\r
402 if (count($ip_segments) != 4)
\r
406 // IP can not start with 0
\r
407 if ($ip_segments[0][0] == '0')
\r
411 // Check each segment
\r
412 foreach ($ip_segments as $segment)
\r
414 // IP segments must be digits and can not be
\r
415 // longer than 3 digits or greater then 255
\r
416 if ($segment == '' OR preg_match("/[^0-9]/", $segment) OR $segment > 255 OR strlen($segment) > 3)
\r
425 // --------------------------------------------------------------------
\r
433 function user_agent()
\r
435 if ($this->user_agent !== FALSE)
\r
437 return $this->user_agent;
\r
440 $this->user_agent = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT'];
\r
442 return $this->user_agent;
\r
445 // --------------------------------------------------------------------
\r
448 * Filename Security
\r
454 function filename_security($str)
\r
491 return stripslashes(str_replace($bad, '', $str));
\r
494 // --------------------------------------------------------------------
\r
499 * Sanitizes data so that Cross Site Scripting Hacks can be
\r
500 * prevented. This function does a fair amount of work but
\r
501 * it is extremely thorough, designed to prevent even the
\r
502 * most obscure XSS attempts. Nothing is ever 100% foolproof,
\r
503 * of course, but I haven't been able to get anything passed
\r
506 * Note: This function should only be used to deal with data
\r
507 * upon submission. It's not something that should
\r
508 * be used for general runtime processing.
\r
510 * This function was based in part on some code and ideas I
\r
511 * got from Bitflux: http://blog.bitflux.ch/wiki/XSS_Prevention
\r
513 * To help develop this script I used this great list of
\r
514 * vulnerabilities along with a few other hacks I've
\r
515 * harvested from examining vulnerabilities in other programs:
\r
516 * http://ha.ckers.org/xss.html
\r
522 function xss_clean($str, $is_image = FALSE)
\r
525 * Is the string an array?
\r
528 if (is_array($str))
\r
530 while (list($key) = each($str))
\r
532 $str[$key] = $this->xss_clean($str[$key]);
\r
539 * Remove Invisible Characters
\r
541 $str = $this->_remove_invisible_characters($str);
\r
544 * Protect GET variables in URLs
\r
547 // 901119URL5918AMP18930PROTECT8198
\r
549 $str = preg_replace('|\&([a-z\_0-9]+)\=([a-z\_0-9]+)|i', $this->xss_hash()."\\1=\\2", $str);
\r
552 * Validate standard character entities
\r
554 * Add a semicolon if missing. We do this to enable
\r
555 * the conversion of entities to ASCII later.
\r
558 $str = preg_replace('#(&\#?[0-9a-z]{2,})[\x00-\x20]*;?#i', "\\1;", $str);
\r
561 * Validate UTF16 two byte encoding (x00)
\r
563 * Just as above, adds a semicolon if missing.
\r
566 $str = preg_replace('#(&\#x?)([0-9A-F]+);?#i',"\\1\\2;",$str);
\r
569 * Un-Protect GET variables in URLs
\r
571 $str = str_replace($this->xss_hash(), '&', $str);
\r
576 * Just in case stuff like this is submitted:
\r
578 * <a href="http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D">Google</a>
\r
580 * Note: Use rawurldecode() so it does not remove plus signs
\r
583 $str = rawurldecode($str);
\r
586 * Convert character entities to ASCII
\r
588 * This permits our tests below to work reliably.
\r
589 * We only convert entities that are within tags since
\r
590 * these are the ones that will pose security problems.
\r
594 $str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str);
\r
596 $str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_html_entity_decode_callback'), $str);
\r
599 * Remove Invisible Characters Again!
\r
601 $str = $this->_remove_invisible_characters($str);
\r
604 * Convert all tabs to spaces
\r
606 * This prevents strings like this: ja vascript
\r
607 * NOTE: we deal with spaces between characters later.
\r
608 * NOTE: preg_replace was found to be amazingly slow here on large blocks of data,
\r
609 * so we use str_replace.
\r
613 if (strpos($str, "\t") !== FALSE)
\r
615 $str = str_replace("\t", ' ', $str);
\r
619 * Capture converted string for later comparison
\r
621 $converted_string = $str;
\r
624 * Not Allowed Under Any Conditions
\r
627 foreach ($this->never_allowed_str as $key => $val)
\r
629 $str = str_replace($key, $val, $str);
\r
632 foreach ($this->never_allowed_regex as $key => $val)
\r
634 $str = preg_replace("#".$key."#i", $val, $str);
\r
638 * Makes PHP tags safe
\r
640 * Note: XML tags are inadvertently replaced too:
\r
644 * But it doesn't seem to pose a problem.
\r
647 if ($is_image === TRUE)
\r
649 // Images have a tendency to have the PHP short opening and closing tags every so often
\r
650 // so we skip those and only do the long opening tags.
\r
651 $str = str_replace(array('<?php', '<?PHP'), array('<?php', '<?PHP'), $str);
\r
655 $str = str_replace(array('<?php', '<?PHP', '<?', '?'.'>'), array('<?php', '<?PHP', '<?', '?>'), $str);
\r
659 * Compact any exploded words
\r
661 * This corrects words like: j a v a s c r i p t
\r
662 * These words are compacted back to their correct state.
\r
665 $words = array('javascript', 'expression', 'vbscript', 'script', 'applet', 'alert', 'document', 'write', 'cookie', 'window');
\r
666 foreach ($words as $word)
\r
670 for ($i = 0, $wordlen = strlen($word); $i < $wordlen; $i++)
\r
672 $temp .= substr($word, $i, 1)."\s*";
\r
675 // We only want to do this when it is followed by a non-word character
\r
676 // That way valid stuff like "dealer to" does not become "dealerto"
\r
677 $str = preg_replace_callback('#('.substr($temp, 0, -3).')(\W)#is', array($this, '_compact_exploded_words'), $str);
\r
681 * Remove disallowed Javascript in links or img tags
\r
682 * We used to do some version comparisons and use of stripos for PHP5, but it is dog slow compared
\r
683 * to these simplified non-capturing preg_match(), especially if the pattern exists in the string
\r
689 if (preg_match("/<a/i", $str))
\r
691 $str = preg_replace_callback("#<a\s+([^>]*?)(>|$)#si", array($this, '_js_link_removal'), $str);
\r
694 if (preg_match("/<img/i", $str))
\r
696 $str = preg_replace_callback("#<img\s+([^>]*?)(\s?/?>|$)#si", array($this, '_js_img_removal'), $str);
\r
699 if (preg_match("/script/i", $str) OR preg_match("/xss/i", $str))
\r
701 $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str);
\r
704 while($original != $str);
\r
709 * Remove JavaScript Event Handlers
\r
711 * Note: This code is a little blunt. It removes
\r
712 * the event handler and anything up to the closing >,
\r
713 * but it's unlikely to be a problem.
\r
716 $event_handlers = array('[^a-z_\-]on\w*','xmlns');
\r
718 if ($is_image === TRUE)
\r
721 * Adobe Photoshop puts XML metadata into JFIF images, including namespacing,
\r
722 * so we have to allow this for images. -Paul
\r
724 unset($event_handlers[array_search('xmlns', $event_handlers)]);
\r
727 $str = preg_replace("#<([^><]+?)(".implode('|', $event_handlers).")(\s*=\s*[^><]*)([><]*)#i", "<\\1\\4", $str);
\r
730 * Sanitize naughty HTML elements
\r
732 * If a tag containing any of the words in the list
\r
733 * below is found, the tag gets converted to entities.
\r
736 * Becomes: <blink>
\r
739 $naughty = 'alert|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|xml|xss';
\r
740 $str = preg_replace_callback('#<(/*\s*)('.$naughty.')([^><]*)([><]*)#is', array($this, '_sanitize_naughty_html'), $str);
\r
743 * Sanitize naughty scripting elements
\r
745 * Similar to above, only instead of looking for
\r
746 * tags it looks for PHP and JavaScript commands
\r
747 * that are disallowed. Rather than removing the
\r
748 * code, it simply converts the parenthesis to entities
\r
749 * rendering the code un-executable.
\r
751 * For example: eval('some code')
\r
752 * Becomes: eval('some code')
\r
755 $str = preg_replace('#(alert|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)#si', "\\1\\2(\\3)", $str);
\r
760 * This adds a bit of extra precaution in case
\r
761 * something got through the above filters
\r
764 foreach ($this->never_allowed_str as $key => $val)
\r
766 $str = str_replace($key, $val, $str);
\r
769 foreach ($this->never_allowed_regex as $key => $val)
\r
771 $str = preg_replace("#".$key."#i", $val, $str);
\r
775 * Images are Handled in a Special Way
\r
776 * - Essentially, we want to know that after all of the character conversion is done whether
\r
777 * any unwanted, likely XSS, code was found. If not, we return TRUE, as the image is clean.
\r
778 * However, if the string post-conversion does not matched the string post-removal of XSS,
\r
779 * then it fails, as there was unwanted XSS code found and removed/changed during processing.
\r
782 if ($is_image === TRUE)
\r
784 if ($str == $converted_string)
\r
794 log_message('debug', "XSS Filtering completed");
\r
798 // --------------------------------------------------------------------
\r
801 * Random Hash for protecting URLs
\r
806 function xss_hash()
\r
808 if ($this->xss_hash == '')
\r
810 if (phpversion() >= 4.2)
\r
813 mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff);
\r
815 $this->xss_hash = md5(time() + mt_rand(0, 1999999999));
\r
818 return $this->xss_hash;
\r
821 // --------------------------------------------------------------------
\r
824 * Remove Invisible Characters
\r
826 * This prevents sandwiching null characters
\r
827 * between ascii characters, like Java\0script.
\r
833 function _remove_invisible_characters($str)
\r
835 static $non_displayables;
\r
837 if ( ! isset($non_displayables))
\r
839 // every control character except newline (dec 10), carriage return (dec 13), and horizontal tab (dec 09),
\r
840 $non_displayables = array(
\r
841 '/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15
\r
842 '/%1[0-9a-f]/', // url encoded 16-31
\r
843 '/[\x00-\x08]/', // 00-08
\r
844 '/\x0b/', '/\x0c/', // 11, 12
\r
845 '/[\x0e-\x1f]/' // 14-31
\r
852 $str = preg_replace($non_displayables, '', $str);
\r
854 while ($cleaned != $str);
\r
859 // --------------------------------------------------------------------
\r
862 * Compact Exploded Words
\r
864 * Callback function for xss_clean() to remove whitespace from
\r
865 * things like j a v a s c r i p t
\r
871 function _compact_exploded_words($matches)
\r
873 return preg_replace('/\s+/s', '', $matches[1]).$matches[2];
\r
876 // --------------------------------------------------------------------
\r
879 * Sanitize Naughty HTML
\r
881 * Callback function for xss_clean() to remove naughty HTML elements
\r
887 function _sanitize_naughty_html($matches)
\r
889 // encode opening brace
\r
890 $str = '<'.$matches[1].$matches[2].$matches[3];
\r
892 // encode captured opening or closing brace to prevent recursive vectors
\r
893 $str .= str_replace(array('>', '<'), array('>', '<'), $matches[4]);
\r
898 // --------------------------------------------------------------------
\r
903 * Callback function for xss_clean() to sanitize links
\r
904 * This limits the PCRE backtracks, making it more performance friendly
\r
905 * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in
\r
906 * PHP 5.2+ on link-heavy strings
\r
912 function _js_link_removal($match)
\r
914 $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]));
\r
915 return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si", "", $attributes), $match[0]);
\r
921 * Callback function for xss_clean() to sanitize image tags
\r
922 * This limits the PCRE backtracks, making it more performance friendly
\r
923 * and prevents PREG_BACKTRACK_LIMIT_ERROR from being triggered in
\r
924 * PHP 5.2+ on image tag heavy strings
\r
930 function _js_img_removal($match)
\r
932 $attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]));
\r
933 return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si", "", $attributes), $match[0]);
\r
936 // --------------------------------------------------------------------
\r
939 * Attribute Conversion
\r
941 * Used as a callback for XSS Clean
\r
947 function _convert_attribute($match)
\r
949 return str_replace(array('>', '<'), array('>', '<'), $match[0]);
\r
952 // --------------------------------------------------------------------
\r
955 * HTML Entity Decode Callback
\r
957 * Used as a callback for XSS Clean
\r
963 function _html_entity_decode_callback($match)
\r
965 $CFG =& load_class('Config');
\r
966 $charset = $CFG->item('charset');
\r
968 return $this->_html_entity_decode($match[0], strtoupper($charset));
\r
971 // --------------------------------------------------------------------
\r
974 * HTML Entities Decode
\r
976 * This function is a replacement for html_entity_decode()
\r
978 * In some versions of PHP the native function does not work
\r
979 * when UTF-8 is the specified character set, so this gives us
\r
980 * a work-around. More info here:
\r
981 * http://bugs.php.net/bug.php?id=25670
\r
988 /* -------------------------------------------------
\r
989 /* Replacement for html_entity_decode()
\r
990 /* -------------------------------------------------*/
\r
993 NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the
\r
994 character set, and the PHP developers said they were not back porting the
\r
995 fix to versions other than PHP 5.x.
\r
997 function _html_entity_decode($str, $charset='UTF-8')
\r
999 if (stristr($str, '&') === FALSE) return $str;
\r
1001 // The reason we are not using html_entity_decode() by itself is because
\r
1002 // while it is not technically correct to leave out the semicolon
\r
1003 // at the end of an entity most browsers will still interpret the entity
\r
1004 // correctly. html_entity_decode() does not convert entities without
\r
1005 // semicolons, so we are left with our own little solution here. Bummer.
\r
1007 if (function_exists('html_entity_decode') && (strtolower($charset) != 'utf-8' OR version_compare(phpversion(), '5.0.0', '>=')))
\r
1009 $str = html_entity_decode($str, ENT_COMPAT, $charset);
\r
1010 $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str);
\r
1011 return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str);
\r
1014 // Numeric Entities
\r
1015 $str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str);
\r
1016 $str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str);
\r
1018 // Literal Entities - Slightly slow so we do another check
\r
1019 if (stristr($str, '&') === FALSE)
\r
1021 $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES)));
\r
1027 // --------------------------------------------------------------------
\r
1030 * Filter Attributes
\r
1032 * Filters tag attributes for consistency and safety
\r
1038 function _filter_attributes($str)
\r
1042 if (preg_match_all('#\s*[a-z\-]+\s*=\s*(\042|\047)([^\\1]*?)\\1#is', $str, $matches))
\r
1044 foreach ($matches[0] as $match)
\r
1046 $out .= "{$match}";
\r
1053 // --------------------------------------------------------------------
\r
1056 // END Input class
\r
1058 /* End of file Input.php */
\r
1059 /* Location: ./system/libraries/Input.php */