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

Side by Side Diff: Source/core/frame/LocalDOMWindow.cpp

Issue 1085973003: Make error messages for cross-domain access OOPIF-friendly. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase (pull in CL to print errors on calling window) Created 5 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 { 1487 {
1488 if (!isCurrentlyDisplayedInFrame()) 1488 if (!isCurrentlyDisplayedInFrame())
1489 return; 1489 return;
1490 1490
1491 if (message.isEmpty()) 1491 if (message.isEmpty())
1492 return; 1492 return;
1493 1493
1494 frameConsole()->addMessage(ConsoleMessage::create(JSMessageSource, ErrorMess ageLevel, message)); 1494 frameConsole()->addMessage(ConsoleMessage::create(JSMessageSource, ErrorMess ageLevel, message));
1495 } 1495 }
1496 1496
1497 // FIXME: Once we're throwing exceptions for cross-origin access violations, we will always sanitize the target
1498 // frame details, so we can safely combine 'crossDomainAccessErrorMessage' with this method after considering
1499 // exactly which details may be exposed to JavaScript.
1500 //
1501 // http://crbug.com/17325
1502 String LocalDOMWindow::sanitizedCrossDomainAccessErrorMessage(LocalDOMWindow* ca llingWindow)
1503 {
1504 if (!callingWindow || !callingWindow->document())
1505 return String();
1506
1507 const KURL& callingWindowURL = callingWindow->document()->url();
1508 if (callingWindowURL.isNull())
1509 return String();
1510
1511 ASSERT(!callingWindow->document()->securityOrigin()->canAccess(document()->s ecurityOrigin()));
1512
1513 SecurityOrigin* activeOrigin = callingWindow->document()->securityOrigin();
1514 String message = "Blocked a frame with origin \"" + activeOrigin->toString() + "\" from accessing a cross-origin frame.";
1515
1516 // FIXME: Evaluate which details from 'crossDomainAccessErrorMessage' may sa fely be reported to JavaScript.
1517
1518 return message;
1519 }
1520
1521 String LocalDOMWindow::crossDomainAccessErrorMessage(LocalDOMWindow* callingWind ow)
1522 {
1523 if (!callingWindow || !callingWindow->document())
1524 return String();
1525
1526 const KURL& callingWindowURL = callingWindow->document()->url();
1527 if (callingWindowURL.isNull())
1528 return String();
1529
1530 ASSERT(!callingWindow->document()->securityOrigin()->canAccess(document()->s ecurityOrigin()));
1531
1532 // FIXME: This message, and other console messages, have extra newlines. Sho uld remove them.
1533 SecurityOrigin* activeOrigin = callingWindow->document()->securityOrigin();
1534 SecurityOrigin* targetOrigin = document()->securityOrigin();
1535 String message = "Blocked a frame with origin \"" + activeOrigin->toString() + "\" from accessing a frame with origin \"" + targetOrigin->toString() + "\". ";
1536
1537 // Sandbox errors: Use the origin of the frames' location, rather than their actual origin (since we know that at least one will be "null").
1538 KURL activeURL = callingWindow->document()->url();
1539 KURL targetURL = document()->url();
1540 if (document()->isSandboxed(SandboxOrigin) || callingWindow->document()->isS andboxed(SandboxOrigin)) {
1541 message = "Blocked a frame at \"" + SecurityOrigin::create(activeURL)->t oString() + "\" from accessing a frame at \"" + SecurityOrigin::create(targetURL )->toString() + "\". ";
1542 if (document()->isSandboxed(SandboxOrigin) && callingWindow->document()- >isSandboxed(SandboxOrigin))
1543 return "Sandbox access violation: " + message + " Both frames are sa ndboxed and lack the \"allow-same-origin\" flag.";
1544 if (document()->isSandboxed(SandboxOrigin))
1545 return "Sandbox access violation: " + message + " The frame being ac cessed is sandboxed and lacks the \"allow-same-origin\" flag.";
1546 return "Sandbox access violation: " + message + " The frame requesting a ccess is sandboxed and lacks the \"allow-same-origin\" flag.";
1547 }
1548
1549 // Protocol errors: Use the URL's protocol rather than the origin's protocol so that we get a useful message for non-heirarchal URLs like 'data:'.
1550 if (targetOrigin->protocol() != activeOrigin->protocol())
1551 return message + " The frame requesting access has a protocol of \"" + a ctiveURL.protocol() + "\", the frame being accessed has a protocol of \"" + targ etURL.protocol() + "\". Protocols must match.\n";
1552
1553 // 'document.domain' errors.
1554 if (targetOrigin->domainWasSetInDOM() && activeOrigin->domainWasSetInDOM())
1555 return message + "The frame requesting access set \"document.domain\" to \"" + activeOrigin->domain() + "\", the frame being accessed set it to \"" + ta rgetOrigin->domain() + "\". Both must set \"document.domain\" to the same value to allow access.";
1556 if (activeOrigin->domainWasSetInDOM())
1557 return message + "The frame requesting access set \"document.domain\" to \"" + activeOrigin->domain() + "\", but the frame being accessed did not. Both must set \"document.domain\" to the same value to allow access.";
1558 if (targetOrigin->domainWasSetInDOM())
1559 return message + "The frame being accessed set \"document.domain\" to \" " + targetOrigin->domain() + "\", but the frame requesting access did not. Both must set \"document.domain\" to the same value to allow access.";
1560
1561 // Default.
1562 return message + "Protocols, domains, and ports must match.";
1563 }
1564
1565 bool LocalDOMWindow::isInsecureScriptAccess(DOMWindow& callingWindow, const Stri ng& urlString)
1566 {
1567 if (!DOMWindow::isInsecureScriptAccess(callingWindow, urlString))
1568 return false;
1569
1570 if (callingWindow.isLocalDOMWindow())
1571 toLocalDOMWindow(&callingWindow)->printErrorMessage(crossDomainAccessErr orMessage(toLocalDOMWindow(&callingWindow)));
1572 return true;
1573 }
1574
1575 PassRefPtrWillBeRawPtr<DOMWindow> LocalDOMWindow::open(const String& urlString, const AtomicString& frameName, const String& windowFeaturesString, 1497 PassRefPtrWillBeRawPtr<DOMWindow> LocalDOMWindow::open(const String& urlString, const AtomicString& frameName, const String& windowFeaturesString,
1576 LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWindow) 1498 LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWindow)
1577 { 1499 {
1578 if (!isCurrentlyDisplayedInFrame()) 1500 if (!isCurrentlyDisplayedInFrame())
1579 return nullptr; 1501 return nullptr;
1580 Document* activeDocument = callingWindow->document(); 1502 Document* activeDocument = callingWindow->document();
1581 if (!activeDocument) 1503 if (!activeDocument)
1582 return nullptr; 1504 return nullptr;
1583 LocalFrame* firstFrame = enteredWindow->frame(); 1505 LocalFrame* firstFrame = enteredWindow->frame();
1584 if (!firstFrame) 1506 if (!firstFrame)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 return m_frameObserver->frame(); 1582 return m_frameObserver->frame();
1661 } 1583 }
1662 1584
1663 v8::Handle<v8::Object> LocalDOMWindow::wrap(v8::Handle<v8::Object> creationConte xt, v8::Isolate* isolate) 1585 v8::Handle<v8::Object> LocalDOMWindow::wrap(v8::Handle<v8::Object> creationConte xt, v8::Isolate* isolate)
1664 { 1586 {
1665 ASSERT_NOT_REACHED(); // LocalDOMWindow has [Custom=ToV8]. 1587 ASSERT_NOT_REACHED(); // LocalDOMWindow has [Custom=ToV8].
1666 return v8::Handle<v8::Object>(); 1588 return v8::Handle<v8::Object>();
1667 } 1589 }
1668 1590
1669 } // namespace blink 1591 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698