tags:

views:

45

answers:

3

Hello Guys, I’m a new to Codeigniter. Just using it in my project from last 2 months. I’ve a comment section in my project. Where any one can give comments. Every things are going perfect but when ever any one putting HTML content(image/videos) & then when those are showing back in the comment section… direct HTML codes are showing in the comment page rather than HTML content(image/videos).

ex: when i’m saving any “embed youtube video code” in the comment box & save that the out put comes as “raw Embed Video codes” rather than Youtube Video…..

I feel like it must be a minor thing but really can’t understand where the fault has occurring. Plz, if any body have the solution reply me back as soon as possible.

A: 

As a quick hack you can do htmlspecialchars_decode when displaying the comment in your view. This is very dangerous though without the use of sanitization when you receive the comment - search xss_clean on this page. You should also use strip_tags to remove all the HTML tags you don't need (everything except the video tags) prior to inserting the comment in the database.

kitsched
Thx kitsched,for u'r quick reply. Actually, i'm sanitizing all my comment text inputs by xss_clean,trim. Last night, i saw that may b at the sensitization time "param" tag of youtube EMBED code is getting blocked. That's why those videos are not working properly.
mi6crazyheart
+1  A: 

I had a similar problem a while back - wanting to give end users the ability to post YouTube videos, but not allow them to just post anything without some sort of XSS protection.

I ended up using htmlpurifier - http://htmlpurifier.org/ to filter the contents being submitted in the form.

There is a modification that can be made to the whitelist that allows YouTube code through the purifier.

http://htmlpurifier.org/docs/enduser-youtube.html

So far, that's working well, but my system is still in development.

someoneinomaha
htmlpurifier with its associated CodeIgniter library is quite a find. Thank you!
kitsched
+2  A: 

Couldn't one devise a system where somebody just posts the youtube link itself and through a combination of regular expressions your own system generates the object/embed code itself so there's no security risk possible?

djFire
Sounds much safer than wrangling tags.
kitsched