CSS user input ..is it a security threat to database and website?

Reply

Join Date: Dec 2007
Posts: 136
Reputation: justted is an unknown quantity at this point 
Solved Threads: 2
justted justted is offline Offline
Junior Poster

CSS user input ..is it a security threat to database and website?

 
0
  #1
Jun 10th, 2009
Hello all,

My website has a feature in which I can turn on/off a feature which allows members to add their own CSS code for their profile design!

If possible I want to allow this as it would mean a much better platform for my members but I wanted to know what risk I would be causing if I have this feature turned on. Here is the code that processes and checks the code:

  1. // IF NEW
  2. if($task == "dosave") {
  3. $style_profile = addslashes(str_replace("-moz-binding", "", strip_tags(htmlspecialchars_decode($_POST['style_profile'], ENT_QUOTES))));
  4. $style_profile_sample = $_POST['style_profile_sample'];
  5.  
  6. // SET STYLE TO NOTHING IF NEDED
  7. if($user->level_info[level_profile_style] == 0 && $user->level_info[level_profile_style_sample] == 0) {
  8. $style_profile = "";
  9. $style_profile_sample = 0;
  10.  
  11. // SET STYLE TO OPTIONAL IF NEEDED
  12. } elseif($user->level_info[level_profile_style] == 0 && $user->level_info[level_profile_style_sample] != 0) {
  13. $style_profile = addslashes(str_replace("-moz-binding", "", strip_tags($sample[$style_profile_sample])));
  14. }


As you can see the code does check with the addslahes and strip tags but is this enough to protect the entire website? This is of course only CSS and design changes so I wasnt sure if users could inject any dodgy code or not.

Any advice would be appreciated

Justin
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 60
Reputation: Andrieux is an unknown quantity at this point 
Solved Threads: 4
Andrieux Andrieux is offline Offline
Junior Poster in Training

Re: CSS user input ..is it a security threat to database and website?

 
0
  #2
Jun 10th, 2009
Why not just write a .css file for the portion of the site they can edit (you can do so with PHP), then import the CSS file.

Also: http://us2.php.net/manual/en/functio...ape-string.php
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 136
Reputation: justted is an unknown quantity at this point 
Solved Threads: 2
justted justted is offline Offline
Junior Poster

Re: CSS user input ..is it a security threat to database and website?

 
0
  #3
Jun 10th, 2009
Heya.... erm how do you mean exactly?

What if I had 50,000 members (i wish) and they all wanted different designs? Wouldnt this stop that from happening by having a separate .css file?

Currently its stored into the database so if I switch the option on to allow for custom profile design then they can type their own custom css in a text box and submit it!

My website uses quite a complicated system with tons of functions and classes and already has loads of .css templates.

Is this not an adequate way then?

Thanks

Justin
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 340
Reputation: Josh Connerty is an unknown quantity at this point 
Solved Threads: 26
Josh Connerty's Avatar
Josh Connerty Josh Connerty is offline Offline
Posting Whiz

Re: CSS user input ..is it a security threat to database and website?

 
0
  #4
Jun 11th, 2009
You really need to make a HTML structure and then give them an input box to change the value of the CSS color: <this>; .

Got to http://bebo.com/ and try creating a skin and that will give you a little idea on what might be safe. (You might have to sign up :/)
Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.

My Liveperson: http://liveperson.com/josh-connerty/
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 431
Reputation: Atli is on a distinguished road 
Solved Threads: 55
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training

Re: CSS user input ..is it a security threat to database and website?

 
0
  #5
Jun 11th, 2009
Hi.

If you do allow them to use their own CSS, be careful not to let them use url() values, as that could make your users vulnerable to XSS attacks.
(As well as any other style that would allow loading of external resources... can't think of any more of them at the moment)
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: CSS user input ..is it a security threat to database and website?

 
0
  #6
Jun 12th, 2009
Originally Posted by Atli View Post
Hi.

If you do allow them to use their own CSS, be careful not to let them use url() values, as that could make your users vulnerable to XSS attacks.
(As well as any other style that would allow loading of external resources... can't think of any more of them at the moment)
Yes, there are a number of them. There have been a a lot of reports of worms in sites that allow CSS from users (myspace worm). I'm sure it will be hard if not impossible to clean your CSS.

http://www.thespanner.co.uk/category/css/

Funny thing is you can't really search for "css xss" since CSS is another acronym for XSS.
Last edited by digital-ether; Jun 12th, 2009 at 7:00 pm.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC