Skip to content

Commit 8c801f5

Browse files
committed
Bug 1909298 - Confirm permission in webRequest r=rpl
Differential Revision: https://phabricator.services.mozilla.com/D217449
1 parent 0dfb26d commit 8c801f5

File tree

5 files changed

+26
-19
lines changed

5 files changed

+26
-19
lines changed

toolkit/components/extensions/webrequest/ChannelWrapper.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ already_AddRefed<ChannelWrapper> ChannelWrapper::GetRegisteredChannel(
180180
auto& webreq = WebRequestService::GetSingleton();
181181

182182
nsCOMPtr<nsITraceableChannel> channel =
183-
webreq.GetTraceableChannel(aChannelId, aAddon.Id(), contentParent);
183+
webreq.GetTraceableChannel(aChannelId, aAddon, contentParent);
184184
if (!channel) {
185185
return nullptr;
186186
}
@@ -814,9 +814,14 @@ void ChannelWrapper::RegisterTraceableChannel(const WebExtensionPolicy& aAddon,
814814
}
815815

816816
already_AddRefed<nsITraceableChannel> ChannelWrapper::GetTraceableChannel(
817-
nsAtom* aAddonId, dom::ContentParent* aContentParent) const {
817+
const WebExtensionPolicy& aAddon,
818+
dom::ContentParent* aContentParent) const {
818819
nsCOMPtr<nsIRemoteTab> remoteTab;
819-
if (mAddonEntries.Get(aAddonId, getter_AddRefs(remoteTab))) {
820+
if (mAddonEntries.Get(aAddon.Id(), getter_AddRefs(remoteTab))) {
821+
if (!aAddon.CanAccessURI(FinalURLInfo(), false, true, true)) {
822+
return nullptr;
823+
}
824+
820825
ContentParent* contentParent = nullptr;
821826
if (remoteTab) {
822827
contentParent =

toolkit/components/extensions/webrequest/ChannelWrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ class ChannelWrapper final : public DOMEventTargetHelper,
150150
nsIRemoteTab* aBrowserParent);
151151

152152
already_AddRefed<nsITraceableChannel> GetTraceableChannel(
153-
nsAtom* aAddonId, dom::ContentParent* aContentParent) const;
153+
const WebExtensionPolicy& aAddon,
154+
dom::ContentParent* aContentParent) const;
154155

155156
void GetMethod(nsCString& aRetVal) const;
156157

toolkit/components/extensions/webrequest/StreamFilterParent.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,15 @@ auto StreamFilterParent::Create(dom::ContentParent* aContentParent,
120120

121121
auto& webreq = WebRequestService::GetSingleton();
122122

123-
RefPtr<nsAtom> addonId = NS_Atomize(aAddonId);
123+
RefPtr<extensions::WebExtensionPolicy> addonPolicy =
124+
ExtensionPolicyService::GetSingleton().GetByID(aAddonId);
125+
126+
if (!addonPolicy) {
127+
return ChildEndpointPromise::CreateAndReject(false, __func__);
128+
}
129+
124130
nsCOMPtr<nsITraceableChannel> channel =
125-
webreq.GetTraceableChannel(aChannelId, addonId, aContentParent);
131+
webreq.GetTraceableChannel(aChannelId, *addonPolicy, aContentParent);
126132

127133
RefPtr<mozilla::net::nsHttpChannel> chan = do_QueryObject(channel);
128134
if (!chan) {
@@ -131,15 +137,10 @@ auto StreamFilterParent::Create(dom::ContentParent* aContentParent,
131137

132138
nsCOMPtr<nsIChannel> genChan(do_QueryInterface(channel));
133139
if (!StaticPrefs::extensions_filterResponseServiceWorkerScript_disabled() &&
134-
ChannelWrapper::IsServiceWorkerScript(genChan)) {
135-
RefPtr<extensions::WebExtensionPolicy> addonPolicy =
136-
ExtensionPolicyService::GetSingleton().GetByID(aAddonId);
137-
138-
if (!addonPolicy ||
139-
!addonPolicy->HasPermission(
140-
nsGkAtoms::webRequestFilterResponse_serviceWorkerScript)) {
141-
return ChildEndpointPromise::CreateAndReject(false, __func__);
142-
}
140+
ChannelWrapper::IsServiceWorkerScript(genChan) &&
141+
!addonPolicy->HasPermission(
142+
nsGkAtoms::webRequestFilterResponse_serviceWorkerScript)) {
143+
return ChildEndpointPromise::CreateAndReject(false, __func__);
143144
}
144145

145146
// Disable alt-data for extension stream listeners.

toolkit/components/extensions/webrequest/WebRequestService.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ UniquePtr<WebRequestChannelEntry> WebRequestService::RegisterChannel(
3636
}
3737

3838
already_AddRefed<nsITraceableChannel> WebRequestService::GetTraceableChannel(
39-
uint64_t aChannelId, nsAtom* aAddonId, ContentParent* aContentParent) {
39+
uint64_t aChannelId, const WebExtensionPolicy& aAddon,
40+
ContentParent* aContentParent) {
4041
if (auto entry = mChannelEntries.Get(aChannelId)) {
4142
if (entry->mChannel) {
42-
return entry->mChannel->GetTraceableChannel(aAddonId, aContentParent);
43+
return entry->mChannel->GetTraceableChannel(aAddon, aContentParent);
4344
}
4445
}
4546
return nullptr;

toolkit/components/extensions/webrequest/WebRequestService.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "nsHashKeys.h"
1717
#include "nsTHashMap.h"
1818

19-
class nsAtom;
2019
class nsIRemoteTab;
2120
class nsITraceableChannel;
2221

@@ -62,7 +61,7 @@ class WebRequestService final {
6261
void UnregisterTraceableChannel(uint64_t aChannelId);
6362

6463
already_AddRefed<nsITraceableChannel> GetTraceableChannel(
65-
uint64_t aChannelId, nsAtom* aAddonId,
64+
uint64_t aChannelId, const WebExtensionPolicy& aAddon,
6665
dom::ContentParent* aContentParent);
6766

6867
private:

0 commit comments

Comments
 (0)