Skip to content

Commit b94a5dd

Browse files
pfaffeDevtools-frontend LUCI CQ
authored andcommitted
Check hosts policy when loading extensions
Bug: 1451146 Change-Id: I59219bfa59c090264c7a074507520002b9d93384 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4667235 Auto-Submit: Philip Pfaffe <[email protected]> Commit-Queue: Danil Somsikov <[email protected]> Reviewed-by: Danil Somsikov <[email protected]>
1 parent ece1110 commit b94a5dd

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

front_end/models/extensions/ExtensionServer.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ export class HostsPolicy {
9292
}
9393
private constructor(readonly runtimeAllowedHosts: HostUrlPattern[], readonly runtimeBlockedHosts: HostUrlPattern[]) {
9494
}
95+
96+
isAllowedOnCurrentTarget(): boolean {
97+
const inspectedURL = SDK.TargetManager.TargetManager.instance().primaryPageTarget()?.inspectedURL();
98+
if (!inspectedURL) {
99+
// If there aren't any blocked hosts retain the old behavior and don't worry about the inspectedURL
100+
return this.runtimeBlockedHosts.length === 0;
101+
}
102+
if (this.runtimeBlockedHosts.some(pattern => pattern.matchesUrl(inspectedURL)) &&
103+
!this.runtimeAllowedHosts.some(pattern => pattern.matchesUrl(inspectedURL))) {
104+
return false;
105+
}
106+
return true;
107+
}
95108
}
96109

97110
export class ExtensionServer extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
@@ -1005,7 +1018,7 @@ export class ExtensionServer extends Common.ObjectWrapper.ObjectWrapper<EventTyp
10051018
return;
10061019
}
10071020
const hostsPolicy = HostsPolicy.create(extensionInfo.hostsPolicy);
1008-
if (!hostsPolicy) {
1021+
if (!hostsPolicy || !hostsPolicy.isAllowedOnCurrentTarget()) {
10091022
return;
10101023
}
10111024
try {
@@ -1060,18 +1073,7 @@ export class ExtensionServer extends Common.ObjectWrapper.ObjectWrapper<EventTyp
10601073
if (!extension) {
10611074
return false;
10621075
}
1063-
1064-
const inspectedURL = SDK.TargetManager.TargetManager.instance().primaryPageTarget()?.inspectedURL();
1065-
if (!inspectedURL) {
1066-
// If there aren't any blocked hosts retain the old behavior and don't worry about the inspectedURL
1067-
return extension.hostsPolicy.runtimeBlockedHosts.length === 0;
1068-
}
1069-
if (extension.hostsPolicy.runtimeBlockedHosts.some(pattern => pattern.matchesUrl(inspectedURL)) &&
1070-
!extension.hostsPolicy.runtimeAllowedHosts.some(pattern => pattern.matchesUrl(inspectedURL))) {
1071-
return false;
1072-
}
1073-
1074-
return true;
1076+
return extension.hostsPolicy.isAllowedOnCurrentTarget();
10751077
}
10761078

10771079
private async onmessage(event: MessageEvent): Promise<void> {

0 commit comments

Comments
 (0)