John :: Affirming Consequents, Denying Antecedents ([info]idonotlikepeas) wrote in [info]lj_support,

The CSS Cleaner and You: Partners in History

Some folks have wondered what the mysterious messages about "suspect CSS" mean. Now's your chance to find out!

A brief introduction for the folks who may not have heard about this: CSS, AKA Cascading Style Sheets, are the tool used on well-behaved web pages to send style information to your browser; layout, color, positioning, and so on. HTML describes what an element is (a paragraph, a header, an emphasized word, a link) and stylesheets tell your browser how that should be rendered (separate all paragraphs by seven pixels, make every header eighteen-point bold text, emphasize words by coloring them orange, links should be underlined and purple). Most S1 overrides and S2 styles use CSS to create certain looks for your journal, and S2 styles actually have a large box which you can use to enter your own CSS code to override the style's code if you like.

There's an unfortunate consequence to that last part, though: some unscrupulous journal owners could put harmful code in their CSS, that exploited vulnerabilities in some browsers to create unfortunate consequences. The CSS Cleaner is the solution to that problem: it looks for things that look nasty in the CSS code and yanks those things out before transmitting it to the client. Unfortunately, some people may have perfectly innocent CSS code which /looks/ like hostile code and also gets edited out. This post is meant to explain what the CSS cleaner does, so that volunteers working in Styles can understand why the messages are showing up and what to do about them. (And, e.g., write tutorials in howto about fixing problems, etc.)

Please note that this post is based only on my reading of the CSS cleaner. I didn't write the thing, so I may be missing some intricacy; I am certain that I'll be corrected if that's the case. Largely, though, this information should be correct, since the code is relatively straightforward. I will edit this post to accommodate any corrections that need to be made.

The CSS cleaner does two scans of the code; once before removing the comments from it, and once afterwards. (This prevents tricky things like having a hostile instruction with a giant comment in the middle, which a browser would ignore but a CSS cleaner might miss.) Whitespace is also ignored. So code which is separated by large stretches of comments and line breaks may still be stripped, and that can be harder to detect. Before the cleaner begins its scan, it converts HTML entities into their corresponding character values. So, for instance, % would become %.

The following table summarizes what is removed and what it is replaced with. In each case, the "replaced with" message will look like this: /* suspect CSS: [message] */. (The /* and */ are signals to browsers that the code in between is a comment, not to be handled as CSS code.) In stylesheets, the code will also be marked with the text /* Cleaned CSS: */ whether it's been stripped or not. (You can also add style information to HTML elements directly. That code will be checked, but not marked in this way.)

Text Error Message How to Avoid
non-standard characters low bytes or high bytes Only use standard ASCII characters. (Things you can type on an English keyboard.)
<foo start HTML tag Don't follow < with a character. (Better yet, just don't use <.)
\0, \1, \2, ..., \9, \a, \b, ..., \f backslash hex Don't put \ in front of any numbers or any of the letters a-f.
@import [foo] import rule Don't import external stylesheets. If you need code from them, copy and paste it to your stylesheet directly.
@charset [foo] charset rule Don't manually set the character set in your stylesheet.
&# followed by anything except a number found irregular &# Don't use those symbols in order unless you're making a character entity. (In which case you need a number there.)
</ close HTML tag Don't use this anywhere in your CSS code.
data: [foo] potential scripting: data: See above
javascript potential scripting: javascript Ditto
jscript potential scripting: jscript "
livescript potential scripting: livescript "
vbscript potential scripting: vbscript "
expression potential scripting: expression "
eval potential scripting: eval "
cookie potential scripting: cookie "
window potential scripting: window "
parent potential scripting: parent "
this potential scripting: this "
behavior potential scripting: behavior "
behaviour potential scripting: behaviour "
moz-binding potential scripting: moz-binding "

Phew. Now, keep in mind this text can be anywhere in your code. For instance, the following (completely innocent) code would get my CSS axed in four separate ways:

.this-sucks { /* I really hate JavaScript or "livescript" stuff, and also <font> tags. */
   color: #000000;
}

And that's about it. If you've got any questions or comments... well, you know what to do!

Tags: officially unofficial, officially unofficial: css cleaner

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    Your IP address will be recorded 

  • 15 comments

[info]grrliz

August 6 2006, 17:12:55 UTC 5 years ago

Out of curiosity does this CSS Cleaner give you the "/* Cleaned CSS: */" comments in your style sheet even if you don't have errors?

[info]idonotlikepeas

August 7 2006, 13:28:05 UTC 5 years ago

Yep!

[info]right

August 6 2006, 17:42:31 UTC 5 years ago

why aren't you a merit Styles SH?

[info]idonotlikepeas

August 7 2006, 13:28:23 UTC 5 years ago

Because I don't do the work. Can't get SH in Styles if you never touch it.

[info]right

August 7 2006, 13:46:29 UTC 5 years ago

you should totally do the work! this was great, thanks for writing it.

[info]seaofdestiny

August 6 2006, 18:10:57 UTC 5 years ago

So, for instance, &#138; would become Š.

I should hope not.

Perhaps a better example would have been that &#233; becomes é.

(Short reason: HTML's document character set is ISO 10646. I'll post a longer/clearer comment if you want.)

[info]idonotlikepeas

August 7 2006, 13:31:18 UTC 5 years ago

Updated to a more appropriate example.

[info]maidenus

August 6 2006, 18:12:38 UTC 5 years ago

*nods* Very informative. :D

[info]coffeechica

August 7 2006, 01:59:11 UTC 5 years ago

Bless you for this. There are no other words, just...bless you for this.

[info]bridgetester

August 7 2006, 03:37:40 UTC 5 years ago

This could make a good howto. :)

[info]dragonelf_2002

August 7 2006, 12:27:36 UTC 5 years ago

I second that.

[info]foxfirefey

August 19 2006, 04:18:19 UTC 5 years ago

I'd love to integrate this into here with credit, if it's okay with you. (And it's okay if it's not okay, the link does suffice!)

[info]idonotlikepeas

August 23 2006, 02:38:06 UTC 5 years ago

That is entirely OK with me. Although if you're crediting me, I would take it as a great kindness if you would mention that I don't support the main position implied by your URL. (That is, I am not an anti-LJ-ads activist.)

Don't need to make a big deal out of it, but I've had enough people misinterpret my viewpoints based on things my name appears near that I'd like to pre-empt it if possible. :)

[info]foxfirefey

August 26 2006, 20:13:30 UTC 5 years ago

Your concerns are entirely understood and appreciated! I finally managed to get around to translating the post into Mediawiki format and you're welcome to go and see and make sure I mentioned it correctly, and if you want me to change it in any way, don't hesitate to ask. Thank you very much for all the work you put into make this!

[info]camomiletea

March 17 2008, 02:20:03 UTC 4 years ago

An addition is needed to this post, because LJ now strips CSS if it suspects that you are trying to futz with the ads. Some info: http://community.livejournal.com/support_styles/173553.html?mode=reply

I also kind of want to move it to [info]armiebootcamp so the information is all in one place.
Create an Account
Forgot your login or password?
Facebook Twitter More login options
English • Español • Deutsch • Русский…