| 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> creation_context, | 42 v8::Local<v8::Object> creation_context, |
| 48 const WrapperTypeInfo* type) { | 43 const WrapperTypeInfo* type) { |
| 49 ASSERT(!type->Equals(&V8Window::wrapperTypeInfo)); | 44 // TODO(adithyas): We should abort wrapper creation if the context access |
| 50 // According to | 45 // check fails and throws an exception. |
| 51 // https://html.spec.whatwg.org/multipage/browsers.html#security-location, | 46 V8WrapperInstantiationScope scope(creation_context, isolate, type); |
| 52 // cross-origin script access to a few properties of Location is allowed. | |
| 53 // Location already implements the necessary security checks. | |
| 54 bool with_security_check = !type->Equals(&V8Location::wrapperTypeInfo); | |
| 55 V8WrapperInstantiationScope scope(creation_context, isolate, | |
| 56 with_security_check); | |
| 57 | 47 |
| 58 V8PerContextData* per_context_data = | 48 V8PerContextData* per_context_data = |
| 59 V8PerContextData::From(scope.GetContext()); | 49 V8PerContextData::From(scope.GetContext()); |
| 60 v8::Local<v8::Object> wrapper; | 50 v8::Local<v8::Object> wrapper; |
| 61 if (per_context_data) { | 51 if (per_context_data) { |
| 62 wrapper = per_context_data->CreateWrapperFromCache(type); | 52 wrapper = per_context_data->CreateWrapperFromCache(type); |
| 63 } else { | 53 } else { |
| 64 // The context is detached, but still accessible. | 54 // The context is detached, but still accessible. |
| 65 // TODO(yukishiino): This code does not create a wrapper with | 55 // TODO(yukishiino): This code does not create a wrapper with |
| 66 // the correct settings. Should follow the same way as | 56 // the correct settings. Should follow the same way as |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 if (object->InternalFieldCount() < kV8DefaultWrapperInternalFieldCount) | 89 if (object->InternalFieldCount() < kV8DefaultWrapperInternalFieldCount) |
| 100 return false; | 90 return false; |
| 101 | 91 |
| 102 const ScriptWrappable* untrusted_script_wrappable = ToScriptWrappable(object); | 92 const ScriptWrappable* untrusted_script_wrappable = ToScriptWrappable(object); |
| 103 const WrapperTypeInfo* untrusted_wrapper_type_info = | 93 const WrapperTypeInfo* untrusted_wrapper_type_info = |
| 104 ToWrapperTypeInfo(object); | 94 ToWrapperTypeInfo(object); |
| 105 return untrusted_script_wrappable && untrusted_wrapper_type_info && | 95 return untrusted_script_wrappable && untrusted_wrapper_type_info && |
| 106 untrusted_wrapper_type_info->gin_embedder == gin::kEmbedderBlink; | 96 untrusted_wrapper_type_info->gin_embedder == gin::kEmbedderBlink; |
| 107 } | 97 } |
| 108 | 98 |
| 109 void V8WrapperInstantiationScope::SecurityCheck( | |
| 110 v8::Isolate* isolate, | |
| 111 v8::Local<v8::Context> context_for_wrapper) { | |
| 112 if (context_.IsEmpty()) | |
| 113 return; | |
| 114 // If the context is different, we need to make sure that the current | |
| 115 // context has access to the creation context. | |
| 116 LocalFrame* frame = ToLocalFrameIfNotDetached(context_for_wrapper); | |
| 117 if (!frame) { | |
| 118 // Sandbox detached frames - they can't create cross origin objects. | |
| 119 LocalDOMWindow* calling_window = CurrentDOMWindow(isolate); | |
| 120 LocalDOMWindow* target_window = ToLocalDOMWindow(context_for_wrapper); | |
| 121 // TODO(jochen): Currently, Location is the only object for which we can | |
| 122 // reach this code path. Should be generalized. | |
| 123 ExceptionState exception_state( | |
| 124 isolate, ExceptionState::kConstructionContext, "Location"); | |
| 125 if (BindingSecurity::ShouldAllowAccessToDetachedWindow( | |
| 126 calling_window, target_window, exception_state)) | |
| 127 return; | |
| 128 | |
| 129 CHECK_EQ(kSecurityError, exception_state.Code()); | |
| 130 return; | |
| 131 } | |
| 132 const DOMWrapperWorld& current_world = DOMWrapperWorld::World(context_); | |
| 133 RELEASE_ASSERT(current_world.GetWorldId() == | |
| 134 DOMWrapperWorld::World(context_for_wrapper).GetWorldId()); | |
| 135 // TODO(jochen): Add the interface name here once this is generalized. | |
| 136 ExceptionState exception_state(isolate, ExceptionState::kConstructionContext, | |
| 137 nullptr); | |
| 138 if (current_world.IsMainWorld() && | |
| 139 !BindingSecurity::ShouldAllowAccessToFrame(CurrentDOMWindow(isolate), | |
| 140 frame, exception_state)) { | |
| 141 CHECK_EQ(kSecurityError, exception_state.Code()); | |
| 142 return; | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 void V8WrapperInstantiationScope::ConvertException() { | |
| 147 v8::Isolate* isolate = context_->GetIsolate(); | |
| 148 // TODO(jochen): Currently, Location is the only object for which we can reach | |
| 149 // this code path. Should be generalized. | |
| 150 ExceptionState exception_state(isolate, ExceptionState::kConstructionContext, | |
| 151 "Location"); | |
| 152 LocalDOMWindow* calling_window = CurrentDOMWindow(isolate); | |
| 153 LocalDOMWindow* target_window = ToLocalDOMWindow(context_); | |
| 154 exception_state.ThrowSecurityError( | |
| 155 target_window->SanitizedCrossDomainAccessErrorMessage(calling_window), | |
| 156 target_window->CrossDomainAccessErrorMessage(calling_window)); | |
| 157 } | |
| 158 | |
| 159 } // namespace blink | 99 } // namespace blink |
| OLD | NEW |