Bug 181460 - REGRESSION(r225650): The scores of MotionMark tests Multiply and Leaves dropped by 8%
Summary: REGRESSION(r225650): The scores of MotionMark tests Multiply and Leaves dropp...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on: 181583
Blocks:
  Show dependency treegraph
 
Reported: 2018-01-09 16:34 PST by Said Abou-Hallawa
Modified: 2018-01-18 10:54 PST (History)
13 users (show)

See Also:


Attachments
patch (1.66 KB, patch)
2018-01-10 02:51 PST, Antti Koivisto
rniwa: review+
Details | Formatted Diff | Diff
Archive of layout-test-results from ews106 for mac-sierra-wk2 (2.65 MB, application/zip)
2018-01-10 04:00 PST, EWS Watchlist
no flags Details
patch (1.65 KB, patch)
2018-01-10 07:54 PST, Antti Koivisto
no flags Details | Formatted Diff | Diff
patch (1.75 KB, patch)
2018-01-12 00:53 PST, Antti Koivisto
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Said Abou-Hallawa 2018-01-09 16:34:35 PST
After the change https://trac.webkit.org/changeset/225650>, the score of the MotionMark tests MotionMark tests Multiply and Leaves dropped by 8%.
Comment 1 Said Abou-Hallawa 2018-01-09 16:35:20 PST
<rdar://problem/36379776>
Comment 2 Antti Koivisto 2018-01-10 02:51:55 PST
Created attachment 330885 [details]
patch
Comment 3 EWS Watchlist 2018-01-10 04:00:17 PST
Comment on attachment 330885 [details]
patch

Attachment 330885 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/6018037

New failing tests:
webgl/1.0.2/conformance/uniforms/uniform-default-values.html
Comment 4 EWS Watchlist 2018-01-10 04:00:19 PST
Created attachment 330890 [details]
Archive of layout-test-results from ews106 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 5 Darin Adler 2018-01-10 07:49:31 PST
Comment on attachment 330885 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=330885&action=review

> Source/WebCore/css/parser/CSSParser.cpp:81
> +    , hasDocumentSecurityOrigin(document.baseURL() == baseURL ? true : document.securityOrigin().canRequest(baseURL))

I would use || here instead of ? :
Comment 6 Antti Koivisto 2018-01-10 07:54:09 PST
Created attachment 330906 [details]
patch
Comment 7 WebKit Commit Bot 2018-01-10 10:19:42 PST
Comment on attachment 330906 [details]
patch

Clearing flags on attachment: 330906

Committed r226721: <https://trac.webkit.org/changeset/226721>
Comment 8 WebKit Commit Bot 2018-01-10 10:19:44 PST
All reviewed patches have been landed.  Closing bug.
Comment 9 Alexey Proskuryakov 2018-01-10 15:36:40 PST
Comment on attachment 330906 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=330906&action=review

> Source/WebCore/css/parser/CSSParser.cpp:81
> +    , hasDocumentSecurityOrigin(document.baseURL() == baseURL || document.securityOrigin().canRequest(baseURL))

Can this tweak be made in canRequest to make it fast instead?

But also, I'm actually not sure if identical base URL is good enough for not having a security boundary, between origins in this case.
Comment 10 Darin Adler 2018-01-10 21:09:50 PST
Comment on attachment 330906 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=330906&action=review

>> Source/WebCore/css/parser/CSSParser.cpp:81
>> +    , hasDocumentSecurityOrigin(document.baseURL() == baseURL || document.securityOrigin().canRequest(baseURL))
> 
> Can this tweak be made in canRequest to make it fast instead?
> 
> But also, I'm actually not sure if identical base URL is good enough for not having a security boundary, between origins in this case.

As for the first question, maybe there is some other way to make a fast path, but we can’t make this exact optimization because canRequest does not have access to the document’s baseURL.

For the second question, I suggest we work together to turn your uncertainty into a test case.
Comment 11 Antti Koivisto 2018-01-11 02:06:22 PST
Yeah, SecurityOrigin::canRequest is inefficient (heap allocating a temporary SecurityOrigin for example) and could be optimized. However that will require bit more refactoring than should be done in this patch.

The logic here is about figuring out if the stylesheet content is readable via getMatchedCSSRules. The rules from the document itself are supposed to be accessible.
Comment 12 Ryosuke Niwa 2018-01-11 13:09:06 PST
(In reply to Antti Koivisto from comment #11)
> Yeah, SecurityOrigin::canRequest is inefficient (heap allocating a temporary
> SecurityOrigin for example) and could be optimized. However that will
> require bit more refactoring than should be done in this patch.
> 
> The logic here is about figuring out if the stylesheet content is readable
> via getMatchedCSSRules. The rules from the document itself are supposed to
> be accessible.

Are you sure this won't allow two null-origin documents to be treated as if sharing the same origin?
Comment 13 Antti Koivisto 2018-01-11 14:00:18 PST
> Are you sure this won't allow two null-origin documents to be treated as if
> sharing the same origin?

CSSParser parses rules either from the document or from stylesheets loaded by the document. I don't know how that would happen.
Comment 14 Ryosuke Niwa 2018-01-11 14:02:17 PST
(In reply to Antti Koivisto from comment #13)
> > Are you sure this won't allow two null-origin documents to be treated as if
> > sharing the same origin?
> 
> CSSParser parses rules either from the document or from stylesheets loaded
> by the document. I don't know how that would happen.

How about data URLs?
Comment 15 Antti Koivisto 2018-01-11 14:27:30 PST
> How about data URLs?

Can you be more specific about the scenario?
Comment 16 Alexey Proskuryakov 2018-01-11 15:01:49 PST
The new security check is different form the old one. Base URL can be anything, as the page author can specify any base with the <base> element. It's not the same URL that the security context is created from.

The sheetBaseURL argument seems like a misnomer. Chris and I looked at one caller, and it was actually passing final stylesheet URL there (the one after redirects). So that's controllable by the attacker, who can start with their own server, and redirect to the victim.

It does seem likely that documents with unique origins also get extra powers with this change.

But I can't follow CSS code enough to tell what the observable effect is. Given that we started with a security check, it probably is a security regression of some sort.
Comment 17 Chris Dumez 2018-01-11 15:10:19 PST
Comment on attachment 330906 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=330906&action=review

>>> Source/WebCore/css/parser/CSSParser.cpp:81
>>> +    , hasDocumentSecurityOrigin(document.baseURL() == baseURL || document.securityOrigin().canRequest(baseURL))
>> 
>> Can this tweak be made in canRequest to make it fast instead?
>> 
>> But also, I'm actually not sure if identical base URL is good enough for not having a security boundary, between origins in this case.
> 
> As for the first question, maybe there is some other way to make a fast path, but we can’t make this exact optimization because canRequest does not have access to the document’s baseURL.
> 
> For the second question, I suggest we work together to turn your uncertainty into a test case.

I would worry a lot less if this would be using document.url() rather than document.baseURL(). AFAIK, the document baseURL can be overridden by a <base> element and the document's securityOrigin comes from its URL, not its baseURL.
Comment 18 Alexey Proskuryakov 2018-01-11 16:07:35 PST
I think that document.url() would make the problem less obvious, but it needs to be explicitly demonstrated that unique origins are not a problem here. Even so, spreading slightly alternative security checks across the code base is a long term liability.
Comment 19 WebKit Commit Bot 2018-01-12 00:38:25 PST
Re-opened since this is blocked by bug 181583
Comment 20 Antti Koivisto 2018-01-12 00:53:45 PST
Created attachment 331184 [details]
patch
Comment 21 Alexey Proskuryakov 2018-01-12 10:06:02 PST
Comment on attachment 331184 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=331184&action=review

> Source/WebCore/ChangeLog:13
> +        Don't do the expensive security origin test if the supplied sheet base URL is null. This
> +        is true for rules coming from the same document.

I think that this is still changing the behavior when the document can't make requests to its own base URL (which is the case at least whenever there is a <base> element with a different origin URL, or for unique origins).
Comment 22 Antti Koivisto 2018-01-12 11:19:21 PST
> I think that this is still changing the behavior when the document can't
> make requests to its own base URL (which is the case at least whenever there
> is a <base> element with a different origin URL, or for unique origins).

The purpose of this bit is to block access to stylesheet via getMatchedCSSRules legacy API in cases where it could not be accessed otherwise via DOM. As you can see from CSSStyleSheet::canAccessRules normal access is granted when the sheet base URL is empty. 

(There is also a cors related test that is missing here, not sure if it is relevant).
Comment 23 Alexey Proskuryakov 2018-01-12 22:08:41 PST
> The purpose of this bit is to block access to stylesheet via getMatchedCSSRules legacy API in cases where it could not be accessed otherwise via DOM. As you can see from CSSStyleSheet::canAccessRules normal access is granted when the sheet base URL is empty. 

This may mean that the patch is OK, I didn't analyze CSS code deep enough to agree or disagree. But I think that it's missing a couple tests. We have three different behaviors here:

1. Original behavior before r226721.
2. Behavior with r226721.
3. Behavior with this patch.

It seems wrong to not have any tests differentiating between these.
Comment 24 Antti Koivisto 2018-01-17 06:49:00 PST
Improving test coverage would be nice but bit outside the scope of this bug.
Comment 25 youenn fablet 2018-01-18 07:24:56 PST
I agree canRequest should be optimized. We should not allocate a SecurityOrigin object, at least in the usual cases of http/data URLs. If we were doing so, the proposed additional check might no longer be needed.

If we land that patch, can we either add a FIXME in CSSParserContext::CSSParserContext or even better quickly come with an optimization of canRequest and revert this change at that time?
Comment 26 youenn fablet 2018-01-18 08:57:49 PST
Comment on attachment 331184 [details]
patch

Can we write a test with a data frame containing inline CSS?
That would also allow us to check what other browsers are doing there.
Comment 27 Antti Koivisto 2018-01-18 09:15:58 PST
Gecko never implemented getMatchedCSSRules in the first place and Chrome is trying to remove it (or already removed?).
Comment 28 WebKit Commit Bot 2018-01-18 09:50:05 PST
Comment on attachment 331184 [details]
patch

Clearing flags on attachment: 331184

Committed r227147: <https://trac.webkit.org/changeset/227147>
Comment 29 WebKit Commit Bot 2018-01-18 09:50:07 PST
All reviewed patches have been landed.  Closing bug.
Comment 30 Simon Fraser (smfr) 2018-01-18 10:54:38 PST
Comment on attachment 331184 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=331184&action=review

> Source/WebCore/css/parser/CSSParser.cpp:83
> +    

Extra blank line here.