Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter and XSS protection
#23

[eluser]theshiftexchange[/eluser]
Well - this is my global solution to XSS attacks. Firstly - I do not do ANY XSS cleaning on the inputs.

I run a hook on the _output - which cleans all my "view_data" (which is the variable I use to send data to the views).

I can toggle if I dont want the XSS Clean to run by inserting a "$view_data['clean_output'] = false" in my controller, which the hook checks:

Code:
if (( ! isset($this->CI->view_data['clean_output'])) || ($this->CI->view_data['clean_output']))
   {
    // Apply to all in the list
    $this->CI->view_data = array_map("htmlspecialchars", $this->CI->view_data);
   }


In my case - I also have a "jquery_validation" string that must not be parsed, but the rest needs to be. My simple hack was:

Code:
// Firstly - check if we want to clean out output - do that first before doing anything else
   if (( ! isset($this->CI->view_data['clean_output'])) || ($this->CI->view_data['clean_output']))
   {
    // Apply to all in the list
    // Except for jquery_validation - so copy that and reinsert
    $page_rules = $this->CI->view_data['jquery_validation'];
    $this->CI->view_data = array_map("htmlspecialchars", $this->CI->view_data);
    $this->CI->view_data['jquery_validation'] = $page_rules;
   }


Seems to be working well.


Messages In This Thread
CodeIgniter and XSS protection - by El Forum - 05-10-2011, 06:04 PM
CodeIgniter and XSS protection - by El Forum - 05-11-2011, 12:37 AM
CodeIgniter and XSS protection - by El Forum - 05-11-2011, 02:15 AM
CodeIgniter and XSS protection - by El Forum - 05-11-2011, 03:52 AM
CodeIgniter and XSS protection - by El Forum - 05-11-2011, 04:36 AM
CodeIgniter and XSS protection - by El Forum - 05-12-2011, 10:28 PM
CodeIgniter and XSS protection - by El Forum - 05-13-2011, 03:10 AM
CodeIgniter and XSS protection - by El Forum - 05-13-2011, 03:29 AM
CodeIgniter and XSS protection - by El Forum - 05-13-2011, 03:47 AM
CodeIgniter and XSS protection - by El Forum - 05-13-2011, 05:41 AM
CodeIgniter and XSS protection - by El Forum - 05-13-2011, 05:44 AM
CodeIgniter and XSS protection - by El Forum - 05-13-2011, 06:24 AM
CodeIgniter and XSS protection - by El Forum - 05-13-2011, 07:36 AM
CodeIgniter and XSS protection - by El Forum - 05-13-2011, 08:06 AM
CodeIgniter and XSS protection - by El Forum - 05-13-2011, 09:01 AM
CodeIgniter and XSS protection - by El Forum - 05-14-2011, 02:01 AM
CodeIgniter and XSS protection - by El Forum - 05-14-2011, 02:01 AM
CodeIgniter and XSS protection - by El Forum - 05-14-2011, 07:14 AM
CodeIgniter and XSS protection - by El Forum - 05-16-2011, 08:25 AM
CodeIgniter and XSS protection - by El Forum - 05-17-2011, 01:34 AM
CodeIgniter and XSS protection - by El Forum - 06-23-2011, 08:58 PM
CodeIgniter and XSS protection - by El Forum - 04-21-2012, 11:13 PM
CodeIgniter and XSS protection - by El Forum - 04-28-2012, 05:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB