The following HTML raises security exceptions in Firefox and Opera (IE7 does not appear to support these APIs). Webkit nightly runs the code fine: <html> <head> <link rel="stylesheet" href="https://mail.google.com/mail"> <script> function func() { var sheet = document.styleSheets[0]; try { var len = sheet.cssRules.length; alert(len); alert(sheet.cssRules.item(0).cssText); } catch (e) { alert("Error name: " + e.name + ". Error message: " + e.message); } } </script> </head> <body onload="func()"> <div id="blah" class="show"> </body> </html> It's not a huge security hole because cross domain CSS property values can be accessed via e.g. window.getComputedStyle(ele, null).getPropertyValue('blah') I can think of a couple of minor threat scenarios this would protect against: - If a paranoid site wanted to hide sensitive property values (a customized background-url perhaps?) it would use randomized style names. - Any over-tolerance in the CSS parser would expose less of the HTML page. It's certainly worth bringing into line with Firefox in case there is some future attack I haven't thought about.
<rdar://problem/6176957>
I don't understand what this would be protecting against if all the values are accessible by other means. I am not sure there is much value in changing this if the only reason is to be brought in line with Firefox.
The values are accessible but ONLY if you know the style name. Some web site out there may well use unpredictable style names to protect against this. Other threats may pop up in the future; I'd rather just be safe rather than waiting for a problem.
Some minor frameworks do seem to randomize CSS style name (although the reason is not clear) so this may be worth fixing.
Hmm... this would actually permit cross-domain theft of this (and related constructs): {} hexadecimal_or_ascii_security_token {} Because the lax CSS parser will pull that selector name (plus empty selector) out of the middle of some non-CSS target cross domain resource.
This seems low cost and a slight improvement. I, for one, would welcome a patch that changed our behavior to match Firefox.
Patch forthcoming.
Created attachment 42250 [details] Patch
Nice patch Adam :) I had some random q's: 1) Does this prevent access at the same place in the object tree as FF? i.e., getting cssRules object as opposed to the actual stylesheet object? 2) We've had trouble in this area where we didn't account for any redirects in the security check. Is that taken care of? 3) It just occurred to me that Firefox had an interesting bug where it would expose the eventual redirect destination (including sensitive URL params :) of the "href" attribute on a stylesheet. Hopefully we're good here?
(In reply to comment #9) > 1) Does this prevent access at the same place in the object tree as FF? i.e., > getting cssRules object as opposed to the actual stylesheet object? Yes. Firefox throws an exception here. We just return null, but the mediation point is the same. > 2) We've had trouble in this area where we didn't account for any redirects in > the security check. Is that taken care of? We should add a test for that case! My understanding is that this code is checking against the final URL, just like access to an iframe is based on the final URL of the content loaded in the frame. > 3) It just occurred to me that Firefox had an interesting bug where it would > expose the eventual redirect destination (including sensitive URL params :) of > the "href" attribute on a stylesheet. Hopefully we're good here? No idea. I recommend writing a test. If we pass the test, great! We can check it in and we won't regress. If we fail the test, that's the first step towards fixing the problem.
Ok. I'll be writing a test for some CSS issues I'm working on, so I can work these cases in.
Created attachment 42263 [details] Patch
> We should add a test for that case! Added.
This doesn't really seem like the correct layer to be doing this check. All the other same-origin checks exist in the JS bindings layer, so that other bindings are not changed.
(In reply to comment #14) > This doesn't really seem like the correct layer to be doing this check. All > the other same-origin checks exist in the JS bindings layer, so that other > bindings are not changed. I modelled this check after similar checks that we do in WebCore for XMLHttpRequest, XSL style sheets, and external XML entities. I actually had the check in the bindings layer in my original patch (not posted). I can move it back if you like.
Oh, there's another instance in the canvas code somewhere that does similar things for cross-origin images.
Pinging reviewer :)
http://trac.webkit.org/changeset/50587
This breaks a technique where a site: 1) Puts its CSS on a different server. Putting subresources in a separate domain can be useful so that the HTTP GET does not include any cookies and also so you can do different types of caching and network acceleration. 2) Uses JavaScript to iterate the CSS so it can wait for all the CSS images to load before doing something. The Safari welcome screen webpage at http://www.apple.com/safari/welcome/ makes use of this technique.
> The Safari welcome screen webpage at http://www.apple.com/safari/welcome/ makes > use of this technique. How does the Safari welcome page work in Firefox? We're aiming to match FF here.
> How does the Safari welcome page work in Firefox? We're aiming to match FF > here. "Download Safari 4 to view this page." I guess that page doesn't work in other browsers.