Skip to content

Commit

Permalink
Bug 1767800 - Part 5: Factor out a method to check whether a URL to l…
Browse files Browse the repository at this point in the history
…oad is trusted r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D145473
  • Loading branch information
jonco3 committed May 6, 2022
1 parent f587179 commit 180a271
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions js/xpconnect/loader/mozJSComponentLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,11 @@ nsresult mozJSComponentLoader::ExtractExports(
return NS_OK;
}

/* static */
bool mozJSComponentLoader::IsTrustedScheme(nsIURI* aURI) {
return aURI->SchemeIs("resource") || aURI->SchemeIs("chrome");
}

nsresult mozJSComponentLoader::Import(JSContext* aCx,
const nsACString& aLocation,
JS::MutableHandleObject aModuleGlobal,
Expand Down Expand Up @@ -1281,8 +1286,7 @@ nsresult mozJSComponentLoader::Import(JSContext* aCx,
MOZ_TRY(info.EnsureResolvedURI());

// Reject imports from untrusted sources.
if ((!info.URI()->SchemeIs("resource")) &&
(!info.URI()->SchemeIs("chrome"))) {
if (!IsTrustedScheme(info.URI())) {
return NS_ERROR_DOM_SECURITY_ERR;
}

Expand Down
2 changes: 2 additions & 0 deletions js/xpconnect/loader/mozJSComponentLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class mozJSComponentLoader final : public nsIMemoryReporter {
nsresult IsModuleLoaded(const nsACString& aResourceURI, bool* aRetval);
bool IsLoaderGlobal(JSObject* aObj) { return mLoaderGlobal == aObj; }

static bool IsTrustedScheme(nsIURI* aURI);

size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);

protected:
Expand Down

0 comments on commit 180a271

Please sign in to comment.