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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h

Issue 2745313003: Move securityCheck out of V8WrapperInstantiationScope (Closed)
Patch Set: Add TODO 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h b/third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h
index e7216cf49b68781dcef5e55f741446c5d943d6bc..a3dec3ed47c3877b018eb5e94e2b95d9b3af6710 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h
+++ b/third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h
@@ -31,10 +31,10 @@
#ifndef V8DOMWrapper_h
#define V8DOMWrapper_h
-#include "bindings/core/v8/BindingSecurity.h"
#include "bindings/core/v8/DOMDataStore.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/core/v8/V8Binding.h"
+#include "bindings/core/v8/WrapperCreationSecurityCheck.h"
#include "core/CoreExport.h"
#include "platform/wtf/Compiler.h"
#include "platform/wtf/text/AtomicString.h"
@@ -127,11 +127,12 @@ class V8WrapperInstantiationScope {
public:
V8WrapperInstantiationScope(v8::Local<v8::Object> creation_context,
v8::Isolate* isolate,
- bool with_security_check)
+ const WrapperTypeInfo* type)
: did_enter_context_(false),
context_(isolate->GetCurrentContext()),
try_catch_(isolate),
- convert_exceptions_(false) {
+ type_(type),
+ access_check_failed_(false) {
// creationContext should not be empty. Because if we have an
// empty creationContext, we will end up creating
// a new object in the context currently entered. This is wrong.
@@ -143,12 +144,16 @@ class V8WrapperInstantiationScope {
// context is different from the context that we are about to enter.
if (context_for_wrapper == context_)
return;
- if (with_security_check) {
- SecurityCheck(isolate, context_for_wrapper);
- } else {
- convert_exceptions_ = true;
+
+ context_ = context_for_wrapper;
+
+ if (!WrapperCreationSecurityCheck::VerifyContextAccess(context_, type_)) {
+ DCHECK(try_catch_.HasCaught());
+ try_catch_.ReThrow();
+ access_check_failed_ = true;
+ return;
}
- context_ = v8::Local<v8::Context>::New(isolate, context_for_wrapper);
+
did_enter_context_ = true;
context_->Enter();
}
@@ -159,26 +164,30 @@ class V8WrapperInstantiationScope {
return;
}
context_->Exit();
- // Rethrow any cross-context exceptions as security error.
- if (try_catch_.HasCaught()) {
- if (convert_exceptions_) {
- try_catch_.Reset();
- ConvertException();
- }
- try_catch_.ReThrow();
- }
+
+ if (access_check_failed_ || !try_catch_.HasCaught())
+ return;
+
+ // Any exception caught here is a cross context exception and it may not be
+ // safe to directly rethrow the exception in the current context (without
+ // converting it). rethrowCrossContextException converts the exception in
+ // such a scenario.
+ v8::Local<v8::Value> caught_exception = try_catch_.Exception();
+ try_catch_.Reset();
+ WrapperCreationSecurityCheck::RethrowCrossContextException(
+ context_, type_, caught_exception);
+ try_catch_.ReThrow();
}
v8::Local<v8::Context> GetContext() const { return context_; }
+ bool AccessCheckFailed() const { return access_check_failed_; }
private:
- void SecurityCheck(v8::Isolate*, v8::Local<v8::Context> context_for_wrapper);
- void ConvertException();
-
bool did_enter_context_;
v8::Local<v8::Context> context_;
v8::TryCatch try_catch_;
- bool convert_exceptions_;
+ const WrapperTypeInfo* type_;
+ bool access_check_failed_;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698