Skip to content

Commit

Permalink
Bug 1735746 - Log an error message to the web console for blocked ext…
Browse files Browse the repository at this point in the history
…ernal protocol navigation from sandbox. r=ckerschb

Depends on D141132

Differential Revision: https://phabricator.services.mozilla.com/D141133
  • Loading branch information
Trikolon committed Apr 5, 2022
1 parent dd7683c commit 216bf2a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dom/locales/en-US/chrome/security/security.properties
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ HTTPSOnlyUpgradeSpeculativeConnection = Upgrading insecure speculative TCP conne
# LOCALIZATION NOTE: %S is the URL of the blocked request;
IframeSandboxBlockedDownload = Download of “%S” was blocked because the triggering iframe has the sandbox flag set.

# LOCALIZATION NOTE: %S is the URL of the blocked request;
SandboxBlockedCustomProtocols = Blocked navigation to custom protocol “%S” from a sandboxed context.

# Sanitizer API
# LOCALIZATION NOTE: Please do not localize "DocumentFragment". It's the name of an API.
SanitizerRcvdNoInput = Received empty or no input. Returning an empty DocumentFragment.
Expand Down
19 changes: 19 additions & 0 deletions uriloader/exthandler/nsExternalHelperAppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,25 @@ nsExternalHelperAppService::LoadURI(nsIURI* aURI,
if (aBrowsingContext &&
ExternalProtocolIsBlockedBySandbox(aBrowsingContext,
aHasValidUserGestureActivation)) {
// Log an error to the web console of the sandboxed BrowsingContext.
nsAutoString localizedMsg;
nsAutoCString spec;
aURI->GetSpec(spec);

AutoTArray<nsString, 1> params = {NS_ConvertUTF8toUTF16(spec)};
nsresult rv = nsContentUtils::FormatLocalizedString(
nsContentUtils::eSECURITY_PROPERTIES, "SandboxBlockedCustomProtocols",
params, localizedMsg);
NS_ENSURE_SUCCESS(rv, rv);

WindowContext* windowContext = aBrowsingContext->GetCurrentWindowContext();
NS_ENSURE_TRUE(windowContext, NS_ERROR_FAILURE);

nsContentUtils::ReportToConsoleByWindowID(
localizedMsg, nsIScriptError::errorFlag, "Security"_ns,
windowContext->InnerWindowId(),
windowContext->Canonical()->GetDocumentURI());

return NS_OK;
}

Expand Down

0 comments on commit 216bf2a

Please sign in to comment.