blob: d9d5b728bf87af1d6d2a6a329e3abe55ab7bd431 [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001########
2Security
3########
4
5This page describes some "best practices" regarding web security, and
6details CodeIgniter's internal security features.
7
8URI Security
9============
10
11CodeIgniter is fairly restrictive regarding which characters it allows
12in your URI strings in order to help minimize the possibility that
13malicious data can be passed to your application. URIs may only contain
14the following:
15
16- Alpha-numeric text
17- Tilde: ~
18- Period: .
19- Colon: :
20- Underscore: \_
21- Dash: -
22
23Register_globals
24=================
25
26During system initialization all global variables are unset, except
27those found in the $_GET, $_POST, and $_COOKIE arrays. The unsetting
28routine is effectively the same as register_globals = off.
29
30error_reporting
31================
32
33In production environments, it is typically desirable to disable PHP's
34error reporting by setting the internal error_reporting flag to a value
35of 0. This disables native PHP errors from being rendered as output,
36which may potentially contain sensitive information.
37
38Setting CodeIgniter's ENVIRONMENT constant in index.php to a value of
39'production' will turn off these errors. In development mode, it is
40recommended that a value of 'development' is used. More information
41about differentiating between environments can be found on the :doc:`Handling
42Environments <environments>` page.
43
44magic_quotes_runtime
45======================
46
47The magic_quotes_runtime directive is turned off during system
48initialization so that you don't have to remove slashes when retrieving
49data from your database.
50
51**************
52Best Practices
53**************
54
55Before accepting any data into your application, whether it be POST data
56from a form submission, COOKIE data, URI data, XML-RPC data, or even
57data from the SERVER array, you are encouraged to practice this three
58step approach:
59
60#. Filter the data as if it were tainted.
61#. Validate the data to ensure it conforms to the correct type, length,
62 size, etc. (sometimes this step can replace step one)
63#. Escape the data before submitting it into your database.
64
65CodeIgniter provides the following functions to assist in this process:
66
67XSS Filtering
68=============
69
70CodeIgniter comes with a Cross Site Scripting filter. This filter
71looks for commonly used techniques to embed malicious Javascript into
72your data, or other types of code that attempt to hijack cookies or
73do other malicious things. The XSS Filter is described
74:doc:`here <../libraries/security>`.
75
76Validate the data
77=================
78
79CodeIgniter has a :doc:`Form Validation
80Class <../libraries/form_validation>` that assists you in
81validating, filtering, and prepping your data.
82
83Escape all data before database insertion
84=========================================
85
86Never insert information into your database without escaping it.
87Please see the section that discusses
88:doc:`queries <../database/queries>` for more information.
89
90