blob: 103880cf9cc58cdccedafa13997e15db154ba5b8 [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001###############
2Security Helper
3###############
4
5The Security Helper file contains security related functions.
6
Derek Jonesf9491c92013-07-19 16:46:18 -07007.. contents::
8 :local:
9
10.. raw:: html
11
12 <div class="custom-index container"></div>
Derek Jones8ede1a22011-10-05 13:34:52 -050013
14Loading this Helper
15===================
16
Andrey Andreev53b8ef52012-11-08 21:38:53 +020017This helper is loaded using the following code::
Derek Jones8ede1a22011-10-05 13:34:52 -050018
19 $this->load->helper('security');
20
Derek Jonesf9491c92013-07-19 16:46:18 -070021Available Functions
22===================
23
Derek Jones8ede1a22011-10-05 13:34:52 -050024The following functions are available:
25
Derek Jones8ede1a22011-10-05 13:34:52 -050026
Andrey Andreevcd3d9db2015-02-02 13:41:01 +020027.. php:function:: xss_clean($str[, $is_image = FALSE])
Andrey Andreev53b8ef52012-11-08 21:38:53 +020028
29 :param string $str: Input data
30 :param bool $is_image: Whether we're dealing with an image
Andrey Andreev3de130c2014-02-07 23:31:49 +020031 :returns: XSS-clean string
32 :rtype: string
Andrey Andreev53b8ef52012-11-08 21:38:53 +020033
Derek Jonesf9491c92013-07-19 16:46:18 -070034 Provides Cross Site Script Hack filtering.
Andrey Andreev53b8ef52012-11-08 21:38:53 +020035
Derek Jonesf9491c92013-07-19 16:46:18 -070036 This function is an alias for ``CI_Input::xss_clean()``. For more info,
37 please see the :doc:`Input Library <../libraries/input>` documentation.
Derek Jones8ede1a22011-10-05 13:34:52 -050038
Andrey Andreevcd3d9db2015-02-02 13:41:01 +020039.. php:function:: sanitize_filename($filename)
Andrey Andreev53b8ef52012-11-08 21:38:53 +020040
41 :param string $filename: Filename
Andrey Andreev3de130c2014-02-07 23:31:49 +020042 :returns: Sanitized file name
43 :rtype: string
Andrey Andreev53b8ef52012-11-08 21:38:53 +020044
Derek Jonesf9491c92013-07-19 16:46:18 -070045 Provides protection against directory traversal.
Andrey Andreev53b8ef52012-11-08 21:38:53 +020046
Derek Jonesf9491c92013-07-19 16:46:18 -070047 This function is an alias for ``CI_Security::sanitize_filename()``.
48 For more info, please see the :doc:`Security Library <../libraries/security>`
49 documentation.
Derek Jones8ede1a22011-10-05 13:34:52 -050050
Derek Jones8ede1a22011-10-05 13:34:52 -050051
Andrey Andreevcd3d9db2015-02-02 13:41:01 +020052.. php:function:: do_hash($str[, $type = 'sha1'])
Andrey Andreev53b8ef52012-11-08 21:38:53 +020053
54 :param string $str: Input
55 :param string $type: Algorithm
Andrey Andreev3de130c2014-02-07 23:31:49 +020056 :returns: Hex-formatted hash
57 :rtype: string
Andrey Andreev53b8ef52012-11-08 21:38:53 +020058
Derek Jonesf9491c92013-07-19 16:46:18 -070059 Permits you to create one way hashes suitable for encrypting
60 passwords. Will use SHA1 by default.
Andrey Andreev53b8ef52012-11-08 21:38:53 +020061
Derek Jonesf9491c92013-07-19 16:46:18 -070062 See `hash_algos() <http://php.net/function.hash_algos>`_
63 for a full list of supported algorithms.
Derek Jones8ede1a22011-10-05 13:34:52 -050064
Derek Jonesf9491c92013-07-19 16:46:18 -070065 Examples::
Derek Jones8ede1a22011-10-05 13:34:52 -050066
Derek Jonesf9491c92013-07-19 16:46:18 -070067 $str = do_hash($str); // SHA1
68 $str = do_hash($str, 'md5'); // MD5
Derek Jones8ede1a22011-10-05 13:34:52 -050069
Derek Jonesf9491c92013-07-19 16:46:18 -070070 .. note:: This function was formerly named ``dohash()``, which has been
71 removed in favor of ``do_hash()``.
Andrey Andreev0f0b7692012-06-07 14:57:04 +030072
Derek Jonesf9491c92013-07-19 16:46:18 -070073 .. note:: This function is DEPRECATED. Use the native ``hash()`` instead.
Derek Jones8ede1a22011-10-05 13:34:52 -050074
Derek Jones8ede1a22011-10-05 13:34:52 -050075
Andrey Andreevcd3d9db2015-02-02 13:41:01 +020076.. php:function:: strip_image_tags($str)
Derek Jones8ede1a22011-10-05 13:34:52 -050077
Andrey Andreev3de130c2014-02-07 23:31:49 +020078 :param string $str: Input string
79 :returns: The input string with no image tags
80 :rtype: string
Andrey Andreev53b8ef52012-11-08 21:38:53 +020081
Derek Jonesf9491c92013-07-19 16:46:18 -070082 This is a security function that will strip image tags from a string.
83 It leaves the image URL as plain text.
Andrey Andreev53b8ef52012-11-08 21:38:53 +020084
Derek Jonesf9491c92013-07-19 16:46:18 -070085 Example::
Derek Jones8ede1a22011-10-05 13:34:52 -050086
Derek Jonesf9491c92013-07-19 16:46:18 -070087 $string = strip_image_tags($string);
Derek Jones8ede1a22011-10-05 13:34:52 -050088
Derek Jonesf9491c92013-07-19 16:46:18 -070089 This function is an alias for ``CI_Security::strip_image_tags()``. For
90 more info, please see the :doc:`Security Library <../libraries/security>`
91 documentation.
Andrey Andreev53b8ef52012-11-08 21:38:53 +020092
Derek Jones8ede1a22011-10-05 13:34:52 -050093
Andrey Andreevcd3d9db2015-02-02 13:41:01 +020094.. php:function:: encode_php_tags($str)
Derek Jones8ede1a22011-10-05 13:34:52 -050095
Andrey Andreev3de130c2014-02-07 23:31:49 +020096 :param string $str: Input string
97 :returns: Safely formatted string
98 :rtype: string
Derek Jones8ede1a22011-10-05 13:34:52 -050099
Derek Jonesf9491c92013-07-19 16:46:18 -0700100 This is a security function that converts PHP tags to entities.
Derek Jones8ede1a22011-10-05 13:34:52 -0500101
Andrey Andreevcd3d9db2015-02-02 13:41:01 +0200102 .. note:: :php:func:`xss_clean()` does this automatically, if you use it.
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200103
Derek Jonesf9491c92013-07-19 16:46:18 -0700104 Example::
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200105
Derek Jonesf9491c92013-07-19 16:46:18 -0700106 $string = encode_php_tags($string);