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

Unified Diff: Source/modules/cachestorage/CacheStorage.cpp

Issue 1177983007: Cache Storage: restrict access to secure origins (Blink-side) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/http/tests/security/powerfulFeatureRestrictions/cachestorage-on-insecure-origin.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/cachestorage/CacheStorage.cpp
diff --git a/Source/modules/cachestorage/CacheStorage.cpp b/Source/modules/cachestorage/CacheStorage.cpp
index 4961a3fa425ef4fa40a96aa96f7531f7b8449511..9c8e9300ecc69fc578b97292539a0439c65fa69d 100644
--- a/Source/modules/cachestorage/CacheStorage.cpp
+++ b/Source/modules/cachestorage/CacheStorage.cpp
@@ -193,6 +193,18 @@ ScriptPromise CacheStorage::open(ScriptState* scriptState, const String& cacheNa
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
const ScriptPromise promise = resolver->promise();
+ ExecutionContext* executionContext = scriptState->executionContext();
+ // FIXME: May be null due to worker termination: http://crbug.com/413518.
+ if (!executionContext)
+ return ScriptPromise();
+
+ RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
+ String errorMessage;
+ if (!executionContext->isPrivilegedContext(errorMessage)) {
+ resolver->reject(DOMException::create(SecurityError, errorMessage));
+ return promise;
+ }
+
if (m_nameToCacheMap.contains(cacheName)) {
Cache* cache = m_nameToCacheMap.find(cacheName)->value;
resolver->resolve(cache);
@@ -212,6 +224,18 @@ ScriptPromise CacheStorage::has(ScriptState* scriptState, const String& cacheNam
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
const ScriptPromise promise = resolver->promise();
+ ExecutionContext* executionContext = scriptState->executionContext();
+ // FIXME: May be null due to worker termination: http://crbug.com/413518.
+ if (!executionContext)
+ return ScriptPromise();
+
+ RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
+ String errorMessage;
+ if (!executionContext->isPrivilegedContext(errorMessage)) {
+ resolver->reject(DOMException::create(SecurityError, errorMessage));
+ return promise;
+ }
+
if (m_nameToCacheMap.contains(cacheName)) {
resolver->resolve(true);
return promise;
@@ -230,6 +254,18 @@ ScriptPromise CacheStorage::deleteFunction(ScriptState* scriptState, const Strin
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
const ScriptPromise promise = resolver->promise();
+ ExecutionContext* executionContext = scriptState->executionContext();
+ // FIXME: May be null due to worker termination: http://crbug.com/413518.
+ if (!executionContext)
+ return ScriptPromise();
+
+ RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
+ String errorMessage;
+ if (!executionContext->isPrivilegedContext(errorMessage)) {
+ resolver->reject(DOMException::create(SecurityError, errorMessage));
+ return promise;
+ }
+
if (m_webCacheStorage)
m_webCacheStorage->dispatchDelete(new DeleteCallbacks(cacheName, this, resolver), cacheName);
else
@@ -243,6 +279,18 @@ ScriptPromise CacheStorage::keys(ScriptState* scriptState)
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
const ScriptPromise promise = resolver->promise();
+ ExecutionContext* executionContext = scriptState->executionContext();
+ // FIXME: May be null due to worker termination: http://crbug.com/413518.
+ if (!executionContext)
+ return ScriptPromise();
+
+ RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
+ String errorMessage;
+ if (!executionContext->isPrivilegedContext(errorMessage)) {
+ resolver->reject(DOMException::create(SecurityError, errorMessage));
+ return promise;
+ }
Mike West 2015/06/18 19:54:57 Nit: It might be reasonable to extract this repeat
+
if (m_webCacheStorage)
m_webCacheStorage->dispatchKeys(new KeysCallbacks(resolver));
else
@@ -255,6 +303,18 @@ ScriptPromise CacheStorage::match(ScriptState* scriptState, const RequestInfo& r
{
ASSERT(!request.isNull());
+ ExecutionContext* executionContext = scriptState->executionContext();
+ // FIXME: May be null due to worker termination: http://crbug.com/413518.
+ if (!executionContext)
+ return ScriptPromise();
+
+ RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin();
+ String errorMessage;
+ if (!executionContext->isPrivilegedContext(errorMessage)) {
+ exceptionState.throwSecurityError(errorMessage);
+ return ScriptPromise();
+ }
+
if (request.isRequest())
return matchImpl(scriptState, request.getAsRequest(), options);
Request* newRequest = Request::create(scriptState, request.getAsUSVString(), exceptionState);
« no previous file with comments | « LayoutTests/http/tests/security/powerfulFeatureRestrictions/cachestorage-on-insecure-origin.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698