| 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" |
| 34 #include "bindings/core/v8/V8ObjectConstructor.h" | 35 #include "bindings/core/v8/V8ObjectConstructor.h" |
| 35 #include "bindings/core/v8/V8PerContextData.h" | 36 #include "bindings/core/v8/V8PerContextData.h" |
| 36 #include "bindings/core/v8/V8PerIsolateData.h" | 37 #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" |
| 37 | 42 |
| 38 namespace blink { | 43 namespace blink { |
| 39 | 44 |
| 40 v8::Local<v8::Object> V8DOMWrapper::CreateWrapper( | 45 v8::Local<v8::Object> V8DOMWrapper::CreateWrapper( |
| 41 v8::Isolate* isolate, | 46 v8::Isolate* isolate, |
| 42 v8::Local<v8::Object> creation_context, | 47 v8::Local<v8::Object> creation_context, |
| 43 const WrapperTypeInfo* type) { | 48 const WrapperTypeInfo* type) { |
| 44 V8WrapperInstantiationScope scope(creation_context, isolate, type); | 49 ASSERT(!type->Equals(&V8Window::wrapperTypeInfo)); |
| 45 if (scope.AccessCheckFailed()) { | 50 // According to |
| 46 return v8::Local<v8::Object>(); | 51 // https://html.spec.whatwg.org/multipage/browsers.html#security-location, |
| 47 } | 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); |
| 48 | 57 |
| 49 V8PerContextData* per_context_data = | 58 V8PerContextData* per_context_data = |
| 50 V8PerContextData::From(scope.GetContext()); | 59 V8PerContextData::From(scope.GetContext()); |
| 51 v8::Local<v8::Object> wrapper; | 60 v8::Local<v8::Object> wrapper; |
| 52 if (per_context_data) { | 61 if (per_context_data) { |
| 53 wrapper = per_context_data->CreateWrapperFromCache(type); | 62 wrapper = per_context_data->CreateWrapperFromCache(type); |
| 54 } else { | 63 } else { |
| 55 // The context is detached, but still accessible. | 64 // The context is detached, but still accessible. |
| 56 // TODO(yukishiino): This code does not create a wrapper with | 65 // TODO(yukishiino): This code does not create a wrapper with |
| 57 // the correct settings. Should follow the same way as | 66 // the correct settings. Should follow the same way as |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if (object->InternalFieldCount() < kV8DefaultWrapperInternalFieldCount) | 99 if (object->InternalFieldCount() < kV8DefaultWrapperInternalFieldCount) |
| 91 return false; | 100 return false; |
| 92 | 101 |
| 93 const ScriptWrappable* untrusted_script_wrappable = ToScriptWrappable(object); | 102 const ScriptWrappable* untrusted_script_wrappable = ToScriptWrappable(object); |
| 94 const WrapperTypeInfo* untrusted_wrapper_type_info = | 103 const WrapperTypeInfo* untrusted_wrapper_type_info = |
| 95 ToWrapperTypeInfo(object); | 104 ToWrapperTypeInfo(object); |
| 96 return untrusted_script_wrappable && untrusted_wrapper_type_info && | 105 return untrusted_script_wrappable && untrusted_wrapper_type_info && |
| 97 untrusted_wrapper_type_info->gin_embedder == gin::kEmbedderBlink; | 106 untrusted_wrapper_type_info->gin_embedder == gin::kEmbedderBlink; |
| 98 } | 107 } |
| 99 | 108 |
| 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 |
| 100 } // namespace blink | 159 } // namespace blink |
| OLD | NEW |