From 46e77e0d28cf6c057484df022a012e85de2f79b6 Mon Sep 17 00:00:00 2001 From: David Cox Jr Date: Thu, 3 Oct 2013 16:56:04 -0400 Subject: partial fix #2667 this fixes the ability to replace a space with a / and skip the XSS filtering --- system/core/Security.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Security.php') diff --git a/system/core/Security.php b/system/core/Security.php index 70cf3e013..368e17dc3 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -603,7 +603,7 @@ class CI_Security { */ public function strip_image_tags($str) { - return preg_replace(array('##', '##'), '\\1', $str); + return preg_replace(array('##', '##'), '\\1', $str); } // ---------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3a3d5f6c2320a90436de241af41fe22df7344728 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Thu, 17 Oct 2013 22:22:16 +0200 Subject: Replace the last rand() with mt_rand() Better entropy, faster. Also fixed a few "it's" typos. --- system/core/Security.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/core/Security.php') diff --git a/system/core/Security.php b/system/core/Security.php index 368e17dc3..6f5f5cb90 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -884,7 +884,7 @@ class CI_Security { { if ($this->_csrf_hash === '') { - // If the cookie exists we will use it's value. + // If the cookie exists we will use its value. // We don't necessarily want to regenerate it with // each page load since a page could contain embedded // sub-pages causing this feature to fail @@ -894,7 +894,7 @@ class CI_Security { return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name]; } - $this->_csrf_hash = md5(uniqid(rand(), TRUE)); + $this->_csrf_hash = md5(uniqid(mt_rand(), TRUE)); $this->csrf_set_cookie(); } -- cgit v1.2.3-24-g4f1b From 3fa729d7092c814fe14e15d8d51789ce7907f2a8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 18 Oct 2013 20:57:41 +0300 Subject: Fix issue #2681 (alternative to PR #2690) --- system/core/Security.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/core/Security.php') diff --git a/system/core/Security.php b/system/core/Security.php index 6f5f5cb90..5c5c0efb6 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -553,9 +553,9 @@ class CI_Security { { $matches = $matches1 = 0; + $str = preg_replace('~(�*[0-9a-f]{2,5});?~iS', $str, -1, $matches); + $str = preg_replace('~(&#\d{2,4});?~S', $str, -1, $matches1); $str = html_entity_decode($str, ENT_COMPAT, $charset); - $str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str, -1, $matches); - $str = preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str, -1, $matches1); } while ($matches OR $matches1); -- cgit v1.2.3-24-g4f1b From e08411d72226ba5b2f97b519051f78d978747e18 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 18 Oct 2013 21:13:56 +0300 Subject: Eh ... preg_replace() needs a replacement --- system/core/Security.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/core/Security.php') diff --git a/system/core/Security.php b/system/core/Security.php index 5c5c0efb6..9423f825c 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -553,8 +553,8 @@ class CI_Security { { $matches = $matches1 = 0; - $str = preg_replace('~(�*[0-9a-f]{2,5});?~iS', $str, -1, $matches); - $str = preg_replace('~(&#\d{2,4});?~S', $str, -1, $matches1); + $str = preg_replace('~(�*[0-9a-f]{2,5});?~iS', '$1;', $str, -1, $matches); + $str = preg_replace('~(&#\d{2,4});?~S', '$1;', $str, -1, $matches1); $str = html_entity_decode($str, ENT_COMPAT, $charset); } while ($matches OR $matches1); -- cgit v1.2.3-24-g4f1b From 1bbc5644b0c306ff72dc1228b169db56902fc031 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 7 Jan 2014 12:45:27 +0200 Subject: Fix #2268 (manually implementing PR #2269) --- system/core/Security.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/core/Security.php') diff --git a/system/core/Security.php b/system/core/Security.php index 9423f825c..0944fef92 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -117,7 +117,6 @@ class CI_Security { 'document.write' => '[removed]', '.parentNode' => '[removed]', '.innerHTML' => '[removed]', - 'window.location' => '[removed]', '-moz-binding' => '[removed]', '' => '-->', @@ -132,6 +131,7 @@ class CI_Security { */ protected $_never_allowed_regex = array( 'javascript\s*:', + '(document|(document\.)?window)\.(location|on\w*)', 'expression\s*(\(|&\#40;)', // CSS and IE 'vbscript\s*:', // IE, surprise! 'Redirect\s+302', @@ -648,8 +648,8 @@ class CI_Security { */ protected function _remove_evil_attributes($str, $is_image) { - // All javascript event handlers (e.g. onload, onclick, onmouseover), style, and xmlns - $evil_attributes = array('on\w*', 'style', 'xmlns', 'formaction'); + // Formaction, style, and xmlns + $evil_attributes = array('style', 'xmlns', 'formaction'); if ($is_image === TRUE) { -- cgit v1.2.3-24-g4f1b From 99e2f8e2397ec4bf3ce5637d5a660a122aaa7b1b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 19 Jan 2014 00:04:44 +0200 Subject: Fix #2829 --- system/core/Security.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/core/Security.php') diff --git a/system/core/Security.php b/system/core/Security.php index 0944fef92..4c01da2b8 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -551,13 +551,13 @@ class CI_Security { do { - $matches = $matches1 = 0; + $m1 = $m2 = 0; - $str = preg_replace('~(�*[0-9a-f]{2,5});?~iS', '$1;', $str, -1, $matches); - $str = preg_replace('~(&#\d{2,4});?~S', '$1;', $str, -1, $matches1); + $str = preg_replace('/(�*[0-9a-f]{2,5})(?![0-9a-f;])/iS', '$1;', $str, -1, $m1); + $str = preg_replace('/(&#\d{2,4})(?![0-9;])/S', '$1;', $str, -1, $m2); $str = html_entity_decode($str, ENT_COMPAT, $charset); } - while ($matches OR $matches1); + while ($m1 OR $m2); return $str; } -- cgit v1.2.3-24-g4f1b From 4d0571666d03511ac5b4a1f2a6882ccb1509a209 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 20 Jan 2014 11:17:34 +0200 Subject: Fix #2729 --- system/core/Security.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system/core/Security.php') diff --git a/system/core/Security.php b/system/core/Security.php index 4c01da2b8..95957a3d8 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -837,14 +837,15 @@ class CI_Security { * 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); + $str = preg_replace('/(&#\d{2,4})(?![0-9;])/', '$1;', $str); + $str = preg_replace('/(&[a-z]{2,})(?![a-z;])/i', '$1;', $str); /* * 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); + $str = preg_replace('/(�*[0-9a-f]{2,5})(?![0-9a-f;])/i', '$1;', $str); /* * Un-Protect GET variables in URLs -- cgit v1.2.3-24-g4f1b From 4356806dc0298363217694d727db9cad84a073e0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 21 Jan 2014 23:52:31 +0200 Subject: Add