mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-21 14:47:31 +09:00
CSP 2 - ignore (x-)frame-options if CSP with frame-ancestors directive exists
This commit is contained in:
parent
ed463cec3e
commit
a01c9abce8
13 changed files with 197 additions and 34 deletions
|
|
@ -22,6 +22,7 @@
|
||||||
#include "nsIScriptError.h"
|
#include "nsIScriptError.h"
|
||||||
#include "nsDocShellLoadTypes.h"
|
#include "nsDocShellLoadTypes.h"
|
||||||
#include "nsIMultiPartChannel.h"
|
#include "nsIMultiPartChannel.h"
|
||||||
|
#include "mozilla/dom/nsCSPUtils.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
|
|
@ -84,14 +85,6 @@ nsDSURIContentListener::DoContent(const nsACString& aContentType,
|
||||||
NS_ENSURE_ARG_POINTER(aContentHandler);
|
NS_ENSURE_ARG_POINTER(aContentHandler);
|
||||||
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
// Check whether X-Frame-Options permits us to load this content in an
|
|
||||||
// iframe and abort the load (unless we've disabled x-frame-options
|
|
||||||
// checking).
|
|
||||||
if (!CheckFrameOptions(aRequest)) {
|
|
||||||
*aAbortProcess = true;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aAbortProcess = false;
|
*aAbortProcess = false;
|
||||||
|
|
||||||
// determine if the channel has just been retargeted to us...
|
// determine if the channel has just been retargeted to us...
|
||||||
|
|
@ -265,9 +258,10 @@ nsDSURIContentListener::SetParentContentListener(
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
/* static */ bool
|
||||||
nsDSURIContentListener::CheckOneFrameOptionsPolicy(nsIHttpChannel* aHttpChannel,
|
nsDSURIContentListener::CheckOneFrameOptionsPolicy(nsIHttpChannel* aHttpChannel,
|
||||||
const nsAString& aPolicy)
|
const nsAString& aPolicy,
|
||||||
|
nsIDocShell* aDocShell)
|
||||||
{
|
{
|
||||||
static const char allowFrom[] = "allow-from";
|
static const char allowFrom[] = "allow-from";
|
||||||
const uint32_t allowFromLen = ArrayLength(allowFrom) - 1;
|
const uint32_t allowFromLen = ArrayLength(allowFrom) - 1;
|
||||||
|
|
@ -285,7 +279,7 @@ nsDSURIContentListener::CheckOneFrameOptionsPolicy(nsIHttpChannel* aHttpChannel,
|
||||||
aHttpChannel->GetURI(getter_AddRefs(uri));
|
aHttpChannel->GetURI(getter_AddRefs(uri));
|
||||||
|
|
||||||
// XXXkhuey when does this happen? Is returning true safe here?
|
// XXXkhuey when does this happen? Is returning true safe here?
|
||||||
if (!mDocShell) {
|
if (!aDocShell) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -293,7 +287,7 @@ nsDSURIContentListener::CheckOneFrameOptionsPolicy(nsIHttpChannel* aHttpChannel,
|
||||||
// window, if we're not the top. X-F-O: SAMEORIGIN requires that the
|
// 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
|
// document must be same-origin with top window. X-F-O: DENY requires that
|
||||||
// the document must never be framed.
|
// the document must never be framed.
|
||||||
nsCOMPtr<nsPIDOMWindowOuter> thisWindow = mDocShell->GetWindow();
|
nsCOMPtr<nsPIDOMWindowOuter> thisWindow = aDocShell->GetWindow();
|
||||||
// If we don't have DOMWindow there is no risk of clickjacking
|
// If we don't have DOMWindow there is no risk of clickjacking
|
||||||
if (!thisWindow) {
|
if (!thisWindow) {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -313,7 +307,7 @@ nsDSURIContentListener::CheckOneFrameOptionsPolicy(nsIHttpChannel* aHttpChannel,
|
||||||
// content-type docshell doesn't work because some chrome documents are
|
// content-type docshell doesn't work because some chrome documents are
|
||||||
// loaded in content docshells (see bug 593387).
|
// loaded in content docshells (see bug 593387).
|
||||||
nsCOMPtr<nsIDocShellTreeItem> thisDocShellItem(
|
nsCOMPtr<nsIDocShellTreeItem> thisDocShellItem(
|
||||||
do_QueryInterface(static_cast<nsIDocShell*>(mDocShell)));
|
do_QueryInterface(static_cast<nsIDocShell*>(aDocShell)));
|
||||||
nsCOMPtr<nsIDocShellTreeItem> parentDocShellItem;
|
nsCOMPtr<nsIDocShellTreeItem> parentDocShellItem;
|
||||||
nsCOMPtr<nsIDocShellTreeItem> curDocShellItem = thisDocShellItem;
|
nsCOMPtr<nsIDocShellTreeItem> curDocShellItem = thisDocShellItem;
|
||||||
nsCOMPtr<nsIDocument> topDoc;
|
nsCOMPtr<nsIDocument> topDoc;
|
||||||
|
|
@ -402,22 +396,66 @@ nsDSURIContentListener::CheckOneFrameOptionsPolicy(nsIHttpChannel* aHttpChannel,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore x-frame-options if CSP with frame-ancestors exists
|
||||||
|
static bool
|
||||||
|
ShouldIgnoreFrameOptions(nsIChannel* aChannel, nsIPrincipal* aPrincipal)
|
||||||
|
{
|
||||||
|
NS_ENSURE_TRUE(aChannel, false);
|
||||||
|
NS_ENSURE_TRUE(aPrincipal, false);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
||||||
|
aPrincipal->GetCsp(getter_AddRefs(csp));
|
||||||
|
if (!csp) {
|
||||||
|
// if there is no CSP, then there is nothing to do here
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool enforcesFrameAncestors = false;
|
||||||
|
csp->GetEnforcesFrameAncestors(&enforcesFrameAncestors);
|
||||||
|
if (!enforcesFrameAncestors) {
|
||||||
|
// if CSP does not contain frame-ancestors, then there
|
||||||
|
// is nothing to do here.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// log warning to console that xfo is ignored because of CSP
|
||||||
|
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
|
||||||
|
uint64_t innerWindowID = loadInfo ? loadInfo->GetInnerWindowID() : 0;
|
||||||
|
const char16_t* params[] = { u"x-frame-options",
|
||||||
|
u"frame-ancestors" };
|
||||||
|
CSP_LogLocalizedStr(u"IgnoringSrcBecauseOfDirective",
|
||||||
|
params, ArrayLength(params),
|
||||||
|
EmptyString(), // no sourcefile
|
||||||
|
EmptyString(), // no scriptsample
|
||||||
|
0, // no linenumber
|
||||||
|
0, // no columnnumber
|
||||||
|
nsIScriptError::warningFlag,
|
||||||
|
"CSP", innerWindowID);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if X-Frame-Options permits this document to be loaded as a subdocument.
|
// Check if X-Frame-Options permits this document to be loaded as a subdocument.
|
||||||
// This will iterate through and check any number of X-Frame-Options policies
|
// This will iterate through and check any number of X-Frame-Options policies
|
||||||
// in the request (comma-separated in a header, multiple headers, etc).
|
// in the request (comma-separated in a header, multiple headers, etc).
|
||||||
bool
|
/* static */ bool
|
||||||
nsDSURIContentListener::CheckFrameOptions(nsIRequest* aRequest)
|
nsDSURIContentListener::CheckFrameOptions(nsIChannel* aChannel,
|
||||||
|
nsIDocShell* aDocShell,
|
||||||
|
nsIPrincipal* aPrincipal)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
if (!aChannel || !aDocShell) {
|
||||||
nsCOMPtr<nsIChannel> chan = do_QueryInterface(aRequest);
|
|
||||||
if (!chan) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(chan);
|
if (ShouldIgnoreFrameOptions(aChannel, aPrincipal)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult rv;
|
||||||
|
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
|
||||||
if (!httpChannel) {
|
if (!httpChannel) {
|
||||||
// check if it is hiding in a multipart channel
|
// check if it is hiding in a multipart channel
|
||||||
rv = mDocShell->GetHttpChannel(chan, getter_AddRefs(httpChannel));
|
rv = nsDocShell::Cast(aDocShell)->GetHttpChannel(aChannel, getter_AddRefs(httpChannel));
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -442,11 +480,11 @@ nsDSURIContentListener::CheckFrameOptions(nsIRequest* aRequest)
|
||||||
nsCharSeparatedTokenizer tokenizer(xfoHeaderValue, ',');
|
nsCharSeparatedTokenizer tokenizer(xfoHeaderValue, ',');
|
||||||
while (tokenizer.hasMoreTokens()) {
|
while (tokenizer.hasMoreTokens()) {
|
||||||
const nsSubstring& tok = tokenizer.nextToken();
|
const nsSubstring& tok = tokenizer.nextToken();
|
||||||
if (!CheckOneFrameOptionsPolicy(httpChannel, tok)) {
|
if (!CheckOneFrameOptionsPolicy(httpChannel, tok, aDocShell)) {
|
||||||
// cancel the load and display about:blank
|
// cancel the load and display about:blank
|
||||||
httpChannel->Cancel(NS_BINDING_ABORTED);
|
httpChannel->Cancel(NS_BINDING_ABORTED);
|
||||||
if (mDocShell) {
|
if (aDocShell) {
|
||||||
nsCOMPtr<nsIWebNavigation> webNav(do_QueryObject(mDocShell));
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryObject(aDocShell));
|
||||||
if (webNav) {
|
if (webNav) {
|
||||||
webNav->LoadURI(u"about:blank",
|
webNav->LoadURI(u"about:blank",
|
||||||
0, nullptr, nullptr, nullptr);
|
0, nullptr, nullptr, nullptr);
|
||||||
|
|
@ -459,7 +497,7 @@ nsDSURIContentListener::CheckFrameOptions(nsIRequest* aRequest)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
/* static */ void
|
||||||
nsDSURIContentListener::ReportXFOViolation(nsIDocShellTreeItem* aTopDocShellItem,
|
nsDSURIContentListener::ReportXFOViolation(nsIDocShellTreeItem* aTopDocShellItem,
|
||||||
nsIURI* aThisURI,
|
nsIURI* aThisURI,
|
||||||
XFOHeader aHeader)
|
XFOHeader aHeader)
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@ public:
|
||||||
|
|
||||||
nsresult Init();
|
nsresult Init();
|
||||||
|
|
||||||
|
// Determine if X-Frame-Options allows content to be framed
|
||||||
|
// as a subdocument
|
||||||
|
static bool CheckFrameOptions(nsIChannel* aChannel,
|
||||||
|
nsIDocShell* aDocShell,
|
||||||
|
nsIPrincipal* aPrincipal);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit nsDSURIContentListener(nsDocShell* aDocShell);
|
explicit nsDSURIContentListener(nsDocShell* aDocShell);
|
||||||
virtual ~nsDSURIContentListener();
|
virtual ~nsDSURIContentListener();
|
||||||
|
|
@ -39,12 +45,9 @@ protected:
|
||||||
mExistingJPEGStreamListener = nullptr;
|
mExistingJPEGStreamListener = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if X-Frame-Options allows content to be framed
|
static bool CheckOneFrameOptionsPolicy(nsIHttpChannel* aHttpChannel,
|
||||||
// as a subdocument
|
const nsAString& aPolicy,
|
||||||
bool CheckFrameOptions(nsIRequest* aRequest);
|
nsIDocShell* aDocShell);
|
||||||
bool CheckOneFrameOptionsPolicy(nsIHttpChannel* aHttpChannel,
|
|
||||||
const nsAString& aPolicy);
|
|
||||||
|
|
||||||
enum XFOHeader
|
enum XFOHeader
|
||||||
{
|
{
|
||||||
eDENY,
|
eDENY,
|
||||||
|
|
@ -52,9 +55,9 @@ protected:
|
||||||
eALLOWFROM
|
eALLOWFROM
|
||||||
};
|
};
|
||||||
|
|
||||||
void ReportXFOViolation(nsIDocShellTreeItem* aTopDocShellItem,
|
static void ReportXFOViolation(nsIDocShellTreeItem* aTopDocShellItem,
|
||||||
nsIURI* aThisURI,
|
nsIURI* aThisURI,
|
||||||
XFOHeader aHeader);
|
XFOHeader aHeader);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
nsDocShell* mDocShell;
|
nsDocShell* mDocShell;
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@
|
||||||
#include "nsGenericHTMLElement.h"
|
#include "nsGenericHTMLElement.h"
|
||||||
#include "mozilla/dom/CDATASection.h"
|
#include "mozilla/dom/CDATASection.h"
|
||||||
#include "mozilla/dom/ProcessingInstruction.h"
|
#include "mozilla/dom/ProcessingInstruction.h"
|
||||||
|
#include "nsDSURIContentListener.h"
|
||||||
#include "nsDOMString.h"
|
#include "nsDOMString.h"
|
||||||
#include "nsNodeUtils.h"
|
#include "nsNodeUtils.h"
|
||||||
#include "nsLayoutUtils.h" // for GetFrameForPoint
|
#include "nsLayoutUtils.h" // for GetFrameForPoint
|
||||||
|
|
@ -2456,6 +2457,15 @@ nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XFO needs to be checked after CSP because it is ignored if
|
||||||
|
// the CSP defines frame-ancestors.
|
||||||
|
if (!nsDSURIContentListener::CheckFrameOptions(aChannel, docShell, NodePrincipal())) {
|
||||||
|
MOZ_LOG(gCspPRLog, LogLevel::Debug,
|
||||||
|
("XFO doesn't like frame's ancestry, not loading."));
|
||||||
|
// stop! ERROR page!
|
||||||
|
aChannel->Cancel(NS_ERROR_CSP_FRAME_ANCESTOR_VIOLATION);
|
||||||
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1491,7 +1491,6 @@ private:
|
||||||
void PostUnblockOnloadEvent();
|
void PostUnblockOnloadEvent();
|
||||||
void DoUnblockOnload();
|
void DoUnblockOnload();
|
||||||
|
|
||||||
nsresult CheckFrameOptions();
|
|
||||||
nsresult InitCSP(nsIChannel* aChannel);
|
nsresult InitCSP(nsIChannel* aChannel);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,11 @@ interface nsIContentSecurityPolicy : nsISerializable
|
||||||
*/
|
*/
|
||||||
readonly attribute bool blockAllMixedContent;
|
readonly attribute bool blockAllMixedContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this policy enforces the frame-ancestors directive.
|
||||||
|
*/
|
||||||
|
readonly attribute bool enforcesFrameAncestors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the referrer policy (as integer) for this browsing context as
|
* Obtains the referrer policy (as integer) for this browsing context as
|
||||||
* specified in CSP. If there are multiple policies and...
|
* specified in CSP. If there are multiple policies and...
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,10 @@ ignoringReportOnlyDirective = Ignoring sandbox directive when delivered in a rep
|
||||||
# LOCALIZATION NOTE (deprecatedReferrerDirective):
|
# LOCALIZATION NOTE (deprecatedReferrerDirective):
|
||||||
# %1$S is the value of the deprecated Referrer Directive.
|
# %1$S is the value of the deprecated Referrer Directive.
|
||||||
deprecatedReferrerDirective = Referrer Directive ‘%1$S’ has been deprecated. Please use the Referrer-Policy header instead.
|
deprecatedReferrerDirective = Referrer Directive ‘%1$S’ has been deprecated. Please use the Referrer-Policy header instead.
|
||||||
|
# LOCALIZATION NOTE (IgnoringSrcBecauseOfDirective):
|
||||||
|
# %1$S is the name of the src that is ignored.
|
||||||
|
# %2$S is the name of the directive that causes the src to be ignored.
|
||||||
|
IgnoringSrcBecauseOfDirective=Ignoring ‘%1$S’ because of ‘%2$S’ directive.
|
||||||
|
|
||||||
# CSP Errors:
|
# CSP Errors:
|
||||||
# LOCALIZATION NOTE (couldntParseInvalidSource):
|
# LOCALIZATION NOTE (couldntParseInvalidSource):
|
||||||
|
|
|
||||||
|
|
@ -342,6 +342,20 @@ nsCSPContext::GetBlockAllMixedContent(bool *outBlockAllMixedContent)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsCSPContext::GetEnforcesFrameAncestors(bool *outEnforcesFrameAncestors)
|
||||||
|
{
|
||||||
|
*outEnforcesFrameAncestors = false;
|
||||||
|
for (uint32_t i = 0; i < mPolicies.Length(); i++) {
|
||||||
|
if (!mPolicies[i]->getReportOnlyFlag() &&
|
||||||
|
mPolicies[i]->hasDirective(nsIContentSecurityPolicy::FRAME_ANCESTORS_DIRECTIVE)) {
|
||||||
|
*outEnforcesFrameAncestors = true;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsCSPContext::GetReferrerPolicy(uint32_t* outPolicy, bool* outIsSet)
|
nsCSPContext::GetReferrerPolicy(uint32_t* outPolicy, bool* outIsSet)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
10
dom/security/test/csp/file_ignore_xfo.html
Normal file
10
dom/security/test/csp/file_ignore_xfo.html
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Bug 1024557: Ignore x-frame-options if CSP with frame-ancestors exists</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="cspmessage">Ignoring XFO because of CSP</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
3
dom/security/test/csp/file_ignore_xfo.html^headers^
Normal file
3
dom/security/test/csp/file_ignore_xfo.html^headers^
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
Content-Security-Policy: frame-ancestors http://mochi.test:8888
|
||||||
|
X-Frame-Options: deny
|
||||||
|
Cache-Control: no-cache
|
||||||
10
dom/security/test/csp/file_ro_ignore_xfo.html
Normal file
10
dom/security/test/csp/file_ro_ignore_xfo.html
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Bug 1024557: Ignore x-frame-options if CSP with frame-ancestors exists</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="cspmessage">Ignoring XFO because of CSP_RO</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
3
dom/security/test/csp/file_ro_ignore_xfo.html^headers^
Normal file
3
dom/security/test/csp/file_ro_ignore_xfo.html^headers^
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
Content-Security-Policy-Report-Only: frame-ancestors http://mochi.test:8888
|
||||||
|
X-Frame-Options: deny
|
||||||
|
Cache-Control: no-cache
|
||||||
|
|
@ -206,6 +206,10 @@ support-files =
|
||||||
file_iframe_srcdoc.sjs
|
file_iframe_srcdoc.sjs
|
||||||
file_iframe_sandbox_srcdoc.html
|
file_iframe_sandbox_srcdoc.html
|
||||||
file_iframe_sandbox_srcdoc.html^headers^
|
file_iframe_sandbox_srcdoc.html^headers^
|
||||||
|
file_ignore_xfo.html
|
||||||
|
file_ignore_xfo.html^headers^
|
||||||
|
file_ro_ignore_xfo.html
|
||||||
|
file_ro_ignore_xfo.html^headers^
|
||||||
|
|
||||||
[test_base-uri.html]
|
[test_base-uri.html]
|
||||||
[test_blob_data_schemes.html]
|
[test_blob_data_schemes.html]
|
||||||
|
|
@ -298,3 +302,4 @@ tags = mcb
|
||||||
support-files =
|
support-files =
|
||||||
file_sandbox_allow_scripts.html
|
file_sandbox_allow_scripts.html
|
||||||
file_sandbox_allow_scripts.html^headers^
|
file_sandbox_allow_scripts.html^headers^
|
||||||
|
[test_ignore_xfo.html]
|
||||||
|
|
|
||||||
59
dom/security/test/csp/test_ignore_xfo.html
Normal file
59
dom/security/test/csp/test_ignore_xfo.html
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Bug 1024557: Ignore x-frame-options if CSP with frame-ancestors exists</title>
|
||||||
|
<!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
|
||||||
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<iframe style="width:100%;" id="csp_testframe"></iframe>
|
||||||
|
<iframe style="width:100%;" id="csp_ro_testframe"></iframe>
|
||||||
|
|
||||||
|
<script class="testbody" type="text/javascript">
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We load two frames using:
|
||||||
|
* x-frame-options: deny
|
||||||
|
* where the first frame uses a csp and the second a csp_ro including frame-ancestors.
|
||||||
|
* We make sure that xfo is ignored for regular csp but not for csp_ro.
|
||||||
|
*/
|
||||||
|
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
|
var testcounter = 0;
|
||||||
|
function checkFinished() {
|
||||||
|
testcounter++;
|
||||||
|
if (testcounter < 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1) test XFO with CSP
|
||||||
|
var csp_testframe = document.getElementById("csp_testframe");
|
||||||
|
csp_testframe.onload = function() {
|
||||||
|
var msg = csp_testframe.contentWindow.document.getElementById("cspmessage");
|
||||||
|
is(msg.innerHTML, "Ignoring XFO because of CSP", "Loading frame with with XFO and CSP");
|
||||||
|
checkFinished();
|
||||||
|
}
|
||||||
|
csp_testframe.onerror = function() {
|
||||||
|
ok(false, "sanity: should not fire onerror for csp_testframe");
|
||||||
|
}
|
||||||
|
csp_testframe.src = "file_ignore_xfo.html";
|
||||||
|
|
||||||
|
// 2) test XFO with CSP_RO
|
||||||
|
var csp_ro_testframe = document.getElementById("csp_ro_testframe");
|
||||||
|
csp_ro_testframe.onload = function() {
|
||||||
|
var msg = csp_ro_testframe.contentWindow.document.getElementById("cspmessage");
|
||||||
|
is(msg, null, "Blocking frame with with XFO and CSP_RO");
|
||||||
|
checkFinished();
|
||||||
|
}
|
||||||
|
csp_ro_testframe.onerror = function() {
|
||||||
|
ok(false, "sanity: should not fire onerror for csp_ro_testframe");
|
||||||
|
}
|
||||||
|
csp_ro_testframe.src = "file_ro_ignore_xfo.html";
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue