Commit 31234102 authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

Follow up on stopping setting CORS flag for data URLs

 - Replace |url.ProtocolIsData() || origin->CanRequest(url)|
   with |origin->CanReadContent(url)|.
 - Remove cross-origin settings for data URLs in workers as data URLs
   are now considered as same-origin.

This is a follow up for [1].

1: https://chromium-review.googlesource.com/c/chromium/src/+/1160126

Bug: 870173
Change-Id: Ie95e82c57882e4ce7d52e8ab0607c81e4b18c171
Reviewed-on: https://chromium-review.googlesource.com/1177472
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarHiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587955}
parent cee4208c
...@@ -116,9 +116,7 @@ bool ExecutionContext::ShouldSanitizeScriptError( ...@@ -116,9 +116,7 @@ bool ExecutionContext::ShouldSanitizeScriptError(
if (cors_status == kOpaqueResource) if (cors_status == kOpaqueResource)
return true; return true;
const KURL& url = CompleteURL(source_url); const KURL& url = CompleteURL(source_url);
if (url.ProtocolIsData()) return !(GetSecurityOrigin()->CanReadContent(url) ||
return false;
return !(GetSecurityOrigin()->CanRequest(url) ||
cors_status == kSharableCrossOrigin); cors_status == kSharableCrossOrigin);
} }
......
...@@ -128,10 +128,6 @@ void WebSharedWorkerImpl::OnShadowPageInitialized() { ...@@ -128,10 +128,6 @@ void WebSharedWorkerImpl::OnShadowPageInitialized() {
network::mojom::FetchRequestMode::kSameOrigin; network::mojom::FetchRequestMode::kSameOrigin;
network::mojom::FetchCredentialsMode fetch_credentials_mode = network::mojom::FetchCredentialsMode fetch_credentials_mode =
network::mojom::FetchCredentialsMode::kSameOrigin; network::mojom::FetchCredentialsMode::kSameOrigin;
if ((static_cast<KURL>(script_request_url_)).ProtocolIsData()) {
fetch_request_mode = network::mojom::FetchRequestMode::kNoCORS;
fetch_credentials_mode = network::mojom::FetchCredentialsMode::kInclude;
}
main_script_loader_->LoadTopLevelScriptAsynchronously( main_script_loader_->LoadTopLevelScriptAsynchronously(
*shadow_page_->GetDocument(), script_request_url_, *shadow_page_->GetDocument(), script_request_url_,
......
...@@ -57,8 +57,7 @@ KURL AbstractWorker::ResolveURL(ExecutionContext* execution_context, ...@@ -57,8 +57,7 @@ KURL AbstractWorker::ResolveURL(ExecutionContext* execution_context,
// We can safely expose the URL in the following exceptions, as these checks // We can safely expose the URL in the following exceptions, as these checks
// happen synchronously before redirection. JavaScript receives no new // happen synchronously before redirection. JavaScript receives no new
// information. // information.
if (!script_url.ProtocolIsData() && if (!execution_context->GetSecurityOrigin()->CanReadContent(script_url)) {
!execution_context->GetSecurityOrigin()->CanRequest(script_url)) {
exception_state.ThrowSecurityError( exception_state.ThrowSecurityError(
"Script at '" + script_url.ElidedString() + "Script at '" + script_url.ElidedString() +
"' cannot be accessed from origin '" + "' cannot be accessed from origin '" +
......
...@@ -172,10 +172,6 @@ void DedicatedWorker::Start() { ...@@ -172,10 +172,6 @@ void DedicatedWorker::Start() {
network::mojom::FetchRequestMode::kSameOrigin; network::mojom::FetchRequestMode::kSameOrigin;
network::mojom::FetchCredentialsMode fetch_credentials_mode = network::mojom::FetchCredentialsMode fetch_credentials_mode =
network::mojom::FetchCredentialsMode::kSameOrigin; network::mojom::FetchCredentialsMode::kSameOrigin;
if (script_request_url_.ProtocolIsData()) {
fetch_request_mode = network::mojom::FetchRequestMode::kNoCORS;
fetch_credentials_mode = network::mojom::FetchCredentialsMode::kInclude;
}
classic_script_loader_ = WorkerClassicScriptLoader::Create(); classic_script_loader_ = WorkerClassicScriptLoader::Create();
classic_script_loader_->LoadTopLevelScriptAsynchronously( classic_script_loader_->LoadTopLevelScriptAsynchronously(
*GetExecutionContext(), script_request_url_, *GetExecutionContext(), script_request_url_,
......
...@@ -270,11 +270,7 @@ bool CalculateCORSFlag(const KURL& url, ...@@ -270,11 +270,7 @@ bool CalculateCORSFlag(const KURL& url,
// CORS needs a proper origin (including a unique opaque origin). If the // CORS needs a proper origin (including a unique opaque origin). If the
// request doesn't have one, CORS should not work. // request doesn't have one, CORS should not work.
DCHECK(origin); DCHECK(origin);
return !origin->CanReadContent(url);
if (url.ProtocolIsData())
return false;
return !origin->CanRequest(url);
} }
} // namespace CORS } // namespace CORS
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment