Currently I'm using Modernizr on all my sites and it turns out because of how it works it requires unsafe-inline
styles to be allowed. I am already not allowing inline scripts and unsafe-eval for scripts. Curious as to what security risks there are for allowing inline styles?
Allowing inline styles makes you susceptible to a the "other XSS". Cross Site Styling attacks.
The idea here is that any places where a user can inject a style attribute into your document they can modify the appearance of your page any way they want. I'll list a couple potential attacks ordered by increasing severity:
- They could turn your page pink, and make it look silly.
- They could modify the text of your page, making it look like you're saying something offensive that could offend your readership audience.
- They could make user generated content, like a link they provided appear outside of the normal places where people expect to see user content, making it appear official. (eg, replacing a "Login" button on your site with their own link).
- Using a carefully crafted style rules they could send any information included on the page to external domains and expose or otherwise use that data maliciously against your users.
The fourth example, with the information being leaked to external domains could be entirely prevented in spite of the unsafe-inline
provided you ensure your other CSP rules never allow any kind of request to go to a untrusted or wildcard domain. But the first 3 will always be possible if you miss blocking a style attribute somewhere.
Mike West did a good talk on this for CSSConf a few years back for some more examples.
I agree with Jacob - please observe the following pattern (from MantisBT):
/**
* Print user font preference
* @return void
*/
function layout_user_font_preference() {
$t_font_family = config_get( 'font_family', null, null, ALL_PROJECTS );
echo '<style>', "\n";
echo '* { font-family: "' . $t_font_family . '"; } ', "\n";
echo 'h1, h2, h3, h4, h5 { font-family: "' . $t_font_family . '"; } ', "\n";
echo '</style>', "\n";
}
Will you create a temporary .css file for each user, just to provide script kiddies with audit tools a way to make a dollar ?
If you don't code - you won't make any error ! Going towards 0 bytes content with these absurdities ...
And if my user love his page pink or rainbow, then let the guy have it :)
Personally I find not using unsafe-inline for CSS is impractical. It means I have to use an external style sheet file for EVERY style. Coloring text, centering text etc. It can be done. You can do this by using a main style sheet "main.css" and a file sheet for every page ("index.css", "contect.css", etc). However I am not so stupid that I allow arbitrary code execution; I filter out all less then and grater then signs. I find this to be an unreasonable restriction. Blocking inline JavaScript is not as bad as blocking inline CSS. I can see blocking inline JavaScript. However I don't think I will do that ether. If you are careful to filter your less then and grater then signs (there are some other stupid things you can do besides not filtering these) if you don't make stupid mistakes that allows arbitrary code execution then you are safe. These inline blocks are only created to protect web developers that screw up there code in a way that allows arbitrary code execution. But the blocks make it a bit harder to code. So it's a trade off.
TLDR IMHO not worth blocking inline CSS, worth blocking inline JavaScript but unnecessary. I will NOT consider blocking inline CSS, I am not going to block inline JavaScript but I might consider it.
Experience: I am a web designer that designs in code using HTML CSS JavaScript and PHP. I have my own website that I coded by hand. And I validate with the official w3 validator. I keep up with web design standards like HTML5.
© 2022 - 2024 — McMap. All rights reserved.