diff --git a/content/base/src/nsCSPService.cpp b/content/base/src/nsCSPService.cpp index 2a4172a55389..6cb0bb0cf6c4 100644 --- a/content/base/src/nsCSPService.cpp +++ b/content/base/src/nsCSPService.cpp @@ -55,6 +55,8 @@ #include "nsIAsyncVerifyRedirectCallback.h" #include "nsAsyncRedirectVerifyHelper.h" #include "mozilla/Preferences.h" +#include "nsIScriptError.h" +#include "nsContentUtils.h" using namespace mozilla; @@ -284,10 +286,28 @@ CSPService::AsyncOnChannelRedirect(nsIChannel *oldChannel, // the redirect is permitted, so propagate the Content Security Policy // and load type to the redirecting channel nsresult rv; - nsCOMPtr props2 = do_QueryInterface(newChannel, &rv); - if (props2) - props2->SetPropertyAsInterface(NS_CHANNEL_PROP_CHANNEL_POLICY, - channelPolicy); + nsCOMPtr props2 = do_QueryInterface(newChannel); + if (props2) { + rv = props2->SetPropertyAsInterface(NS_CHANNEL_PROP_CHANNEL_POLICY, + channelPolicy); + if (NS_SUCCEEDED(rv)) { + return NS_OK; + } + } - return NS_OK; + // The redirecting channel isn't a writable property bag, we won't be able + // to enforce the load policy if it redirects again, so we stop it now. + nsXPIDLString message; + nsCAutoString newUriSpec; + newUri->GetSpec(newUriSpec); + const PRUnichar *formatParams[] = { NS_ConvertUTF8toUTF16(newUriSpec).get() }; + if (NS_SUCCEEDED(rv)) { + nsContentUtils::ReportToConsole(nsContentUtils::eDOM_PROPERTIES, + "InvalidRedirectChannelWarning", + formatParams, 1, nsnull, EmptyString(), + 0, 0, nsIScriptError::warningFlag, + "Redirect Error"); + } + + return NS_BINDING_FAILED; } diff --git a/content/base/test/Makefile.in b/content/base/test/Makefile.in index c69a40b06f9a..d7e7b0154d2c 100644 --- a/content/base/test/Makefile.in +++ b/content/base/test/Makefile.in @@ -528,6 +528,9 @@ _TEST_FILES2 = \ test_bug693875.html \ test_nodelist_holes.html \ test_xhr_abort_after_load.html \ + test_bug702439.html \ + test_bug702439.html^headers^ \ + file_bug702439.html \ $(NULL) _CHROME_FILES = \ diff --git a/content/base/test/file_bug702439.html b/content/base/test/file_bug702439.html new file mode 100644 index 000000000000..b679330fbac6 --- /dev/null +++ b/content/base/test/file_bug702439.html @@ -0,0 +1,11 @@ + + + +click + + diff --git a/content/base/test/test_bug702439.html b/content/base/test/test_bug702439.html new file mode 100644 index 000000000000..e1fdecbf8c2d --- /dev/null +++ b/content/base/test/test_bug702439.html @@ -0,0 +1,32 @@ + + + + + Test for Bug 428847 + + + + + + + + diff --git a/content/base/test/test_bug702439.html^headers^ b/content/base/test/test_bug702439.html^headers^ new file mode 100644 index 000000000000..426d8738c602 --- /dev/null +++ b/content/base/test/test_bug702439.html^headers^ @@ -0,0 +1 @@ +X-Content-Security-Policy: default-src *; options inline-script diff --git a/dom/locales/en-US/chrome/dom/dom.properties b/dom/locales/en-US/chrome/dom/dom.properties index e0c93b49128b..12b6b99985be 100644 --- a/dom/locales/en-US/chrome/dom/dom.properties +++ b/dom/locales/en-US/chrome/dom/dom.properties @@ -127,3 +127,4 @@ RemovedFullScreenElement=Exited full-screen because full-screen element was remo AddedWindowedPluginWhileFullScreen=Exited full-screen because windowed plugin was added to document. HTMLMultipartXHRWarning=HTML parsing in XMLHttpRequest is not supported for multipart responses. HTMLSyncXHRWarning=HTML parsing in XMLHttpRequest is not supported in the synchronous mode. +InvalidRedirectChannelWarning=Unable to redirect to %S because the channel doesn't implement nsIWritablePropertyBag2. diff --git a/netwerk/base/public/nsNetUtil.h b/netwerk/base/public/nsNetUtil.h index 99fb93e0a5ba..c718b92233a4 100644 --- a/netwerk/base/public/nsNetUtil.h +++ b/netwerk/base/public/nsNetUtil.h @@ -232,7 +232,7 @@ NS_NewChannel(nsIChannel **result, if (loadFlags != nsIRequest::LOAD_NORMAL) rv |= chan->SetLoadFlags(loadFlags); if (channelPolicy) { - nsCOMPtr props = do_QueryInterface(chan, &rv); + nsCOMPtr props = do_QueryInterface(chan); if (props) { props->SetPropertyAsInterface(NS_CHANNEL_PROP_CHANNEL_POLICY, channelPolicy);