/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "FramingChecker.h" #include "nsCharSeparatedTokenizer.h" #include "nsCSPUtils.h" #include "nsDocShell.h" #include "nsIChannel.h" #include "nsIConsoleService.h" #include "nsIContentSecurityPolicy.h" #include "nsIScriptError.h" #include "nsNetUtil.h" #include "nsQueryObject.h" #include "mozilla/dom/nsCSPUtils.h" using namespace mozilla; /* static */ bool FramingChecker::CheckOneFrameOptionsPolicy(nsIHttpChannel* aHttpChannel, const nsAString& aPolicy, nsIDocShell* aDocShell) { static const char allowFrom[] = "allow-from"; const uint32_t allowFromLen = ArrayLength(allowFrom) - 1; bool isAllowFrom = StringHead(aPolicy, allowFromLen).LowerCaseEqualsLiteral(allowFrom); // return early if header does not have one of the values with meaning if (!aPolicy.LowerCaseEqualsLiteral("deny") && !aPolicy.LowerCaseEqualsLiteral("sameorigin") && !isAllowFrom) { return true; } nsCOMPtr uri; aHttpChannel->GetURI(getter_AddRefs(uri)); // XXXkhuey when does this happen? Is returning true safe here? if (!aDocShell) { return true; } // We need to check the location of this window and the location of the top // window, if we're not the top. X-F-O: SAMEORIGIN requires that the // document must be same-origin with top window. X-F-O: DENY requires that // the document must never be framed. nsCOMPtr thisWindow = aDocShell->GetWindow(); // If we don't have DOMWindow there is no risk of clickjacking if (!thisWindow) { return true; } // GetScriptableTop, not GetTop, because we want this to respect //