michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 sw=2 et tw=78: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "WindowNamedPropertiesHandler.h" michael@0: #include "mozilla/dom/WindowBinding.h" michael@0: #include "nsDOMClassInfo.h" michael@0: #include "nsGlobalWindow.h" michael@0: #include "nsHTMLDocument.h" michael@0: #include "nsJSUtils.h" michael@0: #include "xpcprivate.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: static bool michael@0: ShouldExposeChildWindow(nsString& aNameBeingResolved, nsIDOMWindow *aChild) michael@0: { michael@0: // If we're same-origin with the child, go ahead and expose it. michael@0: nsCOMPtr sop = do_QueryInterface(aChild); michael@0: NS_ENSURE_TRUE(sop, false); michael@0: if (nsContentUtils::GetSubjectPrincipal()->Equals(sop->GetPrincipal())) { michael@0: return true; michael@0: } michael@0: michael@0: // If we're not same-origin, expose it _only_ if the name of the browsing michael@0: // context matches the 'name' attribute of the frame element in the parent. michael@0: // The motivations behind this heuristic are worth explaining here. michael@0: // michael@0: // Historically, all UAs supported global named access to any child browsing michael@0: // context (that is to say, window.dolske returns a child frame where either michael@0: // the "name" attribute on the frame element was set to "dolske", or where michael@0: // the child explicitly set window.name = "dolske"). michael@0: // michael@0: // This is problematic because it allows possibly-malicious and unrelated michael@0: // cross-origin subframes to pollute the global namespace of their parent in michael@0: // unpredictable ways (see bug 860494). This is also problematic for browser michael@0: // engines like Servo that want to run cross-origin script on different michael@0: // threads. michael@0: // michael@0: // The naive solution here would be to filter out any cross-origin subframes michael@0: // obtained when doing named lookup in global scope. But that is unlikely to michael@0: // be web-compatible, since it will break named access for consumers that do michael@0: //