Skip to content

Commit

Permalink
Bug 1696229 - Don't report wrong errors for expanded principals in Ch…
Browse files Browse the repository at this point in the history
…eckLoadURIWithPrincipal. r=ckerschb

Differential Revision: https://phabricator.services.mozilla.com/D107101
  • Loading branch information
evilpie committed Mar 8, 2021
1 parent 08ebc51 commit 801c557
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions caps/nsScriptSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,16 +622,21 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
if (!sourceURI) {
if (basePrin->Is<ExpandedPrincipal>()) {
auto expanded = basePrin->As<ExpandedPrincipal>();
for (auto& prin : expanded->AllowList()) {
nsresult rv =
CheckLoadURIWithPrincipal(prin, aTargetURI, aFlags, aInnerWindowID);
const auto& allowList = expanded->AllowList();
// Only report errors when all principals fail.
uint32_t flags = aFlags | nsIScriptSecurityManager::DONT_REPORT_ERRORS;
for (size_t i = 0; i < allowList.Length() - 1; i++) {
nsresult rv = CheckLoadURIWithPrincipal(allowList[i], aTargetURI, flags,
aInnerWindowID);
if (NS_SUCCEEDED(rv)) {
// Allow access if it succeeded with one of the allowlisted principals
return NS_OK;
}
}
// None of our allowlisted principals worked.
return NS_ERROR_DOM_BAD_URI;

// Report errors (if requested) for the last principal.
return CheckLoadURIWithPrincipal(allowList.LastElement(), aTargetURI,
aFlags, aInnerWindowID);
}
NS_ERROR(
"Non-system principals or expanded principal passed to "
Expand Down

0 comments on commit 801c557

Please sign in to comment.