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

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

Issue 2706923002: Rework security checks to be based on Window rather than Frame. (Closed)
Patch Set: Do not hardcode V8Window::wrapperTypeInfo Created 3 years, 7 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 22 matching lines...) Expand all
33 #include "bindings/core/v8/ScriptController.h" 33 #include "bindings/core/v8/ScriptController.h"
34 #include "bindings/core/v8/ScriptValue.h" 34 #include "bindings/core/v8/ScriptValue.h"
35 #include "bindings/core/v8/SourceLocation.h" 35 #include "bindings/core/v8/SourceLocation.h"
36 #include "bindings/core/v8/UseCounterCallback.h" 36 #include "bindings/core/v8/UseCounterCallback.h"
37 #include "bindings/core/v8/V8BindingForCore.h" 37 #include "bindings/core/v8/V8BindingForCore.h"
38 #include "bindings/core/v8/V8DOMException.h" 38 #include "bindings/core/v8/V8DOMException.h"
39 #include "bindings/core/v8/V8ErrorEvent.h" 39 #include "bindings/core/v8/V8ErrorEvent.h"
40 #include "bindings/core/v8/V8ErrorHandler.h" 40 #include "bindings/core/v8/V8ErrorHandler.h"
41 #include "bindings/core/v8/V8GCController.h" 41 #include "bindings/core/v8/V8GCController.h"
42 #include "bindings/core/v8/V8IdleTaskRunner.h" 42 #include "bindings/core/v8/V8IdleTaskRunner.h"
43 #include "bindings/core/v8/V8Location.h"
44 #include "bindings/core/v8/V8Window.h"
45 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 43 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
46 #include "core/dom/Document.h" 44 #include "core/dom/Document.h"
47 #include "core/dom/ExecutionContext.h" 45 #include "core/dom/ExecutionContext.h"
48 #include "core/frame/LocalDOMWindow.h" 46 #include "core/frame/LocalDOMWindow.h"
49 #include "core/frame/LocalFrame.h"
50 #include "core/frame/csp/ContentSecurityPolicy.h" 47 #include "core/frame/csp/ContentSecurityPolicy.h"
51 #include "core/inspector/ConsoleMessage.h" 48 #include "core/inspector/ConsoleMessage.h"
52 #include "core/inspector/MainThreadDebugger.h" 49 #include "core/inspector/MainThreadDebugger.h"
53 #include "core/workers/WorkerGlobalScope.h" 50 #include "core/workers/WorkerGlobalScope.h"
54 #include "platform/EventDispatchForbiddenScope.h" 51 #include "platform/EventDispatchForbiddenScope.h"
55 #include "platform/RuntimeEnabledFeatures.h" 52 #include "platform/RuntimeEnabledFeatures.h"
56 #include "platform/bindings/DOMWrapperWorld.h" 53 #include "platform/bindings/DOMWrapperWorld.h"
57 #include "platform/bindings/ScriptWrappableVisitor.h" 54 #include "platform/bindings/ScriptWrappableVisitor.h"
58 #include "platform/bindings/V8PerContextData.h" 55 #include "platform/bindings/V8PerContextData.h"
59 #include "platform/bindings/V8PrivateProperty.h" 56 #include "platform/bindings/V8PrivateProperty.h"
60 #include "platform/instrumentation/tracing/TraceEvent.h" 57 #include "platform/instrumentation/tracing/TraceEvent.h"
61 #include "platform/loader/fetch/AccessControlStatus.h" 58 #include "platform/loader/fetch/AccessControlStatus.h"
62 #include "platform/scheduler/child/web_scheduler.h" 59 #include "platform/scheduler/child/web_scheduler.h"
63 #include "platform/weborigin/SecurityViolationReportingPolicy.h" 60 #include "platform/weborigin/SecurityViolationReportingPolicy.h"
64 #include "platform/wtf/AddressSanitizer.h" 61 #include "platform/wtf/AddressSanitizer.h"
65 #include "platform/wtf/Assertions.h" 62 #include "platform/wtf/Assertions.h"
66 #include "platform/wtf/PtrUtil.h" 63 #include "platform/wtf/PtrUtil.h"
67 #include "platform/wtf/RefPtr.h" 64 #include "platform/wtf/RefPtr.h"
68 #include "platform/wtf/text/WTFString.h" 65 #include "platform/wtf/text/WTFString.h"
69 #include "platform/wtf/typed_arrays/ArrayBufferContents.h" 66 #include "platform/wtf/typed_arrays/ArrayBufferContents.h"
70 #include "public/platform/Platform.h" 67 #include "public/platform/Platform.h"
71 #include "public/platform/WebThread.h" 68 #include "public/platform/WebThread.h"
72 #include "v8/include/v8-debug.h" 69 #include "v8/include/v8-debug.h"
73 #include "v8/include/v8-profiler.h" 70 #include "v8/include/v8-profiler.h"
74 71
75 namespace blink { 72 namespace blink {
76 73
77 static Frame* FindFrame(v8::Isolate* isolate,
78 v8::Local<v8::Object> host,
79 v8::Local<v8::Value> data) {
80 const WrapperTypeInfo* type = WrapperTypeInfo::Unwrap(data);
81
82 if (V8Window::wrapperTypeInfo.Equals(type)) {
83 v8::Local<v8::Object> window_wrapper =
84 V8Window::findInstanceInPrototypeChain(host, isolate);
85 if (window_wrapper.IsEmpty())
86 return 0;
87 return V8Window::toImpl(window_wrapper)->GetFrame();
88 }
89
90 if (V8Location::wrapperTypeInfo.Equals(type))
91 return V8Location::toImpl(host)->GetFrame();
92
93 // This function can handle only those types listed above.
94 NOTREACHED();
95 return 0;
96 }
97
98 static void ReportFatalErrorInMainThread(const char* location, 74 static void ReportFatalErrorInMainThread(const char* location,
99 const char* message) { 75 const char* message) {
100 int memory_usage_mb = Platform::Current()->ActualMemoryUsageMB(); 76 int memory_usage_mb = Platform::Current()->ActualMemoryUsageMB();
101 DVLOG(1) << "V8 error: " << message << " (" << location 77 DVLOG(1) << "V8 error: " << message << " (" << location
102 << "). Current memory usage: " << memory_usage_mb << " MB"; 78 << "). Current memory usage: " << memory_usage_mb << " MB";
103 CRASH(); 79 CRASH();
104 } 80 }
105 81
106 static void ReportOOMErrorInMainThread(const char* location, bool is_js_heap) { 82 static void ReportOOMErrorInMainThread(const char* location, bool is_js_heap) {
107 int memory_usage_mb = Platform::Current()->ActualMemoryUsageMB(); 83 int memory_usage_mb = Platform::Current()->ActualMemoryUsageMB();
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 278
303 DCHECK(execution_context->IsWorkerGlobalScope()); 279 DCHECK(execution_context->IsWorkerGlobalScope());
304 WorkerOrWorkletScriptController* script_controller = 280 WorkerOrWorkletScriptController* script_controller =
305 ToWorkerGlobalScope(execution_context)->ScriptController(); 281 ToWorkerGlobalScope(execution_context)->ScriptController();
306 DCHECK(script_controller); 282 DCHECK(script_controller);
307 283
308 PromiseRejectHandler(data, *script_controller->GetRejectedPromises(), 284 PromiseRejectHandler(data, *script_controller->GetRejectedPromises(),
309 script_state); 285 script_state);
310 } 286 }
311 287
312 static void FailedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, 288 static void FailedAccessCheckCallbackInMainThread(v8::Local<v8::Object> holder,
313 v8::AccessType type, 289 v8::AccessType type,
314 v8::Local<v8::Value> data) { 290 v8::Local<v8::Value> data) {
315 v8::Isolate* isolate = v8::Isolate::GetCurrent();
316 Frame* target = FindFrame(isolate, host, data);
317 // FIXME: We should modify V8 to pass in more contextual information (context, 291 // FIXME: We should modify V8 to pass in more contextual information (context,
318 // property, and object). 292 // property, and object).
319 BindingSecurity::FailedAccessCheckFor(isolate, target); 293 BindingSecurity::FailedAccessCheckFor(v8::Isolate::GetCurrent(),
294 WrapperTypeInfo::Unwrap(data), holder);
320 } 295 }
321 296
322 static bool CodeGenerationCheckCallbackInMainThread( 297 static bool CodeGenerationCheckCallbackInMainThread(
323 v8::Local<v8::Context> context) { 298 v8::Local<v8::Context> context) {
324 if (ExecutionContext* execution_context = ToExecutionContext(context)) { 299 if (ExecutionContext* execution_context = ToExecutionContext(context)) {
325 if (ContentSecurityPolicy* policy = 300 if (ContentSecurityPolicy* policy =
326 ToDocument(execution_context)->GetContentSecurityPolicy()) 301 ToDocument(execution_context)->GetContentSecurityPolicy())
327 return policy->AllowEval(ScriptState::From(context), 302 return policy->AllowEval(ScriptState::From(context),
328 SecurityViolationReportingPolicy::kReport, 303 SecurityViolationReportingPolicy::kReport,
329 ContentSecurityPolicy::kWillThrowException); 304 ContentSecurityPolicy::kWillThrowException);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 v8::Isolate::kMessageLog); 558 v8::Isolate::kMessageLog);
584 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker); 559 isolate->SetFatalErrorHandler(ReportFatalErrorInWorker);
585 560
586 uint32_t here; 561 uint32_t here;
587 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - 562 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) -
588 kWorkerMaxStackSize); 563 kWorkerMaxStackSize);
589 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker); 564 isolate->SetPromiseRejectCallback(PromiseRejectHandlerInWorker);
590 } 565 }
591 566
592 } // namespace blink 567 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698