Andrey Andreev | a381d17 | 2012-01-06 19:19:37 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | a381d17 | 2012-01-06 19:19:37 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | a381d17 | 2012-01-06 19:19:37 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * CodeIgniter Security Helpers |
| 30 | * |
| 31 | * @package CodeIgniter |
| 32 | * @subpackage Helpers |
| 33 | * @category Helpers |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 34 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | * @link http://codeigniter.com/user_guide/helpers/security_helper.html |
| 36 | */ |
| 37 | |
| 38 | // ------------------------------------------------------------------------ |
| 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | if ( ! function_exists('xss_clean')) |
| 41 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 42 | /** |
| 43 | * XSS Filtering |
| 44 | * |
| 45 | * @param string |
| 46 | * @param bool whether or not the content is an image file |
| 47 | * @return string |
| 48 | */ |
Derek Jones | f0bcb3c | 2009-02-10 18:40:21 +0000 | [diff] [blame] | 49 | function xss_clean($str, $is_image = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 50 | { |
| 51 | $CI =& get_instance(); |
Derek Jones | 11b1e51 | 2010-03-05 10:22:44 -0600 | [diff] [blame] | 52 | return $CI->security->xss_clean($str, $is_image); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
Derek Allard | 4433f42 | 2010-07-23 08:47:34 -0400 | [diff] [blame] | 56 | // ------------------------------------------------------------------------ |
| 57 | |
Derek Allard | 4433f42 | 2010-07-23 08:47:34 -0400 | [diff] [blame] | 58 | if ( ! function_exists('sanitize_filename')) |
| 59 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 60 | /** |
| 61 | * Sanitize Filename |
| 62 | * |
| 63 | * @param string |
| 64 | * @return string |
| 65 | */ |
Derek Allard | 4433f42 | 2010-07-23 08:47:34 -0400 | [diff] [blame] | 66 | function sanitize_filename($filename) |
| 67 | { |
| 68 | $CI =& get_instance(); |
| 69 | return $CI->security->sanitize_filename($filename); |
| 70 | } |
| 71 | } |
| 72 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 73 | // -------------------------------------------------------------------- |
| 74 | |
Derek Allard | 8719a5c | 2009-10-08 16:42:59 +0000 | [diff] [blame] | 75 | if ( ! function_exists('do_hash')) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 76 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 77 | /** |
| 78 | * Hash encode a string |
| 79 | * |
Andrey Andreev | 0f0b769 | 2012-06-07 14:57:04 +0300 | [diff] [blame^] | 80 | * This function is DEPRECATED and should be removed in |
| 81 | * CodeIgniter 3.1+. Use hash() instead. |
| 82 | * |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 83 | * @param string |
| 84 | * @param string |
| 85 | * @return string |
| 86 | */ |
Derek Allard | 8719a5c | 2009-10-08 16:42:59 +0000 | [diff] [blame] | 87 | function do_hash($str, $type = 'sha1') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 88 | { |
Andrey Andreev | 7eea306 | 2012-03-19 12:58:45 +0200 | [diff] [blame] | 89 | if ( ! in_array(strtolower($type), hash_algos())) |
Andrey Andreev | 50bff7c | 2012-03-19 12:16:38 +0200 | [diff] [blame] | 90 | { |
| 91 | $type = 'md5'; |
| 92 | } |
| 93 | |
freewil | 8840c96 | 2012-03-18 15:23:09 -0400 | [diff] [blame] | 94 | return hash($type, $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 95 | } |
| 96 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 97 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 98 | // ------------------------------------------------------------------------ |
| 99 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 100 | if ( ! function_exists('strip_image_tags')) |
| 101 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 102 | /** |
| 103 | * Strip Image Tags |
| 104 | * |
| 105 | * @param string |
| 106 | * @return string |
| 107 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 108 | function strip_image_tags($str) |
| 109 | { |
Andrey Andreev | 50bff7c | 2012-03-19 12:16:38 +0200 | [diff] [blame] | 110 | return preg_replace(array('#<img\s+.*?src\s*=\s*["\'](.+?)["\'].*?\>#', '#<img\s+.*?src\s*=\s*(.+?).*?\>#'), '\\1', $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 111 | } |
| 112 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 113 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 114 | // ------------------------------------------------------------------------ |
| 115 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 116 | if ( ! function_exists('encode_php_tags')) |
| 117 | { |
Timothy Warren | b75faa1 | 2012-04-27 12:03:32 -0400 | [diff] [blame] | 118 | /** |
| 119 | * Convert PHP tags to entities |
| 120 | * |
| 121 | * @param string |
| 122 | * @return string |
| 123 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 124 | function encode_php_tags($str) |
| 125 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 126 | return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('<?php', '<?PHP', '<?', '?>'), $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 130 | /* End of file security_helper.php */ |
Andrey Andreev | e92df33 | 2012-03-26 22:44:20 +0300 | [diff] [blame] | 131 | /* Location: ./system/helpers/security_helper.php */ |