Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Backed out changeset 09d64535bcda (bug 1216687), a7f1a289dd78, 4dbf06…
Browse files Browse the repository at this point in the history
…183e6c, 26318a5e3006, 9ae2af3cf86d (bug 1226909) for M(1,2,5) oranges. r=backout
  • Loading branch information
Archaeopteryx committed Dec 5, 2015
1 parent 02efc4a commit 879e1b2
Show file tree
Hide file tree
Showing 45 changed files with 726 additions and 792 deletions.
36 changes: 36 additions & 0 deletions caps/nsScriptSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ nsScriptSecurityManager::IsSystemPrincipal(nsIPrincipal* aPrincipal,
////////////////////////////////////
NS_IMPL_ISUPPORTS(nsScriptSecurityManager,
nsIScriptSecurityManager,
nsIChannelEventSink,
nsIObserver)

///////////////////////////////////////////////////
Expand Down Expand Up @@ -1235,6 +1236,41 @@ nsScriptSecurityManager::CanGetService(JSContext *cx,
return NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED;
}

/////////////////////////////////////////////
// Method implementing nsIChannelEventSink //
/////////////////////////////////////////////
NS_IMETHODIMP
nsScriptSecurityManager::AsyncOnChannelRedirect(nsIChannel* oldChannel,
nsIChannel* newChannel,
uint32_t redirFlags,
nsIAsyncVerifyRedirectCallback *cb)
{
nsCOMPtr<nsIPrincipal> oldPrincipal;
GetChannelResultPrincipal(oldChannel, getter_AddRefs(oldPrincipal));

nsCOMPtr<nsIURI> newURI;
newChannel->GetURI(getter_AddRefs(newURI));
nsCOMPtr<nsIURI> newOriginalURI;
newChannel->GetOriginalURI(getter_AddRefs(newOriginalURI));

NS_ENSURE_STATE(oldPrincipal && newURI && newOriginalURI);

const uint32_t flags =
nsIScriptSecurityManager::LOAD_IS_AUTOMATIC_DOCUMENT_REPLACEMENT |
nsIScriptSecurityManager::DISALLOW_SCRIPT;
nsresult rv = CheckLoadURIWithPrincipal(oldPrincipal, newURI, flags);
if (NS_SUCCEEDED(rv) && newOriginalURI != newURI) {
rv = CheckLoadURIWithPrincipal(oldPrincipal, newOriginalURI, flags);
}

if (NS_FAILED(rv))
return rv;

cb->OnRedirectVerifyCallback(NS_OK);
return NS_OK;
}


/////////////////////////////////////
// Method implementing nsIObserver //
/////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions caps/nsScriptSecurityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "nsIAddonPolicyService.h"
#include "nsIPrincipal.h"
#include "nsCOMPtr.h"
#include "nsIChannelEventSink.h"
#include "nsIObserver.h"
#include "nsServiceManagerUtils.h"
#include "plstr.h"
Expand All @@ -38,6 +39,7 @@ class PrincipalOriginAttributes;
{ 0xba, 0x18, 0x00, 0x60, 0xb0, 0xf1, 0x99, 0xa2 }}

class nsScriptSecurityManager final : public nsIScriptSecurityManager,
public nsIChannelEventSink,
public nsIObserver
{
public:
Expand All @@ -47,6 +49,7 @@ class nsScriptSecurityManager final : public nsIScriptSecurityManager,

NS_DECL_ISUPPORTS
NS_DECL_NSISCRIPTSECURITYMANAGER
NS_DECL_NSICHANNELEVENTSINK
NS_DECL_NSIOBSERVER

static nsScriptSecurityManager*
Expand Down
2 changes: 1 addition & 1 deletion dom/base/EventSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ EventSource::InitChannelAndRequestEventSource()
nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS;

if (mWithCredentials) {
securityFlags |= nsILoadInfo::SEC_COOKIES_INCLUDE;
securityFlags |= nsILoadInfo::SEC_REQUIRE_CORS_WITH_CREDENTIALS;
}

nsCOMPtr<nsIChannel> channel;
Expand Down
38 changes: 36 additions & 2 deletions dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,8 +1204,7 @@ Navigator::SendBeacon(const nsAString& aUrl,
rv = NS_NewChannel(getter_AddRefs(channel),
uri,
doc,
nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS |
nsILoadInfo::SEC_COOKIES_INCLUDE,
nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS,
nsIContentPolicy::TYPE_BEACON);

if (NS_FAILED(rv)) {
Expand Down Expand Up @@ -1316,6 +1315,41 @@ Navigator::SendBeacon(const nsAString& aUrl,
channel->SetLoadGroup(loadGroup);

RefPtr<BeaconStreamListener> beaconListener = new BeaconStreamListener();

// Start a preflight if cross-origin and content type is not whitelisted
nsCOMPtr<nsIScriptSecurityManager> secMan = nsContentUtils::GetSecurityManager();
rv = secMan->CheckSameOriginURI(documentURI, uri, false);
bool crossOrigin = NS_FAILED(rv);
nsAutoCString contentType, parsedCharset;
rv = NS_ParseRequestContentType(mimeType, contentType, parsedCharset);
if (crossOrigin &&
mimeType.Length() > 0 &&
!contentType.Equals(APPLICATION_WWW_FORM_URLENCODED) &&
!contentType.Equals(MULTIPART_FORM_DATA) &&
!contentType.Equals(TEXT_PLAIN)) {

// we need to set the sameOriginChecker as a notificationCallback
// so we can tell the channel not to follow redirects
nsCOMPtr<nsIInterfaceRequestor> soc = nsContentUtils::SameOriginChecker();
channel->SetNotificationCallbacks(soc);

nsCOMPtr<nsIHttpChannelInternal> internalChannel =
do_QueryInterface(channel);
if (!internalChannel) {
aRv.Throw(NS_ERROR_FAILURE);
return false;
}
nsTArray<nsCString> unsafeHeaders;
unsafeHeaders.AppendElement(NS_LITERAL_CSTRING("Content-Type"));
rv = internalChannel->SetCorsPreflightParameters(unsafeHeaders,
true,
doc->NodePrincipal());
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(rv);
return false;
}
}

rv = channel->AsyncOpen2(beaconListener);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType,
? nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL
: nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS;
if (aRequest->mCORSMode == CORS_USE_CREDENTIALS) {
securityFlags |= nsILoadInfo::SEC_COOKIES_INCLUDE;
securityFlags |= nsILoadInfo::SEC_REQUIRE_CORS_WITH_CREDENTIALS;
}
securityFlags |= nsILoadInfo::SEC_ALLOW_CHROME;

Expand Down
Loading

0 comments on commit 879e1b2

Please sign in to comment.