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

Side by Side 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: updates 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 unified diff | Download patch | Annotate | Revision Log
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(toScriptWrappable(wrapper) == Scrip tWrappable::fromNode(node)); 106 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(toScriptWrappable(wrapper) == Scrip tWrappable::fromNode(node));
107 return wrapper; 107 return wrapper;
108 } 108 }
109 109
110 class V8WrapperInstantiationScope { 110 class V8WrapperInstantiationScope {
111 STACK_ALLOCATED(); 111 STACK_ALLOCATED();
112 public: 112 public:
113 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext, v8::Isola te* isolate, bool withSecurityCheck = true) 113 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext, v8::Isola te* isolate, bool withSecurityCheck = true)
114 : m_didEnterContext(false) 114 : m_didEnterContext(false)
115 , m_context(isolate->GetCurrentContext()) 115 , m_context(isolate->GetCurrentContext())
116 , m_tryCatch(isolate)
117 , m_convertExceptions(false)
116 { 118 {
117 // creationContext should not be empty. Because if we have an 119 // creationContext should not be empty. Because if we have an
118 // empty creationContext, we will end up creating 120 // empty creationContext, we will end up creating
119 // a new object in the context currently entered. This is wrong. 121 // a new object in the context currently entered. This is wrong.
120 RELEASE_ASSERT(!creationContext.IsEmpty()); 122 RELEASE_ASSERT(!creationContext.IsEmpty());
121 v8::Local<v8::Context> contextForWrapper = creationContext->CreationCont ext(); 123 v8::Local<v8::Context> contextForWrapper = creationContext->CreationCont ext();
124
122 // For performance, we enter the context only if the currently running c ontext 125 // For performance, we enter the context only if the currently running c ontext
123 // is different from the context that we are about to enter. 126 // is different from the context that we are about to enter.
124 if (contextForWrapper == m_context) 127 if (contextForWrapper == m_context)
125 return; 128 return;
126 if (withSecurityCheck) 129 if (withSecurityCheck) {
127 securityCheck(isolate, contextForWrapper); 130 securityCheck(isolate, contextForWrapper);
131 } else {
132 m_convertExceptions = true;
133 }
128 m_context = v8::Local<v8::Context>::New(isolate, contextForWrapper); 134 m_context = v8::Local<v8::Context>::New(isolate, contextForWrapper);
129 m_didEnterContext = true; 135 m_didEnterContext = true;
130 m_context->Enter(); 136 m_context->Enter();
131 } 137 }
132 138
133 ~V8WrapperInstantiationScope() 139 ~V8WrapperInstantiationScope()
134 { 140 {
135 if (!m_didEnterContext) 141 if (!m_didEnterContext) {
142 m_tryCatch.ReThrow();
136 return; 143 return;
144 }
137 m_context->Exit(); 145 m_context->Exit();
146 // Rethrow any cross-context exceptions as security error.
147 if (m_tryCatch.HasCaught()) {
148 if (m_convertExceptions) {
149 m_tryCatch.Reset();
150 convertException();
151 }
152 m_tryCatch.ReThrow();
153 }
138 } 154 }
139 155
140 v8::Local<v8::Context> context() const { return m_context; } 156 v8::Local<v8::Context> context() const { return m_context; }
141 157
142 private: 158 private:
143 void securityCheck(v8::Isolate*, v8::Local<v8::Context> contextForWrapper); 159 void securityCheck(v8::Isolate*, v8::Local<v8::Context> contextForWrapper);
160 void convertException();
144 161
145 bool m_didEnterContext; 162 bool m_didEnterContext;
146 v8::Local<v8::Context> m_context; 163 v8::Local<v8::Context> m_context;
164 v8::TryCatch m_tryCatch;
165 bool m_convertExceptions;
147 }; 166 };
148 167
149 } // namespace blink 168 } // namespace blink
150 169
151 #endif // V8DOMWrapper_h 170 #endif // V8DOMWrapper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698