Bug 1328695 - Use protocol flags to determine if a URI is potentially trustworthy r=ckerschb, r=dveditz, r=mcmanus, r=bz

Before this change, the trusted URI schemes, based on a string whitelist, were:
https, file, resource, app, moz-extension and wss.

This change removes "app" from the list (since we don't implement it),
and adds "about" to the list (because we control the delivery of that).
This commit is contained in:
Kate McKinley 2018-05-31 07:51:42 +02:00
Родитель 6302682c36
Коммит fa06a45b28
10 изменённых файлов: 34 добавлений и 18 удалений

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

@ -162,7 +162,7 @@ SendPing(void* aClosure, nsIContent* aContent, nsIURI* aURI,
if (sm && info->referrer) {
bool referrerIsSecure;
uint32_t flags = nsIProtocolHandler::URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT;
uint32_t flags = nsIProtocolHandler::URI_IS_POTENTIALLY_TRUSTWORTHY;
rv = NS_URIChainHasFlags(info->referrer, flags, &referrerIsSecure);
// Default to sending less data if NS_URIChainHasFlags() fails.

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

@ -890,12 +890,16 @@ nsContentSecurityManager::IsOriginPotentiallyTrustworthy(nsIPrincipal* aPrincipa
// which is technically a substituting protocol handler that is not limited to
// local resource mapping, but in practice is never mapped remotely as this
// would violate assumptions a lot of code makes.
if (scheme.EqualsLiteral("https") ||
scheme.EqualsLiteral("file") ||
scheme.EqualsLiteral("resource") ||
scheme.EqualsLiteral("app") ||
scheme.EqualsLiteral("moz-extension") ||
scheme.EqualsLiteral("wss")) {
// We use nsIProtocolHandler flags to determine which protocols we consider a priori
// authenticated.
bool aPrioriAuthenticated = false;
if (NS_FAILED(NS_URIChainHasFlags(uri,
nsIProtocolHandler::URI_IS_POTENTIALLY_TRUSTWORTHY,
&aPrioriAuthenticated))) {
return NS_ERROR_UNEXPECTED;
}
if (aPrioriAuthenticated) {
*aIsTrustWorthy = true;
return NS_OK;
}

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

@ -597,7 +597,7 @@ nsMixedContentBlocker::ShouldLoad(bool aHadInsecureImageRedirect,
* "moz-icon"
* URI_INHERITS_SECURITY_CONTEXT - e.g.
* "javascript"
* URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT - e.g.
* URI_IS_POTENTIALLY_TRUSTWORTHY - e.g.
* "https",
* "moz-safe-about"
*
@ -609,7 +609,7 @@ nsMixedContentBlocker::ShouldLoad(bool aHadInsecureImageRedirect,
if (NS_FAILED(NS_URIChainHasFlags(innerContentLocation, nsIProtocolHandler::URI_IS_LOCAL_RESOURCE , &schemeLocal)) ||
NS_FAILED(NS_URIChainHasFlags(innerContentLocation, nsIProtocolHandler::URI_DOES_NOT_RETURN_DATA, &schemeNoReturnData)) ||
NS_FAILED(NS_URIChainHasFlags(innerContentLocation, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT, &schemeInherits)) ||
NS_FAILED(NS_URIChainHasFlags(innerContentLocation, nsIProtocolHandler::URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT, &schemeSecure))) {
NS_FAILED(NS_URIChainHasFlags(innerContentLocation, nsIProtocolHandler::URI_IS_POTENTIALLY_TRUSTWORTHY, &schemeSecure))) {
*aDecision = REJECT_REQUEST;
return NS_ERROR_FAILURE;
}

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

@ -302,10 +302,13 @@ interface nsIProtocolHandler : nsISupports
const unsigned long URI_SYNC_LOAD_IS_OK = (1<<17);
/**
* URI is secure to load in an https page and should not be blocked
* by nsMixedContentBlocker
* All the origins whose URI has this scheme are considered potentially
* trustworthy.
* Per the SecureContext spec, https: and wss: should be considered
* a priori secure, and implementations may consider other,
* implementation-specific URI schemes as secure.
*/
const unsigned long URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT = (1<<18);
const unsigned long URI_IS_POTENTIALLY_TRUSTWORTHY = (1<<18);
/**
* This URI may be fetched and the contents are visible to anyone. This is

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

@ -93,7 +93,7 @@ nsAboutProtocolHandler::GetFlagsForURI(nsIURI* aURI, uint32_t* aFlags)
// Secure (https) pages can load safe about pages without becoming
// mixed content.
if (aboutModuleFlags & nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT) {
*aFlags |= URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT;
*aFlags |= URI_IS_POTENTIALLY_TRUSTWORTHY;
// about: pages can only be loaded by unprivileged principals
// if they are marked as LINKABLE
if (aboutModuleFlags & nsIAboutModule::MAKE_LINKABLE) {
@ -305,7 +305,7 @@ nsSafeAboutProtocolHandler::GetDefaultPort(int32_t *result)
NS_IMETHODIMP
nsSafeAboutProtocolHandler::GetProtocolFlags(uint32_t *result)
{
*result = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_ANYONE | URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT;
*result = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_ANYONE | URI_IS_POTENTIALLY_TRUSTWORTHY;
return NS_OK;
}

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

@ -153,7 +153,8 @@ nsFileProtocolHandler::GetDefaultPort(int32_t *result)
NS_IMETHODIMP
nsFileProtocolHandler::GetProtocolFlags(uint32_t *result)
{
*result = URI_NOAUTH | URI_IS_LOCAL_FILE | URI_IS_LOCAL_RESOURCE;
*result = URI_NOAUTH | URI_IS_LOCAL_FILE |
URI_IS_LOCAL_RESOURCE | URI_IS_POTENTIALLY_TRUSTWORTHY;
return NS_OK;
}

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

@ -2713,7 +2713,7 @@ nsHttpsHandler::GetDefaultPort(int32_t *aPort)
NS_IMETHODIMP
nsHttpsHandler::GetProtocolFlags(uint32_t *aProtocolFlags)
{
*aProtocolFlags = NS_HTTP_PROTOCOL_FLAGS | URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT;
*aProtocolFlags = NS_HTTP_PROTOCOL_FLAGS | URI_IS_POTENTIALLY_TRUSTWORTHY;
return NS_OK;
}

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

@ -375,7 +375,9 @@ ExtensionProtocolHandler::GetFlagsForURI(nsIURI* aURI, uint32_t* aFlags)
loadableByAnyone = policy->IsPathWebAccessible(url.FilePath());
}
*aFlags = URI_STD | URI_IS_LOCAL_RESOURCE | (loadableByAnyone ? (URI_LOADABLE_BY_ANYONE | URI_FETCHABLE_BY_ANYONE) : URI_DANGEROUS_TO_LOAD);
*aFlags = URI_STD | URI_IS_LOCAL_RESOURCE | URI_IS_POTENTIALLY_TRUSTWORTHY |
(loadableByAnyone ? (URI_LOADABLE_BY_ANYONE |
URI_FETCHABLE_BY_ANYONE) : URI_DANGEROUS_TO_LOAD);
return NS_OK;
}

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

@ -27,7 +27,10 @@ public:
NS_FORWARD_NSIPROTOCOLHANDLER(mozilla::net::SubstitutingProtocolHandler::)
nsResProtocolHandler()
: mozilla::net::SubstitutingProtocolHandler("resource", URI_STD | URI_IS_UI_RESOURCE | URI_IS_LOCAL_RESOURCE,
: mozilla::net::SubstitutingProtocolHandler("resource", URI_STD |
URI_IS_UI_RESOURCE |
URI_IS_LOCAL_RESOURCE |
URI_IS_POTENTIALLY_TRUSTWORTHY,
/* aEnforceFileOrJar = */ false)
{}

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

@ -290,6 +290,9 @@ BaseWebSocketChannel::GetProtocolFlags(uint32_t *aProtocolFlags)
*aProtocolFlags = URI_NORELATIVE | URI_NON_PERSISTABLE | ALLOWS_PROXY |
ALLOWS_PROXY_HTTP | URI_DOES_NOT_RETURN_DATA | URI_DANGEROUS_TO_LOAD;
if (mEncrypted) {
*aProtocolFlags |= URI_IS_POTENTIALLY_TRUSTWORTHY;
}
return NS_OK;
}