More graceful handling of internal and restricted URLs.

This commit is contained in:
hackademix 2018-07-09 01:36:28 +02:00
parent 5217db79ce
commit 103324e5d2
2 changed files with 9 additions and 3 deletions

View File

@ -314,6 +314,7 @@ var RequestGuard = (() => {
const ABORT = {cancel: true}, ALLOW = {}; const ABORT = {cancel: true}, ALLOW = {};
const INTERNAL_SCHEME = /^(?:chrome|resource|moz-extension|about):/;
const listeners = { const listeners = {
onBeforeRequest(request) { onBeforeRequest(request) {
try { try {
@ -324,7 +325,7 @@ var RequestGuard = (() => {
let {url, originUrl, documentUrl} = request; let {url, originUrl, documentUrl} = request;
if (("fetch" === policyType || "frame" === policyType) && if (("fetch" === policyType || "frame" === policyType) &&
(url === originUrl && originUrl === documentUrl || (url === originUrl && originUrl === documentUrl ||
/^(?:chrome|resource|moz-extension|about):/.test(originUrl)) INTERNAL_SCHEME.test(originUrl))
) { ) {
// livemark request or similar browser-internal, always allow; // livemark request or similar browser-internal, always allow;
return ALLOW; return ALLOW;
@ -334,7 +335,8 @@ var RequestGuard = (() => {
request._dataUrl = url; request._dataUrl = url;
request.url = url = documentUrl; request.url = url = documentUrl;
} }
let allowed = !ns.isEnforced(request.tabId) || let allowed = INTERNAL_SCHEME.test(url) ||
!ns.isEnforced(request.tabId) ||
policy.can(url, policyType, originUrl); policy.can(url, policyType, originUrl);
Content.reportTo(request, allowed, policyType); Content.reportTo(request, allowed, policyType);

View File

@ -130,10 +130,14 @@ addEventListener("unload", e => {
} catch (e) { } catch (e) {
error(e, "Could not run scripts on %s: privileged page?", tab.url); error(e, "Could not run scripts on %s: privileged page?", tab.url);
} }
if (!isHttp) {
await include("/lib/restricted.js");
let isRestricted = isRestrictedURL(tab.url);
if (!isHttp || isRestricted) {
showMessage("warning", _("privilegedPage")); showMessage("warning", _("privilegedPage"));
let tempTrust = document.getElementById("temp-trust-page"); let tempTrust = document.getElementById("temp-trust-page");
tempTrust.disabled = true; tempTrust.disabled = true;
return;
} }
if (!UI.seen) { if (!UI.seen) {
if (!isHttp) return; if (!isHttp) return;