blob: cf9854c1b7351a89624bf079e8b0e4164f8087ff [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001###############
2Security Helper
3###############
4
5The Security Helper file contains security related functions.
6
7.. contents:: Page Contents
8
9Loading this Helper
10===================
11
Andrey Andreev53b8ef52012-11-08 21:38:53 +020012This helper is loaded using the following code::
Derek Jones8ede1a22011-10-05 13:34:52 -050013
14 $this->load->helper('security');
15
16The following functions are available:
17
18xss_clean()
19===========
20
Derek Jonesb8c283a2013-07-19 16:02:53 -070021.. function:: xss_clean($str, $is_image = FALSE)
Andrey Andreev53b8ef52012-11-08 21:38:53 +020022
23 :param string $str: Input data
24 :param bool $is_image: Whether we're dealing with an image
25 :returns: string
26
27Provides Cross Site Script Hack filtering.
28
29This function is an alias for ``CI_Input::xss_clean()``. For more info,
30please see the :doc:`Input Library <../libraries/input>` documentation.
Derek Jones8ede1a22011-10-05 13:34:52 -050031
32sanitize_filename()
33===================
34
Derek Jonesb8c283a2013-07-19 16:02:53 -070035.. function:: sanitize_filename($filename)
Andrey Andreev53b8ef52012-11-08 21:38:53 +020036
37 :param string $filename: Filename
38 :returns: string
39
40Provides protection against directory traversal.
41
42This function is an alias for ``CI_Security::sanitize_filename()``.
43For more info, please see the :doc:`Security Library <../libraries/security>`
44documentation.
Derek Jones8ede1a22011-10-05 13:34:52 -050045
46do_hash()
47=========
48
Derek Jonesb8c283a2013-07-19 16:02:53 -070049.. function:: do_hash($str, $type = 'sha1')
Andrey Andreev53b8ef52012-11-08 21:38:53 +020050
51 :param string $str: Input
52 :param string $type: Algorithm
53 :returns: string
54
freewil8840c962012-03-18 15:23:09 -040055Permits you to create one way hashes suitable for encrypting
Andrey Andreev53b8ef52012-11-08 21:38:53 +020056passwords. Will use SHA1 by default.
57
58See `hash_algos() <http://php.net/function.hash_algos>`_
freewil8840c962012-03-18 15:23:09 -040059for a full list of supported algorithms.
Derek Jones8ede1a22011-10-05 13:34:52 -050060
Andrey Andreev53b8ef52012-11-08 21:38:53 +020061Examples::
Derek Jones8ede1a22011-10-05 13:34:52 -050062
63 $str = do_hash($str); // SHA1
64 $str = do_hash($str, 'md5'); // MD5
65
Andrey Andreev0f0b7692012-06-07 14:57:04 +030066.. note:: This function was formerly named ``dohash()``, which has been
67 removed in favor of ``do_hash()``.
68
69.. note:: This function is DEPRECATED. Use the native ``hash()`` instead.
Derek Jones8ede1a22011-10-05 13:34:52 -050070
71strip_image_tags()
72==================
73
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
79This is a security function that will strip image tags from a string.
80It leaves the image URL as plain text.
81
82Example::
Derek Jones8ede1a22011-10-05 13:34:52 -050083
84 $string = strip_image_tags($string);
85
Andrey Andreev53b8ef52012-11-08 21:38:53 +020086This function is an alias for ``CI_Security::strip_image_tags()``. For
87more info, please see the :doc:`Security Library <../libraries/security>`
88documentation.
89
Derek Jones8ede1a22011-10-05 13:34:52 -050090encode_php_tags()
91=================
92
Derek Jonesb8c283a2013-07-19 16:02:53 -070093.. function:: encode_php_tags($str)
Derek Jones8ede1a22011-10-05 13:34:52 -050094
Andrey Andreev53b8ef52012-11-08 21:38:53 +020095 :param string $str: Input
96 :returns: string
Derek Jones8ede1a22011-10-05 13:34:52 -050097
Andrey Andreev53b8ef52012-11-08 21:38:53 +020098This is a security function that converts PHP tags to entities.
Derek Jones8ede1a22011-10-05 13:34:52 -050099
Derek Jones123bb202013-07-19 16:37:51 -0700100.. note: :func:`xss_clean()` does this automatically, if you use it.
Andrey Andreev53b8ef52012-11-08 21:38:53 +0200101
102Example::
103
104 $string = encode_php_tags($string);