fixup! styleViaXhr: allow cookies for sandbox CSP

This commit is contained in:
tophf 2020-11-15 12:16:58 +03:00
parent 89ec4f352a
commit f4a4b05b6e

View File

@ -78,11 +78,11 @@ CHROME && (async () => {
name: 'Set-Cookie', name: 'Set-Cookie',
value: `${chrome.runtime.id}=${prefs.get('disableAll') ? 1 : 0}${blobId}`, value: `${chrome.runtime.id}=${prefs.get('disableAll') ? 1 : 0}${blobId}`,
}); });
// allow cookies or strip sandbox from CSP (known case: raw github urls) // allow cookies for sandbox CSP (known case: raw github urls)
for (const h of responseHeaders) { for (const h of responseHeaders) {
if (h.name.toLowerCase() === 'content-security-policy' && h.value.includes('sandbox')) { if (h.name.toLowerCase() === 'content-security-policy' && h.value.includes('sandbox')) {
h.value = h.value.replace(/((?:^|;)\s*sandbox)(\s+[^;]+)?\s*(?=;|$)/, h.value = h.value.replace(/(?:^|;)\s*sandbox(\s+[^;]*|)(?=;|$)/, (s, allow) =>
(_, a, b) => !b || b === 'allow-same-origin' ? `${a} allow-same-origin` : ''); allow.split(/\s+/).includes('allow-same-origin') ? s : `${s} allow-same-origin`);
break; break;
} }
} }