Skip to content

Commit b50c1db

Browse files
danilsomsikovDevtools-frontend LUCI CQ
authored andcommitted
Protect canAccessResource in DevTools API form prototype pollution
Bug: 376625003 Change-Id: Ib07a65da8f342c4727bceb6afcbd920bcfd07b81 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5987430 Reviewed-by: Philip Pfaffe <[email protected]> Commit-Queue: Danil Somsikov <[email protected]>
1 parent 6613a76 commit b50c1db

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

front_end/models/extensions/ExtensionAPI.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,17 @@ self.injectedExtensionAPI = function(
11461146
},
11471147
};
11481148

1149+
const protocolGet = Object.getOwnPropertyDescriptor(URL.prototype, 'protocol')?.get;
1150+
function getProtocol(url: string): string {
1151+
if (!protocolGet) {
1152+
throw new Error('URL.protocol is not available');
1153+
}
1154+
return protocolGet.call(new URL(url));
1155+
}
1156+
11491157
function canAccessResource(resource: APIImpl.ResourceData): boolean {
11501158
try {
1151-
return extensionInfo.allowFileAccess || (new URL(resource.url)).protocol !== 'file:';
1159+
return extensionInfo.allowFileAccess || getProtocol(resource.url) !== 'file:';
11521160
} catch (e) {
11531161
return false;
11541162
}

0 commit comments

Comments
 (0)