CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignCSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 21st, 2002, 09:12 AM
the_pedestrian the_pedestrian is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Posts: 210 the_pedestrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Question users editing their own CSS and security

hi all,

im trying to make my site as customizable as possible for its users, and am currently pulling my hair out trying to workout the regexs to allow them to edit their own CSS from an online form.

of course, it would be nice and easy if i could just bring up their CSS in a <TEXTAREA> and let them make changes and save it...but i wonder, is there security issues with this?

all users are behind htaccess, so its not like every script kiddie is gonna be in having a go at compromising my server....any ideas, either on this, or on a tidy method of achieving this result are appreciated.

heres the vibe at the moment

(i) script reads a config file, which contains name/value pairs of the changeable elements in the CSS.

(ii) script prints a form using name values as <INPUT> name/values

(iii) when user submits the form, the script opens a template of the full CSS, reads it into an array - replacing specific tags with the values from the form.

(iv) script open users CSS and spews the lot over the top


while this reads easy, it looks like a dogs dinner in code


cheers

Reply With Quote
  #2  
Old April 22nd, 2002, 06:45 PM
Benahimvp's Avatar
Benahimvp Benahimvp is offline
The Basketball Star
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2001
Location: H-Town
Posts: 550 Benahimvp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Send a message via AIM to Benahimvp Send a message via Yahoo to Benahimvp
I'm not a security expert, but I don't think using a big <textarea> to have them edit their own CSS file would be any more insecure than using a text input field to let them edit an individual style element. Any harm they would do in the <textarea> could be done in the <input> as well. Furthermore, it's really not a security issue at all that you should be worrying about since it's a CSS file. I'm not sure if I'm saying this correctly, but CSS files aren't like Perl files in that they aren't server ran an excuted. They are just read when displaying an HTML file. If anybody puts in any weird (or harmul) characters or words in the big <textarea> I don't think it would be a security issue. It would be more of a "would-it-still-display-correctly" issue. In IE if there are mistakes, I think they are just ignored, but Netscape seems to be more stringent.

With all that said (not very eloquently I must say), I do have a way to make everything secure. You will just have to set all the options. The suer will have all the options with my idea if we're just talking about colors, but if you're talking about fonts and other things of that nature, it will be a bit less "option-ful". What you would do is for each color attribute create 6 tiny <select> fields of one character each (0-9 and A-F). And give them all the same name. If you use CGI.pm all 6 characters will come in as an array and you could use the join command to make them into a scalar variable when you parse it. For example:
Code:
@bgcolor = $query->param('bgcolor');
$bgcolor = join "", @bgcolor;

That would do it. I don't know if it'll work anything besides CGI.pm. Now this form would be very time-consuming to make (although there are ways you could make the script do most of the work), but it'll be very secure and it'll still give them all the options for any color. Now as for the font issues and other things like it, you'll just have to give them a set list of fonts (or whatever it is you're working with). Just think of as many possibilities as you can and go with that.

That's basically it. I hope that gives you ideas and you can work with that. If you need any more help just reply and I'll be glad to do my best to help.
__________________
-Ben Ilegbodu
(Around the Bend Web Designs)

Reply With Quote
  #3  
Old April 22nd, 2002, 10:29 PM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 81
Send a message via AIM to Hero Zzyzzx
Actually, there are significant security risks associated with allowing users to enter free text that will be render as plain HTML (which CSS will be, unless you plan on linking in the style sheet).

Do a google search for "cross site scripting attack," which is when a user enters malicious script tags that get rendered in a browser. This is one of the more common hacks out there, and potentially VERY damaging.

Here's a nice little primer-
http://www.perl.com/pub/a/2002/02/20/css.html

Last edited by Hero Zzyzzx : April 22nd, 2002 at 10:31 PM.

Reply With Quote
  #4  
Old April 23rd, 2002, 05:21 PM
the_pedestrian the_pedestrian is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Posts: 210 the_pedestrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
thanks guys

sorry about the delay responding...i didnt get an email???

nice idea benahimvp - i hadnt considered that the array of similar named form elements would apply outside radio buttons - i suppose a <SELECT> box would do for text, style, size etc....


Hero, the CSS will indeed be linked...i wasnt sure if there was some way they could just type a script into the textarea instead or something......
thankyou for the primer, i thought that stuff was restricted to appearing in the HEAD of a document...bummer.

so a linked CSS is OK? Im not sure i see how?

this is becoming less and less a perl question

in terms of display, if they f*** it up, then its only their view of the site that is effected.....each page dynamically generates a link to the users CSS file on the server....and with an option to restore to default settings, i figured this would be pretty fool proof.

maybe this is just a nice idea, that isnt worth the hassle.

On a similar note, if your going to parse out html tags etc, whats the general perl approach to putting desired ones back in....like the formatting tags on this forum.

my method seems far too complex, which ive found....with perl at least...this means your doing it wrong!

replacing <B> is easy......but what about a link, which has more than one property?

cheers guys

Last edited by the_pedestrian : April 23rd, 2002 at 05:42 PM.

Reply With Quote
  #5  
Old April 23rd, 2002, 05:51 PM
Benahimvp's Avatar
Benahimvp Benahimvp is offline
The Basketball Star
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2001
Location: H-Town
Posts: 550 Benahimvp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Send a message via AIM to Benahimvp Send a message via Yahoo to Benahimvp
I'm not quite sure i understand your last question.

Reply With Quote
  #6  
Old April 23rd, 2002, 06:01 PM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 81
Send a message via AIM to Hero Zzyzzx
So you want to do a VBB type system where people can enter formatting tags?

I personally think that these are usually kludgy systems devised because the author's don't know the true joy of HTML::Parser, and my current favorite, HTML::TagFilter. Why make folks learn another markup system, when you can easily and safely allow them to use the specific parts of HTML that you want?

With HTML::TagFilter, you can RELIABLY (the key here) set up a filter that only allows the HTML tags and attributes that YOU want folks to be able to use.

Check out
this thread here at www.perlmonks.org. Basically, you set up a ruleset of what you allow and deny, and HTML::TagFilter does the rest for you. Here's my example from that thread-

Code:
use HTML::TagFilter;
my $tf = HTML::TagFilter->new(
			      allow=>{
				  p=>{'any'},
				  i=>{'any'},				  
				  b=>{'any'},
				  code=>{'any'},
				  br=>{'any'},
				  u=>{'any'},
				  pre=>{'any'},
				  img=>{width=>['any'],
					height=>['any'],
					border=>['any'],
					src=>['any'],
				    },
				  a=>{href=>['any'],
				      target=>['any'],
				      name=>['any'],
				  },
				  
			      }, 
			      deny=>{}, 
			      log_rejects => 1, 
			      strip_comments => 1, 
			      );

sub filter_html{
    $tf->filter(shift);
}


What this filter does is allow p, i, b, code, br, u, and pre tags with any attributes, allows img tags with any width, height, border and src attributes, and a tags with any href, target, and name attributes. All other HTML is nixed. You can then pass HTML to be filtered through the filter_html() sub (as a scalar) to be processed.

This works REALLY slick, and I really can't think of an easier way to do this. It's also very reliable, because it uses HTML::Parser for all the heavy lifting. HTML::TagFilter ROCKS.

Last edited by Hero Zzyzzx : April 23rd, 2002 at 06:04 PM.

Reply With Quote
  #7  
Old April 23rd, 2002, 06:23 PM
the_pedestrian the_pedestrian is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Posts: 210 the_pedestrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
spot on

hero, this is exactly what im looking for....id read the HTML:Parser et al stuff....but it seemed to be coming from a different angle - extracting HTML from a document...not replacing HTML into a document.

"kludgy" was a very apt description of my system

ill be checking that out further....it did occur to me that if someone was going to learn 'my' system of writing tags...they might as well learn the HTML way.

can the tag parser force, for example, a link to be "_newwindow"...s'pose ill just have to suck it and see.


thanks again.
liked the slashdot article on CD burning - wait till they get a load of us!


mucho gracias

Last edited by the_pedestrian : April 23rd, 2002 at 07:20 PM.

Reply With Quote
  #8  
Old August 1st, 2002, 02:20 PM
Tzicha's Avatar
Tzicha Tzicha is offline
Here, not there
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 312 Tzicha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 36 sec
Reputation Power: 11
Exclamation CSS can contain 'executable' content

Don't forget that css, even when linked from an external file can contain so-called executable material. Some, such as the background-image property allow the loading of files from local or remote locations, with the URI('location') syntax.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > users editing their own CSS and security

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap