Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter global_xss_filtering

In my codeigniter config I have $config['global_xss_filtering'] = TRUE;. In my admin section I have a ckeditor which generates the frontend content.

Everything that is typed and placed inside the editor works fine, images are displayed nice, html is working. All except flash. Whenever I switch to html mode and paste a youtube code piece it is escaped and the code is visible on the frontpage instead of showing a youtube movie.

If I set $config['global_xss_filtering'] = FALSE; the youtube code is passed like it should. This is because 'object', 'embed' etc are flagged as "naughty" by CI and thus escaped.

How can I bypass the xss filtering for this one controller method?

like image 495
Jens Avatar asked Oct 10 '10 09:10

Jens


People also ask

How use XSS filter in CodeIgniter?

XSS Filtering To filter data through the XSS filter use the xss_clean() method: $data = $this->security->xss_clean($data); An optional second parameter, is_image, allows this function to be used to test images for potential XSS attacks, useful for file upload security.

What is XSS filtering CodeIgniter?

XSS means cross-site scripting. CodeIgniter comes with XSS filtering security. This filter will prevent any malicious JavaScript code or any other code that attempts to hijack cookie and do malicious activities. To filter data through the XSS filter, use the xss_clean() method as shown below.


2 Answers

Turn it off by default then enable it for places that really need it.

For example, I have it turned off for all my controllers, then enable it for comments, pages, etc.

One thing you can do is create a MY_Input (or MY_Security in CI 2) like the one in PyroCMS and override the xss_clean method with an exact copy, minus the object|embed| part of the regex.

http://github.com/pyrocms/pyrocms/blob/master/system/pyrocms/libraries/MY_Security.php

It's one hell of a long way around, but it works.

Perhaps we could create a config option could be created listing the bad elements for 2.0?

like image 93
Phil Sturgeon Avatar answered Oct 05 '22 21:10

Phil Sturgeon


My case was that I wanted global_xss_filtering to be on by default but sometimes I needed the $_POST (pst you can do this to any global php array e.g. $_GET...) data to be raw as send from the browser, so my solution was to:

  1. open index.php in root folder of the project
  2. added the following line of code $unsanitized_post = $_POST; after $application_folder = 'application'; (line #92)
  3. then whenever I needed the raw $_POST I would do the following:

    global $unsanitized_post;

    print_r($unsanitized_post);

like image 42
Waqleh Avatar answered Oct 05 '22 21:10

Waqleh