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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/BindingSecurity.cpp

Issue 2745313003: Move securityCheck out of V8WrapperInstantiationScope (Closed)
Patch Set: Move functions into static class and remove flag bit Created 3 years, 8 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
OLDNEW
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 14 matching lines...) Expand all
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/BindingSecurity.h" 31 #include "bindings/core/v8/BindingSecurity.h"
32 32
33 #include "bindings/core/v8/ExceptionState.h" 33 #include "bindings/core/v8/ExceptionState.h"
34 #include "bindings/core/v8/V8Binding.h" 34 #include "bindings/core/v8/V8Binding.h"
35 #include "bindings/core/v8/V8Location.h"
36 #include "bindings/core/v8/WrapperCreationSecurityCheck.h"
35 #include "core/dom/Document.h" 37 #include "core/dom/Document.h"
36 #include "core/frame/LocalDOMWindow.h" 38 #include "core/frame/LocalDOMWindow.h"
37 #include "core/frame/LocalFrame.h" 39 #include "core/frame/LocalFrame.h"
38 #include "core/frame/Location.h" 40 #include "core/frame/Location.h"
39 #include "core/frame/Settings.h" 41 #include "core/frame/Settings.h"
40 #include "core/html/HTMLFrameElementBase.h" 42 #include "core/html/HTMLFrameElementBase.h"
41 #include "core/workers/MainThreadWorkletGlobalScope.h" 43 #include "core/workers/MainThreadWorkletGlobalScope.h"
42 #include "platform/weborigin/SecurityOrigin.h" 44 #include "platform/weborigin/SecurityOrigin.h"
43 45
44 namespace blink { 46 namespace blink {
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // TODO(dcheng): Add ContextType, interface name, and property name as 266 // TODO(dcheng): Add ContextType, interface name, and property name as
265 // arguments, so the generated exception can be more descriptive. 267 // arguments, so the generated exception can be more descriptive.
266 ExceptionState exceptionState(isolate, ExceptionState::UnknownContext, 268 ExceptionState exceptionState(isolate, ExceptionState::UnknownContext,
267 nullptr, nullptr); 269 nullptr, nullptr);
268 exceptionState.throwSecurityError( 270 exceptionState.throwSecurityError(
269 targetWindow->sanitizedCrossDomainAccessErrorMessage( 271 targetWindow->sanitizedCrossDomainAccessErrorMessage(
270 currentDOMWindow(isolate)), 272 currentDOMWindow(isolate)),
271 targetWindow->crossDomainAccessErrorMessage(currentDOMWindow(isolate))); 273 targetWindow->crossDomainAccessErrorMessage(currentDOMWindow(isolate)));
272 } 274 }
273 275
276 bool BindingSecurity::canEnterCreationContext(
Yuki 2017/03/31 09:49:37 nit: Could you place the implementation in the sam
adithyas 2017/03/31 17:49:28 Fixed
277 v8::Isolate* isolate,
278 v8::Local<v8::Context> currentContext,
279 v8::Local<v8::Context> creationContext,
280 ExceptionState& exceptionState) {
281 if (currentContext.IsEmpty())
Yuki 2017/03/31 09:49:37 This must never happen, I think.
282 return false;
283
284 // If the context is different, we need to make sure that the current
285 // context has access to the creation context.
286 LocalFrame* frame = toLocalFrameIfNotDetached(creationContext);
287 if (!frame) {
288 // Sandbox detached frames - they can't create cross origin objects.
289 LocalDOMWindow* callingWindow = currentDOMWindow(isolate);
290 LocalDOMWindow* targetWindow = toLocalDOMWindow(creationContext);
291 if (shouldAllowAccessToDetachedWindow(callingWindow, targetWindow,
292 exceptionState)) {
293 return true;
294 }
295
296 CHECK_EQ(SecurityError, exceptionState.code());
Yuki 2017/03/31 09:49:37 This is guaranteed. If you'd like to add a CHECK,
adithyas 2017/03/31 17:49:28 Sorry, this CHECK existed before, and I wasn't qui
297 return false;
298 }
299 const DOMWrapperWorld& currentWorld = DOMWrapperWorld::world(currentContext);
300 RELEASE_ASSERT(currentWorld.worldId() ==
Yuki 2017/03/31 09:49:37 s/RELEASE_ASSERT/CHECK_EQ/
301 DOMWrapperWorld::world(creationContext).worldId());
302
303 if (currentWorld.isMainWorld() &&
304 !shouldAllowAccessToFrame(currentDOMWindow(isolate), frame,
305 exceptionState)) {
306 CHECK_EQ(SecurityError, exceptionState.code());
307 return false;
308 }
309
310 return true;
311 }
312
313 void BindingSecurity::wrapperCreationSecurityCheck(
314 v8::Isolate* isolate,
315 v8::Local<v8::Context> currentContext,
Yuki 2017/03/31 09:49:37 I'd suggest s/currentContext/accessingContext/ s/
adithyas 2017/03/31 17:49:28 I do think this is specific to wrapper creation so
316 v8::Local<v8::Context> creationContext,
317 const WrapperTypeInfo* type,
318 v8::Local<v8::Value> crossContextException) {
319 ExceptionState exceptionState(isolate, ExceptionState::ConstructionContext,
320 type->interfaceName);
321
322 // According to
323 // https://html.spec.whatwg.org/multipage/browsers.html#security-location,
324 // cross-origin script access to a few properties of Location is allowed.
325 // Location already implements the necessary security checks.
326 if (type->equals(&V8Location::wrapperTypeInfo)) {
327 if (!crossContextException.IsEmpty()) {
Yuki 2017/03/31 09:49:37 I think this function is "rethrow an exception in
adithyas 2017/03/31 17:49:28 Makes sense, changed to an early-exit.
328 // Convert cross-context exception to security error
329 LocalDOMWindow* callingWindow = currentDOMWindow(isolate);
Yuki 2017/03/31 09:49:37 Be consistent with the arguments. Here you ignore
adithyas 2017/03/31 17:49:28 Fixed to use isolate->GetCurrentContext() / curren
330 LocalDOMWindow* targetWindow = toLocalDOMWindow(creationContext);
331 exceptionState.throwSecurityError(
332 targetWindow->sanitizedCrossDomainAccessErrorMessage(callingWindow),
333 targetWindow->crossDomainAccessErrorMessage(callingWindow));
334 };
335 } else {
Yuki 2017/03/31 09:49:37 You can return just after exceptionState.throwSecu
adithyas 2017/03/31 17:49:28 Done
336 if (canEnterCreationContext(isolate, currentContext, creationContext,
Yuki 2017/03/31 09:49:37 I'd personally feel that this helper function does
adithyas 2017/03/31 17:49:28 Coming up with a good name is difficult here :) I
337 exceptionState) &&
338 !crossContextException.IsEmpty()) {
339 exceptionState.rethrowV8Exception(crossContextException);
340 }
341 }
342 }
343
274 } // namespace blink 344 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698