WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
20527
[sg:low] Cross-domain access to stylesheet text should not be allowed
https://bugs.webkit.org/show_bug.cgi?id=20527
Summary
[sg:low] Cross-domain access to stylesheet text should not be allowed
Chris Evans
Reported
Tuesday, August 26, 2008 8:11:12 PM UTC
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.
Attachments
Patch
(4.10 KB, patch)
2009-10-31 04:26 PDT
,
Adam Barth
no flags
Details
Formatted Diff
Diff
Patch
(6.59 KB, patch)
2009-10-31 16:52 PDT
,
Adam Barth
sam
: review+
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
Sam Weinig
Comment 1
Tuesday, August 26, 2008 9:03:20 PM UTC
<
rdar://problem/6176957
>
Sam Weinig
Comment 2
Tuesday, August 26, 2008 9:05:57 PM UTC
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.
Chris Evans
Comment 3
Wednesday, August 27, 2008 1:49:06 AM UTC
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.
Chris Evans
Comment 4
Tuesday, January 27, 2009 10:44:49 PM UTC
Some minor frameworks do seem to randomize CSS style name (although the reason is not clear) so this may be worth fixing.
Chris Evans
Comment 5
Wednesday, April 8, 2009 11:06:15 PM UTC
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.
Adam Barth
Comment 6
Thursday, September 10, 2009 9:05:33 AM UTC
This seems low cost and a slight improvement. I, for one, would welcome a patch that changed our behavior to match Firefox.
Adam Barth
Comment 7
Saturday, October 31, 2009 12:04:36 PM UTC
Patch forthcoming.
Adam Barth
Comment 8
Saturday, October 31, 2009 12:26:46 PM UTC
Created
attachment 42250
[details]
Patch
Chris Evans
Comment 9
Saturday, October 31, 2009 11:17:26 PM UTC
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?
Adam Barth
Comment 10
Saturday, October 31, 2009 11:22:02 PM UTC
(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.
Chris Evans
Comment 11
Saturday, October 31, 2009 11:39:42 PM UTC
Ok. I'll be writing a test for some CSS issues I'm working on, so I can work these cases in.
Adam Barth
Comment 12
Sunday, November 1, 2009 12:52:01 AM UTC
Created
attachment 42263
[details]
Patch
Adam Barth
Comment 13
Sunday, November 1, 2009 12:55:10 AM UTC
> We should add a test for that case!
Added.
Sam Weinig
Comment 14
Monday, November 2, 2009 12:27:54 AM UTC
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.
Adam Barth
Comment 15
Monday, November 2, 2009 12:33:57 AM UTC
(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.
Adam Barth
Comment 16
Monday, November 2, 2009 12:36:07 AM UTC
Oh, there's another instance in the canvas code somewhere that does similar things for cross-origin images.
Chris Evans
Comment 17
Wednesday, November 4, 2009 10:40:23 PM UTC
Pinging reviewer :)
Adam Barth
Comment 18
Friday, November 6, 2009 6:57:16 AM UTC
http://trac.webkit.org/changeset/50587
Darin Adler
Comment 19
Saturday, April 24, 2010 12:30:32 AM UTC
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.
Adam Barth
Comment 20
Saturday, April 24, 2010 12:34:44 AM UTC
> 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.
Adam Barth
Comment 21
Saturday, April 24, 2010 12:36:09 AM UTC
> 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.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug