Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 // TODO(dcheng): Add ContextType, interface name, and property name as | 264 // TODO(dcheng): Add ContextType, interface name, and property name as |
| 265 // arguments, so the generated exception can be more descriptive. | 265 // arguments, so the generated exception can be more descriptive. |
| 266 ExceptionState exceptionState(isolate, ExceptionState::UnknownContext, | 266 ExceptionState exceptionState(isolate, ExceptionState::UnknownContext, |
| 267 nullptr, nullptr); | 267 nullptr, nullptr); |
| 268 exceptionState.throwSecurityError( | 268 exceptionState.throwSecurityError( |
| 269 targetWindow->sanitizedCrossDomainAccessErrorMessage( | 269 targetWindow->sanitizedCrossDomainAccessErrorMessage( |
| 270 currentDOMWindow(isolate)), | 270 currentDOMWindow(isolate)), |
| 271 targetWindow->crossDomainAccessErrorMessage(currentDOMWindow(isolate))); | 271 targetWindow->crossDomainAccessErrorMessage(currentDOMWindow(isolate))); |
| 272 } | 272 } |
| 273 | 273 |
| 274 bool BindingSecurity::canEnterCreationContext( | |
| 275 v8::Isolate* isolate, | |
| 276 v8::Local<v8::Context> currentContext, | |
| 277 v8::Local<v8::Context> creationContext, | |
| 278 const char* interfaceName) { | |
| 279 if (currentContext.IsEmpty() || creationContext.IsEmpty()) | |
|
Yuki
2017/03/16 14:05:55
Is that possible that currentContext.IsEmpty() nor
adithyas
2017/03/28 20:35:40
This was just supposed to be currentContext.IsEmpt
| |
| 280 return false; | |
| 281 | |
| 282 // If the context is different, we need to make sure that the current | |
| 283 // context has access to the creation context. | |
| 284 LocalFrame* frame = toLocalFrameIfNotDetached(creationContext); | |
| 285 if (!frame) { | |
| 286 // Sandbox detached frames - they can't create cross origin objects. | |
| 287 LocalDOMWindow* callingWindow = currentDOMWindow(isolate); | |
| 288 LocalDOMWindow* targetWindow = toLocalDOMWindow(creationContext); | |
| 289 ExceptionState exceptionState(isolate, ExceptionState::ConstructionContext, | |
|
jbroman
2017/03/15 19:58:41
nit: This is the same as the ExceptionState below,
adithyas
2017/03/28 20:35:40
Done!
| |
| 290 interfaceName); | |
| 291 if (shouldAllowAccessToDetachedWindow(callingWindow, targetWindow, | |
| 292 exceptionState)) { | |
| 293 return true; | |
| 294 } | |
| 295 | |
| 296 CHECK_EQ(SecurityError, exceptionState.code()); | |
| 297 return false; | |
| 298 } | |
| 299 const DOMWrapperWorld& currentWorld = DOMWrapperWorld::world(currentContext); | |
| 300 RELEASE_ASSERT(currentWorld.worldId() == | |
| 301 DOMWrapperWorld::world(creationContext).worldId()); | |
| 302 ExceptionState exceptionState(isolate, ExceptionState::ConstructionContext, | |
| 303 interfaceName); | |
| 304 if (currentWorld.isMainWorld() && | |
| 305 !shouldAllowAccessToFrame(currentDOMWindow(isolate), frame, | |
| 306 exceptionState)) { | |
| 307 CHECK_EQ(SecurityError, exceptionState.code()); | |
| 308 return false; | |
| 309 } | |
| 310 | |
| 311 return true; | |
| 312 } | |
| 313 | |
| 314 void BindingSecurity::securityCheckForClassesWithAccessCheckCallbacks( | |
| 315 v8::Isolate* isolate, | |
| 316 v8::Local<v8::Context> currentContext, | |
| 317 v8::Local<v8::Context> creationContext, | |
| 318 const char* interfaceName, | |
| 319 v8::Local<v8::Value> crossContextException) { | |
| 320 // Classes with access check callbacks do allow some cross-origin accesses; | |
| 321 // the security checks are implemented in V8[[interfaceName]]::securityCheck. | |
| 322 if (!crossContextException.IsEmpty()) { | |
| 323 // Convert cross-context exception to security error | |
| 324 ExceptionState exceptionState(isolate, ExceptionState::ConstructionContext, | |
|
Yuki
2017/03/16 14:05:55
In general, ExceptionState should be instantiated
adithyas
2017/03/28 20:35:40
I didn't create an exception state in the call sit
| |
| 325 interfaceName); | |
| 326 LocalDOMWindow* callingWindow = currentDOMWindow(isolate); | |
| 327 LocalDOMWindow* targetWindow = toLocalDOMWindow(creationContext); | |
| 328 exceptionState.throwSecurityError( | |
| 329 targetWindow->sanitizedCrossDomainAccessErrorMessage(callingWindow), | |
| 330 targetWindow->crossDomainAccessErrorMessage(callingWindow)); | |
| 331 }; | |
| 332 } | |
| 333 | |
| 334 void BindingSecurity::securityCheckForClassesWithoutAccessCheckCallbacks( | |
| 335 v8::Isolate* isolate, | |
| 336 v8::Local<v8::Context> currentContext, | |
| 337 v8::Local<v8::Context> creationContext, | |
| 338 const char* interfaceName, | |
| 339 v8::Local<v8::Value> crossContextException) { | |
| 340 if (canEnterCreationContext(isolate, currentContext, creationContext, | |
| 341 interfaceName) && | |
| 342 !crossContextException.IsEmpty()) { | |
| 343 ExceptionState exceptionState(isolate, ExceptionState::ConstructionContext, | |
| 344 interfaceName); | |
| 345 exceptionState.rethrowV8Exception(crossContextException); | |
| 346 } | |
| 347 } | |
| 348 | |
| 274 } // namespace blink | 349 } // namespace blink |
| OLD | NEW |