Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "bindings/core/v8/V8DOMWrapper.h" | 31 #include "bindings/core/v8/V8DOMWrapper.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/V8Binding.h" | 33 #include "bindings/core/v8/V8Binding.h" |
| 34 #include "bindings/core/v8/V8Location.h" | |
| 35 #include "bindings/core/v8/V8ObjectConstructor.h" | 34 #include "bindings/core/v8/V8ObjectConstructor.h" |
| 36 #include "bindings/core/v8/V8PerContextData.h" | 35 #include "bindings/core/v8/V8PerContextData.h" |
| 37 #include "bindings/core/v8/V8PerIsolateData.h" | 36 #include "bindings/core/v8/V8PerIsolateData.h" |
| 38 #include "bindings/core/v8/V8ScriptRunner.h" | |
| 39 #include "bindings/core/v8/V8Window.h" | |
| 40 #include "core/dom/Document.h" | |
| 41 #include "core/frame/LocalDOMWindow.h" | |
| 42 | 37 |
| 43 namespace blink { | 38 namespace blink { |
| 44 | 39 |
| 45 v8::Local<v8::Object> V8DOMWrapper::createWrapper( | 40 v8::Local<v8::Object> V8DOMWrapper::createWrapper( |
| 46 v8::Isolate* isolate, | 41 v8::Isolate* isolate, |
| 47 v8::Local<v8::Object> creationContext, | 42 v8::Local<v8::Object> creationContext, |
| 48 const WrapperTypeInfo* type) { | 43 const WrapperTypeInfo* type) { |
| 49 ASSERT(!type->equals(&V8Window::wrapperTypeInfo)); | 44 V8WrapperInstantiationScope scope(creationContext, isolate, type); |
|
Yuki
2017/04/06 08:26:15
You're not aborting the wrapper creation.
We shou
adithyas
2017/04/06 19:04:20
Ok, done.
| |
| 50 // According to | |
| 51 // https://html.spec.whatwg.org/multipage/browsers.html#security-location, | |
| 52 // cross-origin script access to a few properties of Location is allowed. | |
| 53 // Location already implements the necessary security checks. | |
| 54 bool withSecurityCheck = !type->equals(&V8Location::wrapperTypeInfo); | |
| 55 V8WrapperInstantiationScope scope(creationContext, isolate, | |
| 56 withSecurityCheck); | |
| 57 | 45 |
| 58 V8PerContextData* perContextData = V8PerContextData::from(scope.context()); | 46 V8PerContextData* perContextData = V8PerContextData::from(scope.context()); |
| 59 v8::Local<v8::Object> wrapper; | 47 v8::Local<v8::Object> wrapper; |
| 60 if (perContextData) { | 48 if (perContextData) { |
| 61 wrapper = perContextData->createWrapperFromCache(type); | 49 wrapper = perContextData->createWrapperFromCache(type); |
| 62 } else { | 50 } else { |
| 63 // The context is detached, but still accessible. | 51 // The context is detached, but still accessible. |
| 64 // TODO(yukishiino): This code does not create a wrapper with | 52 // TODO(yukishiino): This code does not create a wrapper with |
| 65 // the correct settings. Should follow the same way as | 53 // the correct settings. Should follow the same way as |
| 66 // V8PerContextData::createWrapperFromCache, though there is no need to | 54 // V8PerContextData::createWrapperFromCache, though there is no need to |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 96 | 84 |
| 97 if (object->InternalFieldCount() < v8DefaultWrapperInternalFieldCount) | 85 if (object->InternalFieldCount() < v8DefaultWrapperInternalFieldCount) |
| 98 return false; | 86 return false; |
| 99 | 87 |
| 100 const ScriptWrappable* untrustedScriptWrappable = toScriptWrappable(object); | 88 const ScriptWrappable* untrustedScriptWrappable = toScriptWrappable(object); |
| 101 const WrapperTypeInfo* untrustedWrapperTypeInfo = toWrapperTypeInfo(object); | 89 const WrapperTypeInfo* untrustedWrapperTypeInfo = toWrapperTypeInfo(object); |
| 102 return untrustedScriptWrappable && untrustedWrapperTypeInfo && | 90 return untrustedScriptWrappable && untrustedWrapperTypeInfo && |
| 103 untrustedWrapperTypeInfo->ginEmbedder == gin::kEmbedderBlink; | 91 untrustedWrapperTypeInfo->ginEmbedder == gin::kEmbedderBlink; |
| 104 } | 92 } |
| 105 | 93 |
| 106 void V8WrapperInstantiationScope::securityCheck( | |
| 107 v8::Isolate* isolate, | |
| 108 v8::Local<v8::Context> contextForWrapper) { | |
| 109 if (m_context.IsEmpty()) | |
| 110 return; | |
| 111 // If the context is different, we need to make sure that the current | |
| 112 // context has access to the creation context. | |
| 113 LocalFrame* frame = toLocalFrameIfNotDetached(contextForWrapper); | |
| 114 if (!frame) { | |
| 115 // Sandbox detached frames - they can't create cross origin objects. | |
| 116 LocalDOMWindow* callingWindow = currentDOMWindow(isolate); | |
| 117 LocalDOMWindow* targetWindow = toLocalDOMWindow(contextForWrapper); | |
| 118 // TODO(jochen): Currently, Location is the only object for which we can | |
| 119 // reach this code path. Should be generalized. | |
| 120 ExceptionState exceptionState(isolate, ExceptionState::ConstructionContext, | |
| 121 "Location"); | |
| 122 if (BindingSecurity::shouldAllowAccessToDetachedWindow( | |
| 123 callingWindow, targetWindow, exceptionState)) | |
| 124 return; | |
| 125 | |
| 126 CHECK_EQ(SecurityError, exceptionState.code()); | |
| 127 return; | |
| 128 } | |
| 129 const DOMWrapperWorld& currentWorld = DOMWrapperWorld::world(m_context); | |
| 130 RELEASE_ASSERT(currentWorld.worldId() == | |
| 131 DOMWrapperWorld::world(contextForWrapper).worldId()); | |
| 132 // TODO(jochen): Add the interface name here once this is generalized. | |
| 133 ExceptionState exceptionState(isolate, ExceptionState::ConstructionContext, | |
| 134 nullptr); | |
| 135 if (currentWorld.isMainWorld() && | |
| 136 !BindingSecurity::shouldAllowAccessToFrame(currentDOMWindow(isolate), | |
| 137 frame, exceptionState)) { | |
| 138 CHECK_EQ(SecurityError, exceptionState.code()); | |
| 139 return; | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 void V8WrapperInstantiationScope::convertException() { | |
| 144 v8::Isolate* isolate = m_context->GetIsolate(); | |
| 145 // TODO(jochen): Currently, Location is the only object for which we can reach | |
| 146 // this code path. Should be generalized. | |
| 147 ExceptionState exceptionState(isolate, ExceptionState::ConstructionContext, | |
| 148 "Location"); | |
| 149 LocalDOMWindow* callingWindow = currentDOMWindow(isolate); | |
| 150 LocalDOMWindow* targetWindow = toLocalDOMWindow(m_context); | |
| 151 exceptionState.throwSecurityError( | |
| 152 targetWindow->sanitizedCrossDomainAccessErrorMessage(callingWindow), | |
| 153 targetWindow->crossDomainAccessErrorMessage(callingWindow)); | |
| 154 } | |
| 155 | |
| 156 } // namespace blink | 94 } // namespace blink |
| OLD | NEW |