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

Side by Side Diff: Source/bindings/core/v8/V8DOMWrapper.h

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

Powered by Google App Engine
This is Rietveld 408576698