Are you sure about handling SECURITY?! |
Hi to all developers...
NOTICE! Dear developer... If you're tired or has no sufficient time to read this, please skip it for now and come back later! We would try to this post be a good and complete reference about the repetitive and not complete issue... input and output security. I know there were some posts about this issue and I read almost all of them. But I think there are still some misunderstanding about security issue and how handling it. SCENARIO 1 Suppose I prepare a form for collecting info about users, like their name, job, state, username, password and etc. let's consider one: PHP Code: <?php echo form_open('user/complete_info'); ?> Now the user insert something in this input and assume submit it. Now in controller: 1. I filter or validate input (as @mwhitney frequently mentioned filter (validate) input, escape output ) PHP Code: $this->form_validation->set_rules('first_name', 'name', 'required|trim|regex_match[/^[^0-9,#@%&~_\!\?\$\*\+\=\(\)\|\/\\\>\<\.\:\-\^]+$/]'); As you see, I validate input via regex and allow just a-z and A-Z chars. (also for now, the user can insert [ and ] and I could not handle this issue!) 2. If the input is valid, I will be store it into database. Controller: PHP Code: if($this->form_validation->run() === FALSE){ Model: PHP Code: public function insert_user_info($info){
Q2. Now that I used CI 3 Query Builders, Should I escape my queries? After I handle these, user can see completed info in his/her panel. Now first, I must retrieve and read info from database, the info are input (as @mwhitney mentioned here) and the output is HTML code that sent to user browser, user panel. Q3. How could I handle this properly? Just retrieve them and put in xss_clean() function and the result pass to view file? Or use htmlspecialchars()? Or some other approach? Q4. As @mwhitney said, now the input is read info from db, so how could validate them as inputs? SCENARIO 1' Suppose I prepare a simple WYSIWYG editor for users and accept some basic tags, in this situation what should I do? As you know, some these editors (like CKEditor) would encode some chars, but I know I must validate them on server-side. Q5. How do this? Just use htmlspecialchars or xss_clean() or it's better to user HTML Purifier classes? Or some other actions? SCENARIO 2 I, as an admin, prepare some posts with a world of tags! and stored them into database in order to allow some users read them. What about this situation? SCENARIO 3 Some developers said about filtering and validating http_request, urls that redirect to them or other foreign input. Is it possible to discuss about these and give practical example? * As I said, I use latest version of CI. * I enable CSRF too. * I know about OWASP and see it quickly and will read more. Thanks to all experts for arrived to this line ![]() |
Messages In This Thread |
Are you sure about handling SECURITY?! - by pb.sajjad - 07-15-2016, 06:52 AM
RE: Are you sure about handling SECURITY?! - by PaulD - 07-15-2016, 07:13 AM
RE: Are you sure about handling SECURITY?! - by mwhitney - 07-15-2016, 10:19 AM
RE: Are you sure about handling SECURITY?! - by pb.sajjad - 07-17-2016, 12:48 PM
RE: Are you sure about handling SECURITY?! - by mwhitney - 07-18-2016, 01:38 PM
RE: Are you sure about handling SECURITY?! - by PaulD - 07-17-2016, 01:22 PM
RE: Are you sure about handling SECURITY?! - by pb.sajjad - 07-17-2016, 02:46 PM
RE: Are you sure about handling SECURITY?! - by PaulD - 07-17-2016, 04:00 PM
RE: Are you sure about handling SECURITY?! - by pb.sajjad - 07-18-2016, 03:27 AM
|