| OLD | NEW |
| 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 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1493 { | 1493 { |
| 1494 if (!isCurrentlyDisplayedInFrame()) | 1494 if (!isCurrentlyDisplayedInFrame()) |
| 1495 return; | 1495 return; |
| 1496 | 1496 |
| 1497 if (message.isEmpty()) | 1497 if (message.isEmpty()) |
| 1498 return; | 1498 return; |
| 1499 | 1499 |
| 1500 frameConsole()->addMessage(ConsoleMessage::create(JSMessageSource, ErrorMess
ageLevel, message)); | 1500 frameConsole()->addMessage(ConsoleMessage::create(JSMessageSource, ErrorMess
ageLevel, message)); |
| 1501 } | 1501 } |
| 1502 | 1502 |
| 1503 // FIXME: Once we're throwing exceptions for cross-origin access violations, we
will always sanitize the target | |
| 1504 // frame details, so we can safely combine 'crossDomainAccessErrorMessage' with
this method after considering | |
| 1505 // exactly which details may be exposed to JavaScript. | |
| 1506 // | |
| 1507 // http://crbug.com/17325 | |
| 1508 String LocalDOMWindow::sanitizedCrossDomainAccessErrorMessage(LocalDOMWindow* ca
llingWindow) | |
| 1509 { | |
| 1510 if (!callingWindow || !callingWindow->document()) | |
| 1511 return String(); | |
| 1512 | |
| 1513 const KURL& callingWindowURL = callingWindow->document()->url(); | |
| 1514 if (callingWindowURL.isNull()) | |
| 1515 return String(); | |
| 1516 | |
| 1517 ASSERT(!callingWindow->document()->securityOrigin()->canAccess(document()->s
ecurityOrigin())); | |
| 1518 | |
| 1519 SecurityOrigin* activeOrigin = callingWindow->document()->securityOrigin(); | |
| 1520 String message = "Blocked a frame with origin \"" + activeOrigin->toString()
+ "\" from accessing a cross-origin frame."; | |
| 1521 | |
| 1522 // FIXME: Evaluate which details from 'crossDomainAccessErrorMessage' may sa
fely be reported to JavaScript. | |
| 1523 | |
| 1524 return message; | |
| 1525 } | |
| 1526 | |
| 1527 String LocalDOMWindow::crossDomainAccessErrorMessage(LocalDOMWindow* callingWind
ow) | |
| 1528 { | |
| 1529 if (!callingWindow || !callingWindow->document()) | |
| 1530 return String(); | |
| 1531 | |
| 1532 const KURL& callingWindowURL = callingWindow->document()->url(); | |
| 1533 if (callingWindowURL.isNull()) | |
| 1534 return String(); | |
| 1535 | |
| 1536 ASSERT(!callingWindow->document()->securityOrigin()->canAccess(document()->s
ecurityOrigin())); | |
| 1537 | |
| 1538 // FIXME: This message, and other console messages, have extra newlines. Sho
uld remove them. | |
| 1539 SecurityOrigin* activeOrigin = callingWindow->document()->securityOrigin(); | |
| 1540 SecurityOrigin* targetOrigin = document()->securityOrigin(); | |
| 1541 String message = "Blocked a frame with origin \"" + activeOrigin->toString()
+ "\" from accessing a frame with origin \"" + targetOrigin->toString() + "\".
"; | |
| 1542 | |
| 1543 // Sandbox errors: Use the origin of the frames' location, rather than their
actual origin (since we know that at least one will be "null"). | |
| 1544 KURL activeURL = callingWindow->document()->url(); | |
| 1545 KURL targetURL = document()->url(); | |
| 1546 if (document()->isSandboxed(SandboxOrigin) || callingWindow->document()->isS
andboxed(SandboxOrigin)) { | |
| 1547 message = "Blocked a frame at \"" + SecurityOrigin::create(activeURL)->t
oString() + "\" from accessing a frame at \"" + SecurityOrigin::create(targetURL
)->toString() + "\". "; | |
| 1548 if (document()->isSandboxed(SandboxOrigin) && callingWindow->document()-
>isSandboxed(SandboxOrigin)) | |
| 1549 return "Sandbox access violation: " + message + " Both frames are sa
ndboxed and lack the \"allow-same-origin\" flag."; | |
| 1550 if (document()->isSandboxed(SandboxOrigin)) | |
| 1551 return "Sandbox access violation: " + message + " The frame being ac
cessed is sandboxed and lacks the \"allow-same-origin\" flag."; | |
| 1552 return "Sandbox access violation: " + message + " The frame requesting a
ccess is sandboxed and lacks the \"allow-same-origin\" flag."; | |
| 1553 } | |
| 1554 | |
| 1555 // 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:'. | |
| 1556 if (targetOrigin->protocol() != activeOrigin->protocol()) | |
| 1557 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"; | |
| 1558 | |
| 1559 // 'document.domain' errors. | |
| 1560 if (targetOrigin->domainWasSetInDOM() && activeOrigin->domainWasSetInDOM()) | |
| 1561 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."; | |
| 1562 if (activeOrigin->domainWasSetInDOM()) | |
| 1563 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."; | |
| 1564 if (targetOrigin->domainWasSetInDOM()) | |
| 1565 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."; | |
| 1566 | |
| 1567 // Default. | |
| 1568 return message + "Protocols, domains, and ports must match."; | |
| 1569 } | |
| 1570 | |
| 1571 bool LocalDOMWindow::isInsecureScriptAccess(DOMWindow& callingWindow, const Stri
ng& urlString) | |
| 1572 { | |
| 1573 if (!DOMWindow::isInsecureScriptAccess(callingWindow, urlString)) | |
| 1574 return false; | |
| 1575 | |
| 1576 if (callingWindow.isLocalDOMWindow()) | |
| 1577 printErrorMessage(crossDomainAccessErrorMessage(static_cast<LocalDOMWind
ow*>(&callingWindow))); | |
| 1578 return true; | |
| 1579 } | |
| 1580 | |
| 1581 PassRefPtrWillBeRawPtr<DOMWindow> LocalDOMWindow::open(const String& urlString,
const AtomicString& frameName, const String& windowFeaturesString, | 1503 PassRefPtrWillBeRawPtr<DOMWindow> LocalDOMWindow::open(const String& urlString,
const AtomicString& frameName, const String& windowFeaturesString, |
| 1582 LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWindow) | 1504 LocalDOMWindow* callingWindow, LocalDOMWindow* enteredWindow) |
| 1583 { | 1505 { |
| 1584 if (!isCurrentlyDisplayedInFrame()) | 1506 if (!isCurrentlyDisplayedInFrame()) |
| 1585 return nullptr; | 1507 return nullptr; |
| 1586 Document* activeDocument = callingWindow->document(); | 1508 Document* activeDocument = callingWindow->document(); |
| 1587 if (!activeDocument) | 1509 if (!activeDocument) |
| 1588 return nullptr; | 1510 return nullptr; |
| 1589 LocalFrame* firstFrame = enteredWindow->frame(); | 1511 LocalFrame* firstFrame = enteredWindow->frame(); |
| 1590 if (!firstFrame) | 1512 if (!firstFrame) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1666 return m_frameObserver->frame(); | 1588 return m_frameObserver->frame(); |
| 1667 } | 1589 } |
| 1668 | 1590 |
| 1669 v8::Handle<v8::Object> LocalDOMWindow::wrap(v8::Handle<v8::Object> creationConte
xt, v8::Isolate* isolate) | 1591 v8::Handle<v8::Object> LocalDOMWindow::wrap(v8::Handle<v8::Object> creationConte
xt, v8::Isolate* isolate) |
| 1670 { | 1592 { |
| 1671 ASSERT_NOT_REACHED(); // LocalDOMWindow has [Custom=ToV8]. | 1593 ASSERT_NOT_REACHED(); // LocalDOMWindow has [Custom=ToV8]. |
| 1672 return v8::Handle<v8::Object>(); | 1594 return v8::Handle<v8::Object>(); |
| 1673 } | 1595 } |
| 1674 | 1596 |
| 1675 } // namespace blink | 1597 } // namespace blink |
| OLD | NEW |