Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [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 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 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 |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 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 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * CodeIgniter Security Helpers |
| 32 | * |
| 33 | * @package CodeIgniter |
| 34 | * @subpackage Helpers |
| 35 | * @category Helpers |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/helpers/security_helper.html |
| 38 | */ |
| 39 | |
| 40 | // ------------------------------------------------------------------------ |
| 41 | |
| 42 | /** |
| 43 | * XSS Filtering |
| 44 | * |
| 45 | * @access public |
| 46 | * @param string |
Derek Jones | f0bcb3c | 2009-02-10 18:40:21 +0000 | [diff] [blame] | 47 | * @param bool whether or not the content is an image file |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 48 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 49 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 50 | if ( ! function_exists('xss_clean')) |
| 51 | { |
Derek Jones | f0bcb3c | 2009-02-10 18:40:21 +0000 | [diff] [blame] | 52 | function xss_clean($str, $is_image = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 53 | { |
| 54 | $CI =& get_instance(); |
Derek Jones | 11b1e51 | 2010-03-05 10:22:44 -0600 | [diff] [blame] | 55 | return $CI->security->xss_clean($str, $is_image); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
Derek Allard | 4433f42 | 2010-07-23 08:47:34 -0400 | [diff] [blame] | 59 | // ------------------------------------------------------------------------ |
| 60 | |
| 61 | /** |
| 62 | * Sanitize Filename |
| 63 | * |
| 64 | * @access public |
| 65 | * @param string |
| 66 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 67 | */ |
Derek Allard | 4433f42 | 2010-07-23 08:47:34 -0400 | [diff] [blame] | 68 | if ( ! function_exists('sanitize_filename')) |
| 69 | { |
| 70 | function sanitize_filename($filename) |
| 71 | { |
| 72 | $CI =& get_instance(); |
| 73 | return $CI->security->sanitize_filename($filename); |
| 74 | } |
| 75 | } |
| 76 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 77 | // -------------------------------------------------------------------- |
| 78 | |
| 79 | /** |
| 80 | * Hash encode a string |
| 81 | * |
| 82 | * @access public |
| 83 | * @param string |
| 84 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 85 | */ |
Derek Allard | 8719a5c | 2009-10-08 16:42:59 +0000 | [diff] [blame] | 86 | if ( ! function_exists('do_hash')) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 87 | { |
Derek Allard | 8719a5c | 2009-10-08 16:42:59 +0000 | [diff] [blame] | 88 | function do_hash($str, $type = 'sha1') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 89 | { |
| 90 | if ($type == 'sha1') |
| 91 | { |
Pascal Kriete | 6b48867 | 2011-04-05 15:02:15 -0400 | [diff] [blame] | 92 | return sha1($str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 93 | } |
| 94 | else |
| 95 | { |
| 96 | return md5($str); |
| 97 | } |
| 98 | } |
| 99 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 100 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 101 | // ------------------------------------------------------------------------ |
| 102 | |
| 103 | /** |
| 104 | * Strip Image Tags |
| 105 | * |
| 106 | * @access public |
| 107 | * @param string |
| 108 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 109 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 110 | if ( ! function_exists('strip_image_tags')) |
| 111 | { |
| 112 | function strip_image_tags($str) |
| 113 | { |
| 114 | $str = preg_replace("#<img\s+.*?src\s*=\s*[\"'](.+?)[\"'].*?\>#", "\\1", $str); |
| 115 | $str = preg_replace("#<img\s+.*?src\s*=\s*(.+?).*?\>#", "\\1", $str); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 116 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 117 | return $str; |
| 118 | } |
| 119 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 120 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 121 | // ------------------------------------------------------------------------ |
| 122 | |
| 123 | /** |
| 124 | * Convert PHP tags to entities |
| 125 | * |
| 126 | * @access public |
| 127 | * @param string |
| 128 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 129 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 130 | if ( ! function_exists('encode_php_tags')) |
| 131 | { |
| 132 | function encode_php_tags($str) |
| 133 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 134 | return str_replace(array('<?php', '<?PHP', '<?', '?>'), array('<?php', '<?PHP', '<?', '?>'), $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | |
| 139 | /* End of file security_helper.php */ |
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 140 | /* Location: ./system/helpers/security_helper.php */ |