Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(852)

Side by Side Diff: content/browser/service_worker/service_worker_version.cc

Issue 980383004: Relax same-origin policy for ServiceWorker openWindow() in Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reject Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_version.h" 5 #include "content/browser/service_worker/service_worker_version.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "content/browser/child_process_security_policy_impl.h"
14 #include "content/browser/message_port_message_filter.h" 15 #include "content/browser/message_port_message_filter.h"
15 #include "content/browser/message_port_service.h" 16 #include "content/browser/message_port_service.h"
16 #include "content/browser/service_worker/embedded_worker_instance.h" 17 #include "content/browser/service_worker/embedded_worker_instance.h"
17 #include "content/browser/service_worker/embedded_worker_registry.h" 18 #include "content/browser/service_worker/embedded_worker_registry.h"
18 #include "content/browser/service_worker/service_worker_context_core.h" 19 #include "content/browser/service_worker/service_worker_context_core.h"
19 #include "content/browser/service_worker/service_worker_context_wrapper.h" 20 #include "content/browser/service_worker/service_worker_context_wrapper.h"
20 #include "content/browser/service_worker/service_worker_registration.h" 21 #include "content/browser/service_worker/service_worker_registration.h"
21 #include "content/browser/service_worker/service_worker_utils.h" 22 #include "content/browser/service_worker/service_worker_utils.h"
22 #include "content/browser/storage_partition_impl.h" 23 #include "content/browser/storage_partition_impl.h"
23 #include "content/common/service_worker/service_worker_messages.h" 24 #include "content/common/service_worker/service_worker_messages.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 url, Referrer::SanitizeForRequest( 265 url, Referrer::SanitizeForRequest(
265 url, Referrer(script_url, blink::WebReferrerPolicyDefault)), 266 url, Referrer(script_url, blink::WebReferrerPolicyDefault)),
266 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 267 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
267 true /* is_renderer_initiated */); 268 true /* is_renderer_initiated */);
268 269
269 GetContentClient()->browser()->OpenURL( 270 GetContentClient()->browser()->OpenURL(
270 browser_context, params, 271 browser_context, params,
271 base::Bind(&DidOpenURL, callback)); 272 base::Bind(&DidOpenURL, callback));
272 } 273 }
273 274
274 void KillEmbeddedWorkerProcess(int process_id, ResultCode code) {
275 DCHECK_CURRENTLY_ON(BrowserThread::UI);
276
277 RenderProcessHost* render_process_host =
278 RenderProcessHost::FromID(process_id);
279 if (render_process_host->GetHandle() != base::kNullProcessHandle)
280 render_process_host->ReceivedBadMessage();
281 }
282
283 void ClearTick(base::TimeTicks* time) { 275 void ClearTick(base::TimeTicks* time) {
284 *time = base::TimeTicks(); 276 *time = base::TimeTicks();
285 } 277 }
286 278
287 void RestartTick(base::TimeTicks* time) { 279 void RestartTick(base::TimeTicks* time) {
288 *time = base::TimeTicks().Now(); 280 *time = base::TimeTicks().Now();
289 } 281 }
290 282
291 base::TimeDelta GetTickDuration(const base::TimeTicks& time) { 283 base::TimeDelta GetTickDuration(const base::TimeTicks& time) {
292 if (time.is_null()) 284 if (time.is_null())
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 if (!callback) { 1151 if (!callback) {
1160 NOTREACHED() << "Got unexpected message: " << request_id; 1152 NOTREACHED() << "Got unexpected message: " << request_id;
1161 return; 1153 return;
1162 } 1154 }
1163 1155
1164 scoped_refptr<ServiceWorkerVersion> protect(this); 1156 scoped_refptr<ServiceWorkerVersion> protect(this);
1165 callback->Run(SERVICE_WORKER_OK, accept_connection); 1157 callback->Run(SERVICE_WORKER_OK, accept_connection);
1166 RemoveCallbackAndStopIfDoomed(&cross_origin_connect_callbacks_, request_id); 1158 RemoveCallbackAndStopIfDoomed(&cross_origin_connect_callbacks_, request_id);
1167 } 1159 }
1168 1160
1169 void ServiceWorkerVersion::OnOpenWindow(int request_id, const GURL& url) { 1161 void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) {
1170 // Just abort if we are shutting down. 1162 // Just abort if we are shutting down.
1171 if (!context_) 1163 if (!context_)
1172 return; 1164 return;
1173 1165
1174 if (url.GetOrigin() != script_url_.GetOrigin()) { 1166 // Blink consider all about: scheme URLs as about:blank. We need to sanitize
1175 // There should be a same origin check by Blink, if the request is still not 1167 // them accordingly to prevent CanRequestURL() call below to fail on them.
falken 2015/03/08 12:23:49 This is kinda inconsistent now... why not just let
mlamouri (slow - plz ping) 2015/03/08 14:34:12 I've updated the comment to have it match RPHImpl:
mlamouri (slow - plz ping) 2015/03/08 14:34:12 I've updated the comment to have it match RPHImpl:
falken 2015/03/08 15:01:50 Ah I see, makes sense.
1176 // same origin, the process might be compromised and should be eliminated. 1168 if (url.SchemeIs(url::kAboutScheme))
1177 DVLOG(1) << "Received a cross origin openWindow() request from a service " 1169 url = GURL(url::kAboutBlankURL);
1178 "worker. Killing associated process."; 1170
1179 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1171 // This call will check whether the process should be able to access the given
1180 base::Bind(&KillEmbeddedWorkerProcess, 1172 // URL. It is possible to receive requests to open such URLs because the
1181 embedded_worker_->process_id(), 1173 // renderer side checks are slightly different. For example, view-source
1182 RESULT_CODE_KILLED_BAD_MESSAGE)); 1174 // scheme will not be filtered out by Blink. This is the reason why failing
1175 // that call will reject the promise instead of killing the renderer.
falken 2015/03/08 12:23:49 nits: "such URLs" reads like "URLs that the proces
mlamouri (slow - plz ping) 2015/03/08 14:34:12 Done.
1176 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL(
1177 embedded_worker_->process_id(), url)) {
1178 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError(
1179 request_id, url.spec() + " cannot be opened."));
1183 return; 1180 return;
1184 } 1181 }
1185 1182
1186 BrowserThread::PostTask( 1183 BrowserThread::PostTask(
1187 BrowserThread::UI, FROM_HERE, 1184 BrowserThread::UI, FROM_HERE,
1188 base::Bind(&OpenWindowOnUI, 1185 base::Bind(&OpenWindowOnUI,
1189 url, 1186 url,
1190 script_url_, 1187 script_url_,
1191 embedded_worker_->process_id(), 1188 embedded_worker_->process_id(),
1192 make_scoped_refptr(context_->wrapper()), 1189 make_scoped_refptr(context_->wrapper()),
1193 base::Bind(&ServiceWorkerVersion::DidOpenWindow, 1190 base::Bind(&ServiceWorkerVersion::DidOpenWindow,
1194 weak_factory_.GetWeakPtr(), 1191 weak_factory_.GetWeakPtr(),
1195 request_id))); 1192 request_id)));
1196 } 1193 }
1197 1194
1198 void ServiceWorkerVersion::DidOpenWindow(int request_id, 1195 void ServiceWorkerVersion::DidOpenWindow(int request_id,
1199 int render_process_id, 1196 int render_process_id,
1200 int render_frame_id) { 1197 int render_frame_id) {
1201 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1198 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1202 1199
1203 if (running_status() != RUNNING) 1200 if (running_status() != RUNNING)
1204 return; 1201 return;
1205 1202
1206 if (render_process_id == ChildProcessHost::kInvalidUniqueID && 1203 if (render_process_id == ChildProcessHost::kInvalidUniqueID &&
1207 render_frame_id == MSG_ROUTING_NONE) { 1204 render_frame_id == MSG_ROUTING_NONE) {
1208 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError(request_id)); 1205 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError(
1206 request_id, "Something went wrong while trying to open the window"));
falken 2015/03/08 12:23:49 nit: Add a period to be consistent with the error
mlamouri (slow - plz ping) 2015/03/08 14:34:12 Done.
1209 return; 1207 return;
1210 } 1208 }
1211 1209
1212 for (const auto& it : controllee_map_) { 1210 for (const auto& it : controllee_map_) {
1213 const ServiceWorkerProviderHost* provider_host = it.first; 1211 const ServiceWorkerProviderHost* provider_host = it.first;
1214 if (provider_host->process_id() != render_process_id || 1212 if (provider_host->process_id() != render_process_id ||
1215 provider_host->frame_id() != render_frame_id) { 1213 provider_host->frame_id() != render_frame_id) {
1216 continue; 1214 continue;
1217 } 1215 }
1218 1216
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 int request_id) { 1585 int request_id) {
1588 callbacks->Remove(request_id); 1586 callbacks->Remove(request_id);
1589 if (is_doomed_) { 1587 if (is_doomed_) {
1590 // The stop should be already scheduled, but try to stop immediately, in 1588 // The stop should be already scheduled, but try to stop immediately, in
1591 // order to release worker resources soon. 1589 // order to release worker resources soon.
1592 StopWorkerIfIdle(); 1590 StopWorkerIfIdle();
1593 } 1591 }
1594 } 1592 }
1595 1593
1596 } // namespace content 1594 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698