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

Side by Side Diff: Source/modules/cachestorage/InspectorCacheStorageAgent.cpp

Issue 1177983007: Cache Storage: restrict access to secure origins (Blink-side) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: DevTools: Skip enumeration if access denied Created 5 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "config.h" 5 #include "config.h"
6 #include "modules/cachestorage/InspectorCacheStorageAgent.h" 6 #include "modules/cachestorage/InspectorCacheStorageAgent.h"
7 7
8 #include "core/InspectorBackendDispatcher.h" 8 #include "core/InspectorBackendDispatcher.h"
9 #include "core/InspectorTypeBuilder.h" 9 #include "core/InspectorTypeBuilder.h"
10 #include "core/dom/Document.h"
11 #include "core/dom/ExecutionContext.h"
12 #include "core/frame/Frame.h"
13 #include "core/page/Page.h"
14 #include "modules/cachestorage/CacheStorage.h"
10 #include "platform/JSONValues.h" 15 #include "platform/JSONValues.h"
11 #include "platform/heap/Handle.h" 16 #include "platform/heap/Handle.h"
12 #include "platform/weborigin/DatabaseIdentifier.h" 17 #include "platform/weborigin/DatabaseIdentifier.h"
13 #include "platform/weborigin/KURL.h" 18 #include "platform/weborigin/KURL.h"
14 #include "platform/weborigin/SecurityOrigin.h" 19 #include "platform/weborigin/SecurityOrigin.h"
15 #include "public/platform/Platform.h" 20 #include "public/platform/Platform.h"
16 #include "public/platform/WebServiceWorkerCache.h" 21 #include "public/platform/WebServiceWorkerCache.h"
17 #include "public/platform/WebServiceWorkerCacheError.h" 22 #include "public/platform/WebServiceWorkerCacheError.h"
18 #include "public/platform/WebServiceWorkerCacheStorage.h" 23 #include "public/platform/WebServiceWorkerCacheStorage.h"
19 #include "public/platform/WebServiceWorkerRequest.h" 24 #include "public/platform/WebServiceWorkerRequest.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 size_t pipe = id.find('|'); 64 size_t pipe = id.find('|');
60 if (pipe == WTF::kNotFound) { 65 if (pipe == WTF::kNotFound) {
61 *errorString = "Invalid cache id."; 66 *errorString = "Invalid cache id.";
62 return false; 67 return false;
63 } 68 }
64 *securityOrigin = id.substring(0, pipe); 69 *securityOrigin = id.substring(0, pipe);
65 *cacheName = id.substring(pipe + 1); 70 *cacheName = id.substring(pipe + 1);
66 return true; 71 return true;
67 } 72 }
68 73
69 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorage(ErrorString* errorSt ring, const String& securityOrigin)
70 {
71 RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(security Origin);
72 String identifier = createDatabaseIdentifierFromSecurityOrigin(secOrigin.get ());
73 OwnPtr<WebServiceWorkerCacheStorage> cache = adoptPtr(Platform::current()->c acheStorage(identifier));
74 if (!cache)
75 *errorString = "Could not find cache storage.";
76 return cache.release();
77 }
78
79 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorageAndNameForId(ErrorStr ing* errorString, const String& cacheId, String* cacheName)
80 {
81 String securityOrigin;
82 if (!parseCacheId(errorString, cacheId, &securityOrigin, cacheName)) {
83 return nullptr;
84 }
85 return assertCacheStorage(errorString, securityOrigin);
86 }
87
88 CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error) 74 CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error)
89 { 75 {
90 switch (*error) { 76 switch (*error) {
91 case WebServiceWorkerCacheErrorNotImplemented: 77 case WebServiceWorkerCacheErrorNotImplemented:
92 return CString("not implemented."); 78 return CString("not implemented.");
93 break; 79 break;
94 case WebServiceWorkerCacheErrorNotFound: 80 case WebServiceWorkerCacheErrorNotFound:
95 return CString("not found."); 81 return CString("not found.");
96 break; 82 break;
97 case WebServiceWorkerCacheErrorExists: 83 case WebServiceWorkerCacheErrorExists:
(...skipping 13 matching lines...) Expand all
111 RequestCacheNames(const String& securityOrigin, PassRefPtrWillBeRawPtr<Reque stCacheNamesCallback> callback) 97 RequestCacheNames(const String& securityOrigin, PassRefPtrWillBeRawPtr<Reque stCacheNamesCallback> callback)
112 : m_securityOrigin(securityOrigin) 98 : m_securityOrigin(securityOrigin)
113 , m_callback(callback) 99 , m_callback(callback)
114 { 100 {
115 } 101 }
116 102
117 ~RequestCacheNames() override { } 103 ~RequestCacheNames() override { }
118 104
119 void onSuccess(WebVector<WebString>* caches) 105 void onSuccess(WebVector<WebString>* caches)
120 { 106 {
121 RefPtr<Array<Cache>> array = Array<Cache>::create(); 107 RefPtr<Array<TypeBuilder::CacheStorage::Cache>> array = Array<TypeBuilde r::CacheStorage::Cache>::create();
122 for (size_t i = 0; i < caches->size(); i++) { 108 for (size_t i = 0; i < caches->size(); i++) {
123 String name = String((*caches)[i]); 109 String name = String((*caches)[i]);
124 RefPtr<Cache> entry = Cache::create() 110 RefPtr<TypeBuilder::CacheStorage::Cache> entry = TypeBuilder::CacheS torage::Cache::create()
125 .setSecurityOrigin(m_securityOrigin) 111 .setSecurityOrigin(m_securityOrigin)
126 .setCacheName(name) 112 .setCacheName(name)
127 .setCacheId(buildCacheId(m_securityOrigin, name)); 113 .setCacheId(buildCacheId(m_securityOrigin, name));
128 array->addItem(entry); 114 array->addItem(entry);
129 } 115 }
130 m_callback->sendSuccess(array); 116 m_callback->sendSuccess(array);
131 } 117 }
132 118
133 void onError(WebServiceWorkerCacheError* error) 119 void onError(WebServiceWorkerCacheError* error)
134 { 120 {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 371 }
386 372
387 private: 373 private:
388 String m_requestSpec; 374 String m_requestSpec;
389 String m_cacheName; 375 String m_cacheName;
390 RefPtrWillBePersistent<DeleteEntryCallback> m_callback; 376 RefPtrWillBePersistent<DeleteEntryCallback> m_callback;
391 }; 377 };
392 378
393 } // namespace 379 } // namespace
394 380
395 InspectorCacheStorageAgent::InspectorCacheStorageAgent() 381 InspectorCacheStorageAgent::InspectorCacheStorageAgent(Page* page)
396 : InspectorBaseAgent<InspectorCacheStorageAgent, InspectorFrontend::CacheSto rage>("CacheStorage") 382 : InspectorBaseAgent<InspectorCacheStorageAgent, InspectorFrontend::CacheSto rage>("CacheStorage")
383 , m_page(page)
397 { 384 {
398 } 385 }
399 386
400 InspectorCacheStorageAgent::~InspectorCacheStorageAgent() { } 387 InspectorCacheStorageAgent::~InspectorCacheStorageAgent() { }
401 388
402 DEFINE_TRACE(InspectorCacheStorageAgent) 389 DEFINE_TRACE(InspectorCacheStorageAgent)
403 { 390 {
404 InspectorBaseAgent::trace(visitor); 391 InspectorBaseAgent::trace(visitor);
405 } 392 }
406 393
407 void InspectorCacheStorageAgent::requestCacheNames(ErrorString* errorString, con st String& securityOrigin, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> cal lback) 394 void InspectorCacheStorageAgent::requestCacheNames(ErrorString* errorString, con st String& securityOrigin, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> cal lback)
408 { 395 {
396 RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(security Origin);
397 ExecutionContext* executionContext = assertExecutionContextForOrigin(errorSt ring, secOrigin.get());
398 if (!executionContext) {
399 callback->sendFailure(*errorString);
400 return;
401 }
402
403 if (!CacheStorage::canAccessCacheStorage(executionContext)) {
pfeldman 2015/08/03 23:53:49 Inspector should have access to everything, but we
jsbell 2015/08/04 00:14:53 Implicitly, entries won't exist if the page doesn'
404 // Don't treat this as an error, just don't attempt to open and enumerat e the caches.
405 callback->sendSuccess(Array<TypeBuilder::CacheStorage::Cache>::create()) ;
406 return;
407 }
408
409 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin); 409 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin);
410 if (!cache) { 410 if (!cache) {
411 callback->sendFailure(*errorString); 411 callback->sendFailure(*errorString);
412 return; 412 return;
413 } 413 }
414 cache->dispatchKeys(new RequestCacheNames(securityOrigin, callback)); 414 cache->dispatchKeys(new RequestCacheNames(securityOrigin, callback));
415 } 415 }
416 416
417 void InspectorCacheStorageAgent::requestEntries(ErrorString* errorString, const String& cacheId, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<RequestEntr iesCallback> callback) 417 void InspectorCacheStorageAgent::requestEntries(ErrorString* errorString, const String& cacheId, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<RequestEntr iesCallback> callback)
418 { 418 {
(...skipping 25 matching lines...) Expand all
444 { 444 {
445 String cacheName; 445 String cacheName;
446 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId( errorString, cacheId, &cacheName); 446 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId( errorString, cacheId, &cacheName);
447 if (!cache) { 447 if (!cache) {
448 callback->sendFailure(*errorString); 448 callback->sendFailure(*errorString);
449 return; 449 return;
450 } 450 }
451 cache->dispatchOpen(new GetCacheForDeleteEntry(request, cacheName, callback) , WebString(cacheName)); 451 cache->dispatchOpen(new GetCacheForDeleteEntry(request, cacheName, callback) , WebString(cacheName));
452 } 452 }
453 453
454 ExecutionContext* InspectorCacheStorageAgent::assertExecutionContextForOrigin(Er rorString* error, SecurityOrigin* origin)
455 {
456 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree().traver seNext()) {
pfeldman 2015/08/03 23:53:48 This approach is super-confusing, I was so happy i
jsbell 2015/08/04 00:14:53 Top level: don't try to and query CacheStorage if
457 if (!frame->isLocalFrame())
458 continue;
459 LocalFrame* localFrame = toLocalFrame(frame);
460 if (localFrame->document() && localFrame->document()->securityOrigin()-> isSameSchemeHostPort(origin))
461 return localFrame->document();
462 }
463
464 *error = "No frame is available for the request";
465 return 0;
466 }
467
468 PassOwnPtr<WebServiceWorkerCacheStorage> InspectorCacheStorageAgent::assertCache Storage(ErrorString* errorString, const String& securityOrigin)
469 {
470 RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(security Origin);
471 ExecutionContext* executionContext = assertExecutionContextForOrigin(errorSt ring, secOrigin.get());
472 if (!executionContext || !CacheStorage::canAccessCacheStorage(executionConte xt, errorString))
473 return nullptr;
474
475 String identifier = createDatabaseIdentifierFromSecurityOrigin(secOrigin.get ());
476 OwnPtr<WebServiceWorkerCacheStorage> cache = adoptPtr(Platform::current()->c acheStorage(identifier));
477 if (!cache)
478 *errorString = "Could not find cache storage.";
479 return cache.release();
480 }
481
482 PassOwnPtr<WebServiceWorkerCacheStorage> InspectorCacheStorageAgent::assertCache StorageAndNameForId(ErrorString* errorString, const String& cacheId, String* cac heName)
483 {
484 String securityOrigin;
485 if (!parseCacheId(errorString, cacheId, &securityOrigin, cacheName))
486 return nullptr;
487 return assertCacheStorage(errorString, securityOrigin);
488 }
454 489
455 } // namespace blink 490 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/cachestorage/InspectorCacheStorageAgent.h ('k') | Source/web/WebDevToolsAgentImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698