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

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

Issue 1339023002: Rethrow cross-site exceptions as security errors (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: git cl set_commit Created 5 years, 3 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: Source/bindings/core/v8/V8DOMWrapper.h
diff --git a/Source/bindings/core/v8/V8DOMWrapper.h b/Source/bindings/core/v8/V8DOMWrapper.h
index 4effd0697a064eca0ee39364987b9d0f0c84f47a..169979317b4e3a67f5f7122b71bb5fb2cc6009de 100644
--- a/Source/bindings/core/v8/V8DOMWrapper.h
+++ b/Source/bindings/core/v8/V8DOMWrapper.h
@@ -113,18 +113,24 @@ public:
V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext, v8::Isolate* isolate, bool withSecurityCheck = true)
: m_didEnterContext(false)
, m_context(isolate->GetCurrentContext())
+ , m_tryCatch(isolate)
+ , m_convertExceptions(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.
RELEASE_ASSERT(!creationContext.IsEmpty());
v8::Local<v8::Context> contextForWrapper = creationContext->CreationContext();
+
// For performance, we enter the context only if the currently running context
// is different from the context that we are about to enter.
if (contextForWrapper == m_context)
return;
- if (withSecurityCheck)
+ if (withSecurityCheck) {
securityCheck(isolate, contextForWrapper);
+ } else {
+ m_convertExceptions = true;
+ }
m_context = v8::Local<v8::Context>::New(isolate, contextForWrapper);
m_didEnterContext = true;
m_context->Enter();
@@ -132,18 +138,31 @@ public:
~V8WrapperInstantiationScope()
{
- if (!m_didEnterContext)
+ if (!m_didEnterContext) {
+ m_tryCatch.ReThrow();
return;
+ }
m_context->Exit();
+ // Rethrow any cross-context exceptions as security error.
+ if (m_tryCatch.HasCaught()) {
+ if (m_convertExceptions) {
+ m_tryCatch.Reset();
+ convertException();
+ }
+ m_tryCatch.ReThrow();
+ }
}
v8::Local<v8::Context> context() const { return m_context; }
private:
void securityCheck(v8::Isolate*, v8::Local<v8::Context> contextForWrapper);
+ void convertException();
bool m_didEnterContext;
v8::Local<v8::Context> m_context;
+ v8::TryCatch m_tryCatch;
+ bool m_convertExceptions;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698