mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
721ef90dc3
- Bug 1107096 - Suppress improper drawing of zero-width invisible glyphs in canvas. r=roc (6f78376bc)
- Bug 1107096 - Reftest for zero-width invisible glyphs in canvas. (ded6cb516)
- Bug 1153958 - Make manifest processor e10s friendly. r=ehsan (ba5f6edf5)
- Bug 1162808 - Add splash_screens support to web manifest processor. r=ehsan (688bbe3d6)
- Bug 1164235 - Add theme_color support to web manifest processor. r=ehsan (0134f58fe)
- Bug 1143879 - Implement lang member of Web manifest. r=ehsan. (0b426965a)
- Bug 1166405 - Consolidate classes into a general web manifest module. r=ehsan. (98a6a4531)
- Bug 1162729 - CORS check is always performed when fetching a manifest. r=ehsan (aab278c12)
- Bug 1167335 - Make manifest obtainer use Task.jsm. r=oyiptong. (a4a48d767)
- Bug 1089255 - Implement and test manifest-src CSP directive. r=bholley, r=dveditz, r=ckerschb (63353eff3)
- Bug 968520 - Use move assignment instead of fallible copy assignment in nsCSPUtils.cpp. r=froydnj (fcaa9e865)
- Bug 968520 - Add mozilla::fallible to Fallible{Auto,}TArray::ReplaceElementsAt calls. r=froydnj (fb81d2305)
- Bug 968520 - Use FallibleTArray::Clear instead of SetLength(0). r=froydnj (3945e3e86)
- Bug 968520 - Add mozilla::fallible to FallibleTArray::InsertElementSorted calls. r=froydnj (dda295d5b)
- make some calls fallible - to get 968520 working (7722d850e)
- Bug 968520 - Always require fallible argument with FallibleTArray calls. r=froydnj (b9e630a76)
- Bug 968520 - Add mozilla::fallible to FallibleArray calls in tests. r=froydnj (53b58ac40)
- Bug 968520 - Explicitly use infallible allocator for ShiftData call in nsTArray::RemoveElementsAt. r=froydnj (9453996c3)
- Bug 1182808 - Part 1: Add and use fallible variant of AlignedTArray_Impl::SetLength. r=padenot (f6330791d)
- Bug 1143575. Replace ImageContainer Lock methods with simplified AutoLockImage. r=nical (c87ffec51)
155 lines
6.1 KiB
C++
155 lines
6.1 KiB
C++
/* -*- 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/. */
|
|
|
|
/*
|
|
* Content policy implementation that prevents all loads of images,
|
|
* subframes, etc from documents loaded as data (eg documents loaded
|
|
* via XMLHttpRequest).
|
|
*/
|
|
|
|
#include "nsDataDocumentContentPolicy.h"
|
|
#include "nsNetUtil.h"
|
|
#include "nsScriptSecurityManager.h"
|
|
#include "nsIDocument.h"
|
|
#include "nsINode.h"
|
|
#include "nsIDOMWindow.h"
|
|
|
|
NS_IMPL_ISUPPORTS(nsDataDocumentContentPolicy, nsIContentPolicy)
|
|
|
|
// Helper method for ShouldLoad()
|
|
// Checks a URI for the given flags. Returns true if the URI has the flags,
|
|
// and false if not (or if we weren't able to tell).
|
|
static bool
|
|
HasFlags(nsIURI* aURI, uint32_t aURIFlags)
|
|
{
|
|
bool hasFlags;
|
|
nsresult rv = NS_URIChainHasFlags(aURI, aURIFlags, &hasFlags);
|
|
return NS_SUCCEEDED(rv) && hasFlags;
|
|
}
|
|
|
|
// If you change DataDocumentContentPolicy, make sure to check that
|
|
// CHECK_PRINCIPAL_AND_DATA in nsContentPolicyUtils is still valid.
|
|
// nsContentPolicyUtils may not pass all the parameters to ShouldLoad.
|
|
NS_IMETHODIMP
|
|
nsDataDocumentContentPolicy::ShouldLoad(uint32_t aContentType,
|
|
nsIURI *aContentLocation,
|
|
nsIURI *aRequestingLocation,
|
|
nsISupports *aRequestingContext,
|
|
const nsACString &aMimeGuess,
|
|
nsISupports *aExtra,
|
|
nsIPrincipal *aRequestPrincipal,
|
|
int16_t *aDecision)
|
|
{
|
|
MOZ_ASSERT(aContentType == nsContentUtils::InternalContentPolicyTypeToExternal(aContentType),
|
|
"We should only see external content policy types here.");
|
|
|
|
*aDecision = nsIContentPolicy::ACCEPT;
|
|
// Look for the document. In most cases, aRequestingContext is a node.
|
|
nsCOMPtr<nsIDocument> doc;
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aRequestingContext);
|
|
if (node) {
|
|
doc = node->OwnerDoc();
|
|
} else {
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aRequestingContext);
|
|
if (window) {
|
|
doc = window->GetDoc();
|
|
}
|
|
}
|
|
|
|
// DTDs are always OK to load
|
|
if (!doc || aContentType == nsIContentPolicy::TYPE_DTD) {
|
|
return NS_OK;
|
|
}
|
|
|
|
// Nothing else is OK to load for data documents
|
|
if (doc->IsLoadedAsData()) {
|
|
// ...but let static (print/print preview) documents to load fonts.
|
|
if (!doc->IsStaticDocument() || aContentType != nsIContentPolicy::TYPE_FONT) {
|
|
*aDecision = nsIContentPolicy::REJECT_TYPE;
|
|
return NS_OK;
|
|
}
|
|
}
|
|
|
|
if (doc->IsBeingUsedAsImage()) {
|
|
// We only allow SVG images to load content from URIs that are local and
|
|
// also satisfy one of the following conditions:
|
|
// - URI inherits security context, e.g. data URIs
|
|
// OR
|
|
// - URI loadable by subsumers, e.g. blob URIs
|
|
// Any URI that doesn't meet these requirements will be rejected below.
|
|
if (!HasFlags(aContentLocation,
|
|
nsIProtocolHandler::URI_IS_LOCAL_RESOURCE) ||
|
|
(!HasFlags(aContentLocation,
|
|
nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT) &&
|
|
!HasFlags(aContentLocation,
|
|
nsIProtocolHandler::URI_LOADABLE_BY_SUBSUMERS))) {
|
|
*aDecision = nsIContentPolicy::REJECT_TYPE;
|
|
|
|
// Report error, if we can.
|
|
if (node) {
|
|
nsIPrincipal* requestingPrincipal = node->NodePrincipal();
|
|
nsRefPtr<nsIURI> principalURI;
|
|
nsresult rv =
|
|
requestingPrincipal->GetURI(getter_AddRefs(principalURI));
|
|
if (NS_SUCCEEDED(rv) && principalURI) {
|
|
nsScriptSecurityManager::ReportError(
|
|
nullptr, NS_LITERAL_STRING("CheckSameOriginError"), principalURI,
|
|
aContentLocation);
|
|
}
|
|
}
|
|
} else if ((aContentType == nsIContentPolicy::TYPE_IMAGE ||
|
|
aContentType == nsIContentPolicy::TYPE_IMAGESET) &&
|
|
doc->GetDocumentURI()) {
|
|
// Check for (& disallow) recursive image-loads
|
|
bool isRecursiveLoad;
|
|
nsresult rv = aContentLocation->EqualsExceptRef(doc->GetDocumentURI(),
|
|
&isRecursiveLoad);
|
|
if (NS_FAILED(rv) || isRecursiveLoad) {
|
|
NS_WARNING("Refusing to recursively load image");
|
|
*aDecision = nsIContentPolicy::REJECT_TYPE;
|
|
}
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
// Allow all loads for non-resource documents
|
|
if (!doc->IsResourceDoc()) {
|
|
return NS_OK;
|
|
}
|
|
|
|
// For resource documents, blacklist some load types
|
|
if (aContentType == nsIContentPolicy::TYPE_OBJECT ||
|
|
aContentType == nsIContentPolicy::TYPE_DOCUMENT ||
|
|
aContentType == nsIContentPolicy::TYPE_SUBDOCUMENT ||
|
|
aContentType == nsIContentPolicy::TYPE_SCRIPT ||
|
|
aContentType == nsIContentPolicy::TYPE_XSLT ||
|
|
aContentType == nsIContentPolicy::TYPE_FETCH ||
|
|
aContentType == nsIContentPolicy::TYPE_WEB_MANIFEST) {
|
|
*aDecision = nsIContentPolicy::REJECT_TYPE;
|
|
}
|
|
|
|
// If you add more restrictions here, make sure to check that
|
|
// CHECK_PRINCIPAL_AND_DATA in nsContentPolicyUtils is still valid.
|
|
// nsContentPolicyUtils may not pass all the parameters to ShouldLoad
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsDataDocumentContentPolicy::ShouldProcess(uint32_t aContentType,
|
|
nsIURI *aContentLocation,
|
|
nsIURI *aRequestingLocation,
|
|
nsISupports *aRequestingContext,
|
|
const nsACString &aMimeGuess,
|
|
nsISupports *aExtra,
|
|
nsIPrincipal *aRequestPrincipal,
|
|
int16_t *aDecision)
|
|
{
|
|
return ShouldLoad(aContentType, aContentLocation, aRequestingLocation,
|
|
aRequestingContext, aMimeGuess, aExtra, aRequestPrincipal,
|
|
aDecision);
|
|
}
|