Skip to content

Commit a01c5ef

Browse files
committed
Short-circuit on internal URIs.
1 parent 886995e commit a01c5ef

1 file changed

Lines changed: 21 additions & 20 deletions

File tree

src/bg/RequestGuard.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* NoScript - a Firefox extension for whitelist driven safe JavaScript execution
33
*
4-
* Copyright (C) 2005-2024 Giorgio Maone <https://maone.net>
4+
* Copyright (C) 2005-2026 Giorgio Maone <https://maone.net>
55
*
66
* SPDX-License-Identifier: GPL-3.0-or-later
77
*
@@ -784,43 +784,44 @@
784784
}
785785
return ALLOW;
786786
}
787-
let isFetch = "fetch" === policyType;
788787

788+
const isFetch = "fetch" === policyType;
789789
if ((isFetch || "frame" === policyType) &&
790790
(((isFetch && !originUrl
791791
|| url === originUrl) && originUrl === documentUrl
792792
// some extensions make them both undefined,
793793
// see https://github.com/eight04/image-picka/issues/150
794794
) ||
795-
Sites.isInternal(originUrl))
795+
Sites.isInternal(originUrl)) ||
796+
Sites.isInternal(url)
796797
) {
797798
// livemark request or similar browser-internal, always allow;
798799
return ALLOW;
799800
}
800801

802+
let allowed = false;
803+
801804
if (/^(?:data|blob):/.test(url)) {
802805
request._dataUrl = url;
803806
request.url = url = documentUrl || originUrl;
807+
allowed = Sites.isInternal(url);
804808
}
805809

806-
let allowed = Sites.isInternal(url);
810+
if (tabId < 0 && documentUrl?.startsWith("https:")) {
811+
allowed = [...ns.unrestrictedTabs]
812+
.some(tabId => TabStatus.hasOrigin(tabId, documentUrl));
813+
}
807814
if (!allowed) {
808-
if (tabId < 0 && documentUrl?.startsWith("https:")) {
809-
allowed = [...ns.unrestrictedTabs]
810-
.some(tabId => TabStatus.hasOrigin(tabId, documentUrl));
811-
}
812-
if (!allowed) {
813-
const capabilities = intersectCapabilities(
814-
policy.get(url, ns.policyContext(request)),
815-
request);
816-
allowed = !policyType || capabilities.has(policyType);
817-
if (allowed && request._dataUrl && type.endsWith("frame")) {
818-
let blocker = csp.buildFromCapabilities(capabilities);
819-
if (blocker) {
820-
let redirectUrl = CSP.patchDataURI(request._dataUrl, blocker);
821-
if (redirectUrl !== request._dataUrl) {
822-
return previous.return = {redirectUrl};
823-
}
815+
const capabilities = intersectCapabilities(
816+
policy.get(url, ns.policyContext(request)),
817+
request);
818+
allowed = !policyType || capabilities.has(policyType);
819+
if (allowed && request._dataUrl && type.endsWith("frame")) {
820+
const blocker = csp.buildFromCapabilities(capabilities);
821+
if (blocker) {
822+
const redirectUrl = CSP.patchDataURI(request._dataUrl, blocker);
823+
if (redirectUrl !== request._dataUrl) {
824+
return previous.return = { redirectUrl };
824825
}
825826
}
826827
}

0 commit comments

Comments
 (0)