From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/base/nsNoDataProtocolContentPolicy.cpp | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 dom/base/nsNoDataProtocolContentPolicy.cpp (limited to 'dom/base/nsNoDataProtocolContentPolicy.cpp') diff --git a/dom/base/nsNoDataProtocolContentPolicy.cpp b/dom/base/nsNoDataProtocolContentPolicy.cpp new file mode 100644 index 0000000000..1911c613cf --- /dev/null +++ b/dom/base/nsNoDataProtocolContentPolicy.cpp @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* + * Content policy implementation that prevents all loads of images, + * subframes, etc from protocols that don't return data but rather open + * applications (such as mailto). + */ + +#include "nsNoDataProtocolContentPolicy.h" +#include "nsString.h" +#include "nsIProtocolHandler.h" +#include "nsIURI.h" +#include "nsNetUtil.h" +#include "nsContentUtils.h" + +NS_IMPL_ISUPPORTS(nsNoDataProtocolContentPolicy, nsIContentPolicy) + +NS_IMETHODIMP +nsNoDataProtocolContentPolicy::ShouldLoad(nsIURI* aContentLocation, + nsILoadInfo* aLoadInfo, + const nsACString& aMimeGuess, + int16_t* aDecision) { + ExtContentPolicyType contentType = aLoadInfo->GetExternalContentPolicyType(); + + *aDecision = nsIContentPolicy::ACCEPT; + + // Don't block for TYPE_OBJECT since such URIs are sometimes loaded by the + // plugin, so they don't necessarily open external apps + // TYPE_WEBSOCKET loads can only go to ws:// or wss://, so we don't need to + // concern ourselves with them. + if (contentType != ExtContentPolicy::TYPE_DOCUMENT && + contentType != ExtContentPolicy::TYPE_SUBDOCUMENT && + contentType != ExtContentPolicy::TYPE_OBJECT && + contentType != ExtContentPolicy::TYPE_WEBSOCKET) { + // The following are just quick-escapes for the most common cases + // where we would allow the content to be loaded anyway. + nsAutoCString scheme; + aContentLocation->GetScheme(scheme); + if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("https") || + scheme.EqualsLiteral("ftp") || scheme.EqualsLiteral("file") || + scheme.EqualsLiteral("chrome")) { + return NS_OK; + } + + if (nsContentUtils::IsExternalProtocol(aContentLocation)) { + NS_SetRequestBlockingReason( + aLoadInfo, + nsILoadInfo::BLOCKING_REASON_CONTENT_POLICY_NO_DATA_PROTOCOL); + *aDecision = nsIContentPolicy::REJECT_REQUEST; + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsNoDataProtocolContentPolicy::ShouldProcess(nsIURI* aContentLocation, + nsILoadInfo* aLoadInfo, + const nsACString& aMimeGuess, + int16_t* aDecision) { + return ShouldLoad(aContentLocation, aLoadInfo, aMimeGuess, aDecision); +} -- cgit v1.2.3