blob: 7df85d017255d019c6fc20473473dc09d64e1c12 [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
Derek Jonesf9491c92013-07-19 16:46:18 -070027.. 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
31 :returns: string
32
Derek Jonesf9491c92013-07-19 16:46:18 -070033 Provides Cross Site Script Hack filtering.
Andrey Andreev53b8ef52012-11-08 21:38:53 +020034
Derek Jonesf9491c92013-07-19 16:46:18 -070035 This function is an alias for ``CI_Input::xss_clean()``. For more info,
36 please see the :doc:`Input Library <../libraries/input>` documentation.
Derek Jones8ede1a22011-10-05 13:34:52 -050037
Derek Jones8ede1a22011-10-05 13:34:52 -050038
Derek Jonesb8c283a2013-07-19 16:02:53 -070039.. function:: sanitize_filename($filename)
Andrey Andreev53b8ef52012-11-08 21:38:53 +020040
41 :param string $filename: Filename
42 :returns: string
43
Derek Jonesf9491c92013-07-19 16:46:18 -070044 Provides protection against directory traversal.
Andrey Andreev53b8ef52012-11-08 21:38:53 +020045
Derek Jonesf9491c92013-07-19 16:46:18 -070046 This function is an alias for ``CI_Security::sanitize_filename()``.
47 For more info, please see the :doc:`Security Library <../libraries/security>`
48 documentation.
Derek Jones8ede1a22011-10-05 13:34:52 -050049
Derek Jones8ede1a22011-10-05 13:34:52 -050050
Derek Jonesf9491c92013-07-19 16:46:18 -070051.. function:: do_hash($str[, $type = 'sha1'])
Andrey Andreev53b8ef52012-11-08 21:38:53 +020052
53 :param string $str: Input
54 :param string $type: Algorithm
55 :returns: string
56
Derek Jonesf9491c92013-07-19 16:46:18 -070057 Permits you to create one way hashes suitable for encrypting
58 passwords. Will use SHA1 by default.
Andrey Andreev53b8ef52012-11-08 21:38:53 +020059
Derek Jonesf9491c92013-07-19 16:46:18 -070060 See `hash_algos() <http://php.net/function.hash_algos>`_
61 for a full list of supported algorithms.
Derek Jones8ede1a22011-10-05 13:34:52 -050062
Derek Jonesf9491c92013-07-19 16:46:18 -070063 Examples::
Derek Jones8ede1a22011-10-05 13:34:52 -050064
Derek Jonesf9491c92013-07-19 16:46:18 -070065 $str = do_hash($str); // SHA1
66 $str = do_hash($str, 'md5'); // MD5
Derek Jones8ede1a22011-10-05 13:34:52 -050067
Derek Jonesf9491c92013-07-19 16:46:18 -070068 .. note:: This function was formerly named ``dohash()``, which has been
69 removed in favor of ``do_hash()``.
Andrey Andreev0f0b7692012-06-07 14:57:04 +030070
Derek Jonesf9491c92013-07-19 16:46:18 -070071 .. note:: This function is DEPRECATED. Use the native ``hash()`` instead.
Derek Jones8ede1a22011-10-05 13:34:52 -050072
Derek Jones8ede1a22011-10-05 13:34:52 -050073
Derek Jonesb8c283a2013-07-19 16:02:53 -070074.. function:: strip_image_tags($str)
Derek Jones8ede1a22011-10-05 13:34:52 -050075
Andrey Andreev53b8ef52012-11-08 21:38:53 +020076 :param string $str: Input
77 :returns: string
78
Derek Jonesf9491c92013-07-19 16:46:18 -070079 This is a security function that will strip image tags from a string.
80 It leaves the image URL as plain text.
Andrey Andreev53b8ef52012-11-08 21:38:53 +020081
Derek Jonesf9491c92013-07-19 16:46:18 -070082 Example::
Derek Jones8ede1a22011-10-05 13:34:52 -050083
Derek Jonesf9491c92013-07-19 16:46:18 -070084 $string = strip_image_tags($string);
Derek Jones8ede1a22011-10-05 13:34:52 -050085
Derek Jonesf9491c92013-07-19 16:46:18 -070086 This function is an alias for ``CI_Security::strip_image_tags()``. For
87 more info, please see the :doc:`Security Library <../libraries/security>`
88 documentation.
Andrey Andreev53b8ef52012-11-08 21:38:53 +020089
Derek Jones8ede1a22011-10-05 13:34:52 -050090
Derek Jonesb8c283a2013-07-19 16:02:53 -070091.. function:: encode_php_tags($str)
Derek Jones8ede1a22011-10-05 13:34:52 -050092
Andrey Andreev53b8ef52012-11-08 21:38:53 +020093 :param string $str: Input
94 :returns: string
Derek Jones8ede1a22011-10-05 13:34:52 -050095
Derek Jonesf9491c92013-07-19 16:46:18 -070096 This is a security function that converts PHP tags to entities.
Derek Jones8ede1a22011-10-05 13:34:52 -050097
Derek Jonesf9491c92013-07-19 16:46:18 -070098 .. note:: :func:`xss_clean()` does this automatically, if you use it.
Andrey Andreev53b8ef52012-11-08 21:38:53 +020099
Derek Jonesf9491c92013-07-19 16:46:18 -0700100 Example::
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200101
Derek Jonesf9491c92013-07-19 16:46:18 -0700102 $string = encode_php_tags($string);