Bug 1340710 - Part 3: Add an assertion to ensure that codebase principals are never constructed with URI schemes such as javascript:, about: and data:; r=bholley

This commit is contained in:
Ehsan Akhgari 2017-02-23 21:47:28 -05:00
Родитель 8f6e8510f6
Коммит f3dc163eaf
1 изменённых файлов: 13 добавлений и 0 удалений

Просмотреть файл

@ -100,6 +100,19 @@ nsPrincipal::Init(nsIURI *aCodebase, const OriginAttributes& aOriginAttributes)
mInitialized = true;
// Assert that the URI we get here isn't any of the schemes that we know we
// should not get here. These schemes always either inherit their principal
// or fall back to a null principal. These are schemes which return
// URI_INHERITS_SECURITY_CONTEXT from their protocol handler's
// GetProtocolFlags function.
bool hasFlag;
Unused << hasFlag; // silence possible compiler warnings.
MOZ_DIAGNOSTIC_ASSERT(
NS_SUCCEEDED(NS_URIChainHasFlags(aCodebase,
nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
&hasFlag)) &&
!hasFlag);
mCodebase = NS_TryToMakeImmutable(aCodebase);
mCodebaseImmutable = URIIsImmutable(mCodebase);
mOriginAttributes = aOriginAttributes;