Skip to content

Commit 88d34a3

Browse files
author
Alexandru Michis
committed
Backed out changeset 19de2822bc0c (bug 1711168) for causing Bug 1719063.
CLOSED TREE
1 parent 3cad835 commit 88d34a3

11 files changed

+53
-316
lines changed

caps/BasePrincipal.cpp

+12-24
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "nsAboutProtocolUtils.h"
1919
#include "ThirdPartyUtil.h"
2020
#include "mozilla/ContentPrincipal.h"
21-
#include "mozilla/ExtensionPolicyService.h"
2221
#include "mozilla/NullPrincipal.h"
2322
#include "mozilla/dom/BlobURLProtocolHandler.h"
2423
#include "mozilla/dom/ChromeUtils.h"
@@ -571,32 +570,21 @@ nsresult BasePrincipal::CheckMayLoadHelper(nsIURI* aURI,
571570
}
572571
}
573572

574-
// Get the principal uri for the last flag check or error.
575-
nsCOMPtr<nsIURI> prinURI;
576-
rv = GetURI(getter_AddRefs(prinURI));
577-
if (!(NS_SUCCEEDED(rv) && prinURI)) {
578-
return NS_ERROR_DOM_BAD_URI;
579-
}
580-
581-
// If Extension uris are web accessible by this principal it is allowed to
582-
// load.
583-
bool maybeWebAccessible = false;
584-
NS_URIChainHasFlags(aURI, nsIProtocolHandler::WEBEXT_URI_WEB_ACCESSIBLE,
585-
&maybeWebAccessible);
586-
NS_ENSURE_SUCCESS(rv, rv);
587-
if (maybeWebAccessible) {
588-
bool isWebAccessible = false;
589-
rv = ExtensionPolicyService::GetSingleton().SourceMayLoadExtensionURI(
590-
prinURI, aURI, &isWebAccessible);
591-
if (NS_SUCCEEDED(rv) && isWebAccessible) {
592-
return NS_OK;
593-
}
573+
bool fetchableByAnyone;
574+
rv = NS_URIChainHasFlags(aURI, nsIProtocolHandler::URI_FETCHABLE_BY_ANYONE,
575+
&fetchableByAnyone);
576+
if (NS_SUCCEEDED(rv) && fetchableByAnyone) {
577+
return NS_OK;
594578
}
595579

596580
if (aReport) {
597-
nsScriptSecurityManager::ReportError(
598-
"CheckSameOriginError", prinURI, aURI,
599-
mOriginAttributes.mPrivateBrowsingId > 0, aInnerWindowID);
581+
nsCOMPtr<nsIURI> prinURI;
582+
rv = GetURI(getter_AddRefs(prinURI));
583+
if (NS_SUCCEEDED(rv) && prinURI) {
584+
nsScriptSecurityManager::ReportError(
585+
"CheckSameOriginError", prinURI, aURI,
586+
mOriginAttributes.mPrivateBrowsingId > 0, aInnerWindowID);
587+
}
600588
}
601589

602590
return NS_ERROR_DOM_BAD_URI;

caps/nsScriptSecurityManager.cpp

+18-32
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,21 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
670670
return NS_ERROR_DOM_BAD_URI;
671671
}
672672

673+
// Extensions may allow access to a web accessible resource.
674+
bool maybeWebAccessible = false;
675+
NS_URIChainHasFlags(targetBaseURI,
676+
nsIProtocolHandler::WEBEXT_URI_WEB_ACCESSIBLE,
677+
&maybeWebAccessible);
678+
NS_ENSURE_SUCCESS(rv, rv);
679+
if (maybeWebAccessible) {
680+
bool isWebAccessible = false;
681+
rv = ExtensionPolicyService::GetSingleton().SourceMayLoadExtensionURI(
682+
sourceURI, targetBaseURI, &isWebAccessible);
683+
if (!(NS_SUCCEEDED(rv) && isWebAccessible)) {
684+
return NS_ERROR_DOM_BAD_URI;
685+
}
686+
}
687+
673688
// Check for uris that are only loadable by principals that subsume them
674689
bool targetURIIsLoadableBySubsumers = false;
675690
rv = NS_URIChainHasFlags(targetBaseURI,
@@ -743,7 +758,6 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
743758
bool schemesMatch =
744759
scheme.Equals(otherScheme, nsCaseInsensitiveCStringComparator);
745760
bool isSamePage = false;
746-
bool isExtensionMismatch = false;
747761
// about: URIs are special snowflakes.
748762
if (scheme.EqualsLiteral("about") && schemesMatch) {
749763
nsAutoCString moduleName, otherModuleName;
@@ -791,13 +805,6 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
791805
}
792806
}
793807
}
794-
} else if (schemesMatch && scheme.EqualsLiteral("moz-extension")) {
795-
// If it is not the same exension, we want to ensure we end up
796-
// calling CheckLoadURIFlags
797-
nsAutoCString host, otherHost;
798-
currentURI->GetHost(host);
799-
currentOtherURI->GetHost(otherHost);
800-
isExtensionMismatch = !host.Equals(otherHost);
801808
} else {
802809
bool equalExceptRef = false;
803810
rv = currentURI->EqualsExceptRef(currentOtherURI, &equalExceptRef);
@@ -806,12 +813,10 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
806813

807814
// If schemes are not equal, or they're equal but the target URI
808815
// is different from the source URI and doesn't always allow linking
809-
// from the same scheme, or this is two different extensions, check
810-
// if the URI flags of the current target URI allow the current
811-
// source URI to link to it.
816+
// from the same scheme, check if the URI flags of the current target
817+
// URI allow the current source URI to link to it.
812818
// The policy is specified by the protocol flags on both URIs.
813-
if (!schemesMatch || (denySameSchemeLinks && !isSamePage) ||
814-
isExtensionMismatch) {
819+
if (!schemesMatch || (denySameSchemeLinks && !isSamePage)) {
815820
return CheckLoadURIFlags(
816821
currentURI, currentOtherURI, sourceBaseURI, targetBaseURI, aFlags,
817822
aPrincipal->OriginAttributesRef().mPrivateBrowsingId > 0,
@@ -886,25 +891,6 @@ nsresult nsScriptSecurityManager::CheckLoadURIFlags(
886891
}
887892
}
888893

889-
// If Extension uris are web accessible they have WEBEXT_URI_WEB_ACCESSIBLE.
890-
bool maybeWebAccessible = false;
891-
NS_URIChainHasFlags(aTargetURI, nsIProtocolHandler::WEBEXT_URI_WEB_ACCESSIBLE,
892-
&maybeWebAccessible);
893-
NS_ENSURE_SUCCESS(rv, rv);
894-
if (maybeWebAccessible) {
895-
bool isWebAccessible = false;
896-
rv = ExtensionPolicyService::GetSingleton().SourceMayLoadExtensionURI(
897-
aSourceURI, aTargetURI, &isWebAccessible);
898-
if (NS_SUCCEEDED(rv) && isWebAccessible) {
899-
return NS_OK;
900-
}
901-
if (reportErrors) {
902-
ReportError(errorTag, aSourceURI, aTargetURI, aFromPrivateWindow,
903-
aInnerWindowID);
904-
}
905-
return NS_ERROR_DOM_BAD_URI;
906-
}
907-
908894
// Check for chrome target URI
909895
bool targetURIIsUIResource = false;
910896
rv = NS_URIChainHasFlags(aTargetURI, nsIProtocolHandler::URI_IS_UI_RESOURCE,

dom/chrome-webidl/WebExtensionPolicy.webidl

+1-2
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ interface WebExtensionPolicy {
268268

269269
dictionary WebAccessibleResourceInit {
270270
required sequence<MatchGlobOrString> resources;
271-
MatchPatternSetOrStringSequence? matches = null;
272-
sequence<DOMString>? extensions = null;
271+
MatchPatternSetOrStringSequence matches;
273272
};
274273

275274
dictionary WebExtensionInit {

dom/security/nsContentSecurityManager.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ nsresult nsContentSecurityManager::CheckAllowLoadInSystemPrivilegedContext(
10801080
}
10811081

10821082
/*
1083-
* Every protocol handler must set one of the six security flags
1083+
* Every protocol handler must set one of the five security flags
10841084
* defined in nsIProtocolHandler - if not - deny the load.
10851085
*/
10861086
nsresult nsContentSecurityManager::CheckChannelHasProtocolSecurityFlag(
@@ -1105,9 +1105,6 @@ nsresult nsContentSecurityManager::CheckChannelHasProtocolSecurityFlag(
11051105
NS_ENSURE_SUCCESS(rv, rv);
11061106

11071107
uint32_t securityFlagsSet = 0;
1108-
if (flags & nsIProtocolHandler::WEBEXT_URI_WEB_ACCESSIBLE) {
1109-
securityFlagsSet += 1;
1110-
}
11111108
if (flags & nsIProtocolHandler::URI_LOADABLE_BY_ANYONE) {
11121109
securityFlagsSet += 1;
11131110
}

netwerk/base/nsIProtocolHandler.idl

+8-1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,13 @@ interface nsIProtocolHandler : nsISupports
272272
*/
273273
const unsigned long URI_IS_POTENTIALLY_TRUSTWORTHY = (1<<17);
274274

275+
/**
276+
* This URI may be fetched and the contents are visible to anyone. This is
277+
* semantically equivalent to the resource being served with all-access CORS
278+
* headers.
279+
*/
280+
const unsigned long URI_FETCHABLE_BY_ANYONE = (1 << 18);
281+
275282
/**
276283
* If this flag is set, then the origin for this protocol is the full URI
277284
* spec, not just the scheme + host + port.
@@ -305,7 +312,7 @@ interface nsIProtocolHandler : nsISupports
305312

306313
/**
307314
* This is an extension web accessible uri that is loadable if checked
308-
* against an allow whitelist using ExtensionPolicyService::SourceMayLoadExtensionURI.
315+
* against an allow whitelist.
309316
*/
310317
const unsigned long WEBEXT_URI_WEB_ACCESSIBLE = (1 << 24);
311318
};

netwerk/protocol/res/ExtensionProtocolHandler.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,15 @@ nsresult ExtensionProtocolHandler::GetFlagsForURI(nsIURI* aURI,
368368

369369
URLInfo url(aURI);
370370
if (auto* policy = EPS().GetByURL(url)) {
371-
// In general a moz-extension URI is only loadable by chrome, but an
372-
// allowlist subset are web-accessible (and cross-origin fetchable).
373-
// The allowlist is checked using EPS.SourceMayLoadExtensionURI in
374-
// BasePrincipal and nsScriptSecurityManager.
371+
// In general a moz-extension URI is only loadable by chrome, but a
372+
// whitelisted subset are web-accessible (and cross-origin fetchable). Check
373+
// that whitelist. For Manifest V3 extensions, an additional whitelist
374+
// for the source loading the url must be checked so we add the flag
375+
// WEBEXT_URI_WEB_ACCESSIBLE, which is then checked in
376+
// nsScriptSecurityManager.
375377
if (policy->IsWebAccessiblePath(url.FilePath())) {
376-
flags |= WEBEXT_URI_WEB_ACCESSIBLE;
378+
flags |= URI_LOADABLE_BY_ANYONE | URI_FETCHABLE_BY_ANYONE |
379+
WEBEXT_URI_WEB_ACCESSIBLE;
377380
} else {
378381
flags |= URI_DANGEROUS_TO_LOAD;
379382
}

toolkit/components/extensions/Schemas.jsm

-12
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,6 @@ const POSTPROCESSORS = {
306306
context.logError(context.makeError(msg));
307307
throw new Error(msg);
308308
},
309-
310-
webAcessibleMatching(value, context) {
311-
// Ensure each object has at least one of matches or extensions array.
312-
for (let obj of value) {
313-
if (!obj.matches && !obj.extensions) {
314-
const msg = `web_accessible_resources requires one of "matches" or "extensions"`;
315-
context.logError(context.makeError(msg));
316-
throw new Error(msg);
317-
}
318-
}
319-
return value;
320-
},
321309
};
322310

323311
// Parses a regular expression, with support for the Python extended

toolkit/components/extensions/WebExtensionPolicy.cpp

+1-13
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,12 @@ WebAccessibleResource::WebAccessibleResource(
143143
return;
144144
}
145145

146-
if (!aInit.mMatches.IsNull()) {
146+
if (aInit.mMatches.WasPassed()) {
147147
MatchPatternOptions options;
148148
options.mRestrictSchemes = true;
149149
mMatches = ParseMatches(aGlobal, aInit.mMatches.Value(), options,
150150
ErrorBehavior::CreateEmptyPattern, aRv);
151151
}
152-
153-
if (!aInit.mExtensions.IsNull()) {
154-
mExtensions = new AtomSet(aInit.mExtensions.Value());
155-
}
156-
}
157-
158-
bool WebAccessibleResource::IsExtensionMatch(const URLInfo& aURI) {
159-
if (!mExtensions) {
160-
return false;
161-
}
162-
WebExtensionPolicy* policy = EPS().GetByHost(aURI.Host());
163-
return policy && mExtensions->Contains(policy->Id());
164152
}
165153

166154
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebAccessibleResource)

toolkit/components/extensions/WebExtensionPolicy.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,16 @@ class WebAccessibleResource final : public nsISupports {
5050
}
5151

5252
bool SourceMayAccessPath(const URLInfo& aURI, const nsAString& aPath) {
53-
return mWebAccessiblePaths.Matches(aPath) &&
54-
(IsHostMatch(aURI) || IsExtensionMatch(aURI));
53+
return mWebAccessiblePaths.Matches(aPath) && mMatches &&
54+
mMatches->Matches(aURI);
5555
}
5656

57-
bool IsHostMatch(const URLInfo& aURI) {
58-
return mMatches && mMatches->Matches(aURI);
59-
}
60-
61-
bool IsExtensionMatch(const URLInfo& aURI);
62-
6357
protected:
6458
virtual ~WebAccessibleResource() = default;
6559

6660
private:
6761
MatchGlobSet mWebAccessiblePaths;
6862
RefPtr<MatchPatternSet> mMatches;
69-
RefPtr<AtomSet> mExtensions;
7063
};
7164

7265
class WebExtensionPolicy final : public nsISupports,

toolkit/components/extensions/schemas/manifest.json

-7
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@
243243
{
244244
"min_manifest_version": 3,
245245
"type": "array",
246-
"postprocess": "webAcessibleMatching",
247246
"items": {
248247
"type": "object",
249248
"properties": {
@@ -252,14 +251,8 @@
252251
"items": { "type": "string" }
253252
},
254253
"matches": {
255-
"optional": true,
256254
"type": "array",
257255
"items": { "$ref": "MatchPatternRestricted" }
258-
},
259-
"extensions": {
260-
"optional": true,
261-
"type": "array",
262-
"items": { "$ref": "ExtensionID" }
263256
}
264257
}
265258
}

0 commit comments

Comments
 (0)