Bug 515460 - enforce CSP during frame redirects, r=jst, a=dholbert_sheriff
This commit is contained in:
@@ -220,6 +220,8 @@ static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
||||
#endif
|
||||
|
||||
#include "nsContentErrors.h"
|
||||
#include "nsIChannelPolicy.h"
|
||||
#include "nsIContentSecurityPolicy.h"
|
||||
|
||||
// Number of documents currently loading
|
||||
static PRInt32 gNumberOfDocumentsLoading = 0;
|
||||
@@ -8280,6 +8282,27 @@ nsDocShell::DoURILoad(nsIURI * aURI,
|
||||
loadFlags |= nsIChannel::LOAD_BACKGROUND;
|
||||
}
|
||||
|
||||
// check for Content Security Policy to pass along with the
|
||||
// new channel we are creating
|
||||
nsCOMPtr<nsIChannelPolicy> channelPolicy;
|
||||
if (IsFrame()) {
|
||||
// check the parent docshell for a CSP
|
||||
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
||||
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
||||
GetSameTypeParent(getter_AddRefs(parentItem));
|
||||
nsCOMPtr<nsIDOMDocument> domDoc(do_GetInterface(parentItem));
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
||||
if (doc) {
|
||||
rv = doc->NodePrincipal()->GetCsp(getter_AddRefs(csp));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (csp) {
|
||||
channelPolicy = do_CreateInstance("@mozilla.org/nschannelpolicy;1");
|
||||
channelPolicy->SetContentSecurityPolicy(csp);
|
||||
channelPolicy->SetLoadType(nsIContentPolicy::TYPE_SUBDOCUMENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// open a channel for the url
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
|
||||
@@ -8288,7 +8311,8 @@ nsDocShell::DoURILoad(nsIURI * aURI,
|
||||
nsnull,
|
||||
nsnull,
|
||||
static_cast<nsIInterfaceRequestor *>(this),
|
||||
loadFlags);
|
||||
loadFlags,
|
||||
channelPolicy);
|
||||
if (NS_FAILED(rv)) {
|
||||
if (rv == NS_ERROR_UNKNOWN_PROTOCOL) {
|
||||
// This is a uri with a protocol scheme we don't know how
|
||||
|
||||
Reference in New Issue
Block a user