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

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: Address review comments. Created 3 years, 9 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 23 matching lines...) Expand all
34 #include "bindings/core/v8/ScriptValue.h" 34 #include "bindings/core/v8/ScriptValue.h"
35 #include "bindings/core/v8/ScriptWrappableVisitor.h" 35 #include "bindings/core/v8/ScriptWrappableVisitor.h"
36 #include "bindings/core/v8/SourceLocation.h" 36 #include "bindings/core/v8/SourceLocation.h"
37 #include "bindings/core/v8/UseCounterCallback.h" 37 #include "bindings/core/v8/UseCounterCallback.h"
38 #include "bindings/core/v8/V8Binding.h" 38 #include "bindings/core/v8/V8Binding.h"
39 #include "bindings/core/v8/V8DOMException.h" 39 #include "bindings/core/v8/V8DOMException.h"
40 #include "bindings/core/v8/V8ErrorEvent.h" 40 #include "bindings/core/v8/V8ErrorEvent.h"
41 #include "bindings/core/v8/V8ErrorHandler.h" 41 #include "bindings/core/v8/V8ErrorHandler.h"
42 #include "bindings/core/v8/V8GCController.h" 42 #include "bindings/core/v8/V8GCController.h"
43 #include "bindings/core/v8/V8IdleTaskRunner.h" 43 #include "bindings/core/v8/V8IdleTaskRunner.h"
44 #include "bindings/core/v8/V8Location.h"
45 #include "bindings/core/v8/V8PerContextData.h" 44 #include "bindings/core/v8/V8PerContextData.h"
46 #include "bindings/core/v8/V8PrivateProperty.h" 45 #include "bindings/core/v8/V8PrivateProperty.h"
47 #include "bindings/core/v8/V8Window.h"
48 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 46 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
49 #include "core/dom/Document.h" 47 #include "core/dom/Document.h"
50 #include "core/frame/LocalDOMWindow.h" 48 #include "core/frame/LocalDOMWindow.h"
51 #include "core/frame/LocalFrame.h"
52 #include "core/frame/csp/ContentSecurityPolicy.h" 49 #include "core/frame/csp/ContentSecurityPolicy.h"
53 #include "core/inspector/ConsoleMessage.h" 50 #include "core/inspector/ConsoleMessage.h"
54 #include "core/inspector/MainThreadDebugger.h" 51 #include "core/inspector/MainThreadDebugger.h"
55 #include "core/workers/WorkerGlobalScope.h" 52 #include "core/workers/WorkerGlobalScope.h"
56 #include "platform/EventDispatchForbiddenScope.h" 53 #include "platform/EventDispatchForbiddenScope.h"
57 #include "platform/RuntimeEnabledFeatures.h" 54 #include "platform/RuntimeEnabledFeatures.h"
58 #include "platform/instrumentation/tracing/TraceEvent.h" 55 #include "platform/instrumentation/tracing/TraceEvent.h"
59 #include "platform/loader/fetch/AccessControlStatus.h" 56 #include "platform/loader/fetch/AccessControlStatus.h"
60 #include "platform/weborigin/SecurityViolationReportingPolicy.h" 57 #include "platform/weborigin/SecurityViolationReportingPolicy.h"
61 #include "public/platform/Platform.h" 58 #include "public/platform/Platform.h"
62 #include "public/platform/WebScheduler.h" 59 #include "public/platform/WebScheduler.h"
63 #include "public/platform/WebThread.h" 60 #include "public/platform/WebThread.h"
64 #include "v8/include/v8-debug.h" 61 #include "v8/include/v8-debug.h"
65 #include "v8/include/v8-profiler.h" 62 #include "v8/include/v8-profiler.h"
66 #include "wtf/AddressSanitizer.h" 63 #include "wtf/AddressSanitizer.h"
67 #include "wtf/Assertions.h" 64 #include "wtf/Assertions.h"
68 #include "wtf/PtrUtil.h" 65 #include "wtf/PtrUtil.h"
69 #include "wtf/RefPtr.h" 66 #include "wtf/RefPtr.h"
70 #include "wtf/text/WTFString.h" 67 #include "wtf/text/WTFString.h"
71 #include "wtf/typed_arrays/ArrayBufferContents.h" 68 #include "wtf/typed_arrays/ArrayBufferContents.h"
72 69
73 namespace blink { 70 namespace blink {
74 71
75 static Frame* findFrame(v8::Isolate* isolate,
76 v8::Local<v8::Object> host,
77 v8::Local<v8::Value> data) {
78 const WrapperTypeInfo* type = WrapperTypeInfo::unwrap(data);
79
80 if (V8Window::wrapperTypeInfo.equals(type)) {
81 v8::Local<v8::Object> windowWrapper =
82 V8Window::findInstanceInPrototypeChain(host, isolate);
83 if (windowWrapper.IsEmpty())
84 return 0;
85 return V8Window::toImpl(windowWrapper)->frame();
86 }
87
88 if (V8Location::wrapperTypeInfo.equals(type))
89 return V8Location::toImpl(host)->frame();
90
91 // This function can handle only those types listed above.
92 ASSERT_NOT_REACHED();
93 return 0;
94 }
95
96 static void reportFatalErrorInMainThread(const char* location, 72 static void reportFatalErrorInMainThread(const char* location,
97 const char* message) { 73 const char* message) {
98 int memoryUsageMB = Platform::current()->actualMemoryUsageMB(); 74 int memoryUsageMB = Platform::current()->actualMemoryUsageMB();
99 DVLOG(1) << "V8 error: " << message << " (" << location 75 DVLOG(1) << "V8 error: " << message << " (" << location
100 << "). Current memory usage: " << memoryUsageMB << " MB"; 76 << "). Current memory usage: " << memoryUsageMB << " MB";
101 CRASH(); 77 CRASH();
102 } 78 }
103 79
104 static void reportOOMErrorInMainThread(const char* location, bool isJsHeap) { 80 static void reportOOMErrorInMainThread(const char* location, bool isJsHeap) {
105 int memoryUsageMB = Platform::current()->actualMemoryUsageMB(); 81 int memoryUsageMB = Platform::current()->actualMemoryUsageMB();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 toWorkerGlobalScope(executionContext)->scriptController(); 275 toWorkerGlobalScope(executionContext)->scriptController();
300 ASSERT(scriptController); 276 ASSERT(scriptController);
301 277
302 promiseRejectHandler(data, *scriptController->getRejectedPromises(), 278 promiseRejectHandler(data, *scriptController->getRejectedPromises(),
303 scriptState); 279 scriptState);
304 } 280 }
305 281
306 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host, 282 static void failedAccessCheckCallbackInMainThread(v8::Local<v8::Object> host,
307 v8::AccessType type, 283 v8::AccessType type,
308 v8::Local<v8::Value> data) { 284 v8::Local<v8::Value> data) {
309 v8::Isolate* isolate = v8::Isolate::GetCurrent();
310 Frame* target = findFrame(isolate, host, data);
311 // FIXME: We should modify V8 to pass in more contextual information (context, 285 // FIXME: We should modify V8 to pass in more contextual information (context,
312 // property, and object). 286 // property, and object).
313 BindingSecurity::failedAccessCheckFor(isolate, target); 287 BindingSecurity::failedAccessCheckFor(v8::Isolate::GetCurrent(),
288 WrapperTypeInfo::unwrap(data), host);
haraken 2017/03/07 08:53:57 This host refers to a holder object, right? Maybe
dcheng 2017/03/07 09:06:47 Done.
314 } 289 }
315 290
316 static bool codeGenerationCheckCallbackInMainThread( 291 static bool codeGenerationCheckCallbackInMainThread(
317 v8::Local<v8::Context> context) { 292 v8::Local<v8::Context> context) {
318 if (ExecutionContext* executionContext = toExecutionContext(context)) { 293 if (ExecutionContext* executionContext = toExecutionContext(context)) {
319 if (ContentSecurityPolicy* policy = 294 if (ContentSecurityPolicy* policy =
320 toDocument(executionContext)->contentSecurityPolicy()) 295 toDocument(executionContext)->contentSecurityPolicy())
321 return policy->allowEval(ScriptState::from(context), 296 return policy->allowEval(ScriptState::from(context),
322 SecurityViolationReportingPolicy::Report, 297 SecurityViolationReportingPolicy::Report,
323 ContentSecurityPolicy::WillThrowException); 298 ContentSecurityPolicy::WillThrowException);
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 v8::Isolate::kMessageLog); 535 v8::Isolate::kMessageLog);
561 isolate->SetFatalErrorHandler(reportFatalErrorInWorker); 536 isolate->SetFatalErrorHandler(reportFatalErrorInWorker);
562 537
563 uint32_t here; 538 uint32_t here;
564 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) - 539 isolate->SetStackLimit(reinterpret_cast<uintptr_t>(&here) -
565 kWorkerMaxStackSize); 540 kWorkerMaxStackSize);
566 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker); 541 isolate->SetPromiseRejectCallback(promiseRejectHandlerInWorker);
567 } 542 }
568 543
569 } // namespace blink 544 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698