<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[212059] branches/safari-603-branch</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/212059">212059</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2017-02-09 22:36:45 -0800 (Thu, 09 Feb 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/211758">r211758</a>. rdar://problem/30096129</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari603branchLayoutTestsChangeLog">branches/safari-603-branch/LayoutTests/ChangeLog</a></li>
<li><a href="#branchessafari603branchSourceWebCoreChangeLog">branches/safari-603-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari603branchSourceWebCoreloaderDocumentThreadableLoadercpp">branches/safari-603-branch/Source/WebCore/loader/DocumentThreadableLoader.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCorepageFramecpp">branches/safari-603-branch/Source/WebCore/page/Frame.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCorepagePageh">branches/safari-603-branch/Source/WebCore/page/Page.h</a></li>
<li><a href="#branchessafari603branchSourceWebCoreplatformSchemeRegistrycpp">branches/safari-603-branch/Source/WebCore/platform/SchemeRegistry.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCoreplatformSchemeRegistryh">branches/safari-603-branch/Source/WebCore/platform/SchemeRegistry.h</a></li>
<li><a href="#branchessafari603branchSourceWebCoretestingInternalscpp">branches/safari-603-branch/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#branchessafari603branchSourceWebCoretestingInternalsh">branches/safari-603-branch/Source/WebCore/testing/Internals.h</a></li>
<li><a href="#branchessafari603branchSourceWebCoretestingInternalsidl">branches/safari-603-branch/Source/WebCore/testing/Internals.idl</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari603branchLayoutTestshttptestssecuritybypassingcorschecksforextensionurlsexpectedtxt">branches/safari-603-branch/LayoutTests/http/tests/security/bypassing-cors-checks-for-extension-urls-expected.txt</a></li>
<li><a href="#branchessafari603branchLayoutTestshttptestssecuritybypassingcorschecksforextensionurlshtml">branches/safari-603-branch/LayoutTests/http/tests/security/bypassing-cors-checks-for-extension-urls.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari603branchLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/LayoutTests/ChangeLog (212058 => 212059)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/LayoutTests/ChangeLog        2017-02-10 06:36:40 UTC (rev 212058)
+++ branches/safari-603-branch/LayoutTests/ChangeLog        2017-02-10 06:36:45 UTC (rev 212059)
</span><span class="lines">@@ -1,5 +1,19 @@
</span><span class="cx"> 2017-02-09 Matthew Hanson <matthew_hanson@apple.com>
</span><span class="cx">
</span><ins>+ Merge r211758. rdar://problem/30096129
+
+ 2017-02-06 Youenn Fablet <youennf@gmail.com>
+
+ Allow some schemes to opt-out of CORS
+ https://bugs.webkit.org/show_bug.cgi?id=167795
+
+ Reviewed by Alex Christensen.
+
+ * http/tests/security/bypassing-cors-checks-for-extension-urls-expected.txt: Added.
+ * http/tests/security/bypassing-cors-checks-for-extension-urls.html: Added.
+
+2017-02-09 Matthew Hanson <matthew_hanson@apple.com>
+
</ins><span class="cx"> Merge r211667. rdar://problem/28193222
</span><span class="cx">
</span><span class="cx"> 2017-02-03 Myles C. Maxfield <mmaxfield@apple.com>
</span></span></pre></div>
<a id="branchessafari603branchLayoutTestshttptestssecuritybypassingcorschecksforextensionurlsexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/safari-603-branch/LayoutTests/http/tests/security/bypassing-cors-checks-for-extension-urls-expected.txt (0 => 212059)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/LayoutTests/http/tests/security/bypassing-cors-checks-for-extension-urls-expected.txt         (rev 0)
+++ branches/safari-603-branch/LayoutTests/http/tests/security/bypassing-cors-checks-for-extension-urls-expected.txt        2017-02-10 06:36:45 UTC (rev 212059)
</span><span class="lines">@@ -0,0 +1,8 @@
</span><ins>+CONSOLE MESSAGE: line 19: XMLHttpRequest cannot load safari-extension://test1. Cross origin requests are only supported for HTTP.
+This test ensures that XHR/Fetch will bypass CORS for user extension URLS in case the page is running user scripts.
+
+
+PASS Bypassing CORS on synchronous XHR - should trigger a CORS error message
+PASS Bypassing CORS on synchronous XHR - should not trigger a CORS error message
+PASS Bypassing CORS on asynchronous fetch - should not trigger a CORS error message
+
</ins></span></pre></div>
<a id="branchessafari603branchLayoutTestshttptestssecuritybypassingcorschecksforextensionurlshtml"></a>
<div class="addfile"><h4>Added: branches/safari-603-branch/LayoutTests/http/tests/security/bypassing-cors-checks-for-extension-urls.html (0 => 212059)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/LayoutTests/http/tests/security/bypassing-cors-checks-for-extension-urls.html         (rev 0)
+++ branches/safari-603-branch/LayoutTests/http/tests/security/bypassing-cors-checks-for-extension-urls.html        2017-02-10 06:36:45 UTC (rev 212059)
</span><span class="lines">@@ -0,0 +1,35 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+</head>
+</head>
+<body>
+<p>
+ This test ensures that XHR/Fetch will bypass CORS for user extension URLS in case the page is running user scripts.
+</p>
+<script>
+ if (!window.internals)
+ alert("This test requires WebKit internals API to work properly");
+
+ test(() => {
+ xhr = new XMLHttpRequest();
+ xhr.open("GET", "safari-extension://test1", false);
+ assert_throws({name: "NetworkError"}, () => { xhr.send() });
+ }, "Bypassing CORS on synchronous XHR - should trigger a CORS error message");
+
+ test(() => {
+ internals.setAsRunningUserScripts();
+
+ xhr = new XMLHttpRequest();
+ xhr.open("GET", "safari-extension://test3", false);
+ assert_throws({name: "NetworkError"}, () => { xhr.send() });
+ }, "Bypassing CORS on synchronous XHR - should not trigger a CORS error message");
+
+ promise_test((test) => {
+ return promise_rejects(test, new TypeError, fetch("safari-extension://test4"));
+ }, "Bypassing CORS on asynchronous fetch - should not trigger a CORS error message");
+</script>
+</body>
+</html>
</ins></span></pre></div>
<a id="branchessafari603branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/ChangeLog (212058 => 212059)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/ChangeLog        2017-02-10 06:36:40 UTC (rev 212058)
+++ branches/safari-603-branch/Source/WebCore/ChangeLog        2017-02-10 06:36:45 UTC (rev 212059)
</span><span class="lines">@@ -1,5 +1,38 @@
</span><span class="cx"> 2017-02-09 Matthew Hanson <matthew_hanson@apple.com>
</span><span class="cx">
</span><ins>+ Merge r211758. rdar://problem/30096129
+
+ 2017-02-06 Youenn Fablet <youennf@gmail.com>
+
+ Allow some schemes to opt-out of CORS
+ https://bugs.webkit.org/show_bug.cgi?id=167795
+
+ Reviewed by Alex Christensen.
+
+ Test: http/tests/security/bypassing-cors-checks-for-extension-urls.html
+
+ Adding the possibility to opt out of CORS for DocumentThreadableLoader clients (fetch and XHR).
+ This is made specific to the case of user extension URLs for pages running user scripts.
+ Introducing a boolean flag in Page for that purpose.
+ Introducing a helper routine in SchemeRegistry to centralize the various user script extension schemes.
+
+ * loader/DocumentThreadableLoader.cpp:
+ (WebCore::DocumentThreadableLoader::DocumentThreadableLoader):
+ * page/Frame.cpp:
+ (WebCore::Frame::injectUserScripts):
+ * page/Page.h:
+ (WebCore::Page::setAsRunningUserScripts):
+ (WebCore::Page::isRunningUserScripts):
+ * platform/SchemeRegistry.cpp:
+ (WebCore::SchemeRegistry::isUserExtensionScheme):
+ * platform/SchemeRegistry.h:
+ * testing/Internals.cpp:
+ (WebCore::Internals::setAsRunningUserScripts):
+ * testing/Internals.h:
+ * testing/Internals.idl:
+
+2017-02-09 Matthew Hanson <matthew_hanson@apple.com>
+
</ins><span class="cx"> Merge r211746. rdar://problem/30107622
</span><span class="cx">
</span><span class="cx"> 2017-02-06 Jer Noble <jer.noble@apple.com>
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoreloaderDocumentThreadableLoadercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/loader/DocumentThreadableLoader.cpp (212058 => 212059)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/loader/DocumentThreadableLoader.cpp        2017-02-10 06:36:40 UTC (rev 212058)
+++ branches/safari-603-branch/Source/WebCore/loader/DocumentThreadableLoader.cpp        2017-02-10 06:36:45 UTC (rev 212059)
</span><span class="lines">@@ -110,6 +110,11 @@
</span><span class="cx"> if (m_async && m_options.mode == FetchOptions::Mode::Cors)
</span><span class="cx"> m_originalHeaders = request.httpHeaderFields();
</span><span class="cx">
</span><ins>+ if (document.page() && document.page()->isRunningUserScripts() && SchemeRegistry::isUserExtensionScheme(request.url().protocol().toStringWithoutCopying())) {
+ m_options.mode = FetchOptions::Mode::NoCors;
+ m_options.filteringPolicy = ResponseFilteringPolicy::Disable;
+ }
+
</ins><span class="cx"> // As per step 11 of https://fetch.spec.whatwg.org/#main-fetch, data scheme (if same-origin data-URL flag is set) and about scheme are considered same-origin.
</span><span class="cx"> if (request.url().protocolIsData())
</span><span class="cx"> m_sameOriginRequest = options.sameOriginDataURLFlag == SameOriginDataURLFlag::Set;
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCorepageFramecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/page/Frame.cpp (212058 => 212059)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/page/Frame.cpp        2017-02-10 06:36:40 UTC (rev 212058)
+++ branches/safari-603-branch/Source/WebCore/page/Frame.cpp        2017-02-10 06:36:45 UTC (rev 212059)
</span><span class="lines">@@ -711,8 +711,10 @@
</span><span class="cx"> if (script.injectedFrames() == InjectInTopFrameOnly && ownerElement())
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- if (script.injectionTime() == injectionTime && UserContentURLPattern::matchesPatterns(document->url(), script.whitelist(), script.blacklist()))
</del><ins>+ if (script.injectionTime() == injectionTime && UserContentURLPattern::matchesPatterns(document->url(), script.whitelist(), script.blacklist())) {
+ m_page->setAsRunningUserScripts();
</ins><span class="cx"> m_script->evaluateInWorld(ScriptSourceCode(script.source(), script.url()), world);
</span><ins>+ }
</ins><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCorepagePageh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/page/Page.h (212058 => 212059)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/page/Page.h        2017-02-10 06:36:40 UTC (rev 212058)
+++ branches/safari-603-branch/Source/WebCore/page/Page.h        2017-02-10 06:36:45 UTC (rev 212059)
</span><span class="lines">@@ -391,6 +391,9 @@
</span><span class="cx"> void setResourceUsageOverlayVisible(bool);
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+ void setAsRunningUserScripts() { m_isRunningUserScripts = true; }
+ bool isRunningUserScripts() const { return m_isRunningUserScripts; }
+
</ins><span class="cx"> void setDebugger(JSC::Debugger*);
</span><span class="cx"> JSC::Debugger* debugger() const { return m_debugger; }
</span><span class="cx">
</span><span class="lines">@@ -769,6 +772,8 @@
</span><span class="cx"> std::optional<EventThrottlingBehavior> m_eventThrottlingBehaviorOverride;
</span><span class="cx">
</span><span class="cx"> std::unique_ptr<PerformanceMonitor> m_performanceMonitor;
</span><ins>+
+ bool m_isRunningUserScripts { false };
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> inline PageGroup& Page::group()
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoreplatformSchemeRegistrycpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/platform/SchemeRegistry.cpp (212058 => 212059)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/platform/SchemeRegistry.cpp        2017-02-10 06:36:40 UTC (rev 212058)
+++ branches/safari-603-branch/Source/WebCore/platform/SchemeRegistry.cpp        2017-02-10 06:36:45 UTC (rev 212059)
</span><span class="lines">@@ -357,4 +357,14 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+bool SchemeRegistry::isUserExtensionScheme(const String& scheme)
+{
+ UNUSED_PARAM(scheme);
+#if PLATFORM(MAC)
+ if (scheme == "safari-extension")
+ return true;
+#endif
+ return false;
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoreplatformSchemeRegistryh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/platform/SchemeRegistry.h (212058 => 212059)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/platform/SchemeRegistry.h        2017-02-10 06:36:40 UTC (rev 212058)
+++ branches/safari-603-branch/Source/WebCore/platform/SchemeRegistry.h        2017-02-10 06:36:45 UTC (rev 212059)
</span><span class="lines">@@ -99,6 +99,8 @@
</span><span class="cx"> WEBCORE_EXPORT static void registerURLSchemeAsCachePartitioned(const String& scheme);
</span><span class="cx"> static bool shouldPartitionCacheForURLScheme(const String& scheme);
</span><span class="cx"> #endif
</span><ins>+
+ static bool isUserExtensionScheme(const String& scheme);
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/testing/Internals.cpp (212058 => 212059)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/testing/Internals.cpp        2017-02-10 06:36:40 UTC (rev 212058)
+++ branches/safari-603-branch/Source/WebCore/testing/Internals.cpp        2017-02-10 06:36:45 UTC (rev 212059)
</span><span class="lines">@@ -3646,4 +3646,10 @@
</span><span class="cx"> return accessKeyModifierStrings;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void Internals::setAsRunningUserScripts(Document& document)
+{
+ if (document.page())
+ document.page()->setAsRunningUserScripts();
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/testing/Internals.h (212058 => 212059)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/testing/Internals.h        2017-02-10 06:36:40 UTC (rev 212058)
+++ branches/safari-603-branch/Source/WebCore/testing/Internals.h        2017-02-10 06:36:45 UTC (rev 212059)
</span><span class="lines">@@ -530,6 +530,8 @@
</span><span class="cx">
</span><span class="cx"> Vector<String> accessKeyModifiers() const;
</span><span class="cx">
</span><ins>+ void setAsRunningUserScripts(Document&);
+
</ins><span class="cx"> private:
</span><span class="cx"> explicit Internals(Document&);
</span><span class="cx"> Document* contextDocument() const;
</span></span></pre></div>
<a id="branchessafari603branchSourceWebCoretestingInternalsidl"></a>
<div class="modfile"><h4>Modified: branches/safari-603-branch/Source/WebCore/testing/Internals.idl (212058 => 212059)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-603-branch/Source/WebCore/testing/Internals.idl        2017-02-10 06:36:40 UTC (rev 212058)
+++ branches/safari-603-branch/Source/WebCore/testing/Internals.idl        2017-02-10 06:36:45 UTC (rev 212059)
</span><span class="lines">@@ -503,4 +503,6 @@
</span><span class="cx"> [Conditional=POINTER_LOCK] boolean pageHasPointerLock();
</span><span class="cx">
</span><span class="cx"> sequence<DOMString> accessKeyModifiers();
</span><ins>+
+ [CallWith=Document] void setAsRunningUserScripts();
</ins><span class="cx"> };
</span></span></pre>
</div>
</div>
</body>
</html>