summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjahoti <jahoti@tilde.team>2021-07-17 00:00:00 +0000
committerjahoti <jahoti@tilde.team>2021-07-17 00:00:00 +0000
commit8b823e1a6f29e52effc086d02dfe2e2812b2e187 (patch)
treed86f7a69cb5faf00050aa774e3d2b675a41245ad
parent692577bbde5e8110855c022ec913324dfddce9ae (diff)
downloadbrowser-extension-8b823e1a6f29e52effc086d02dfe2e2812b2e187.tar.gz
browser-extension-8b823e1a6f29e52effc086d02dfe2e2812b2e187.zip
Revamp signatures and break header caching on FF
Signatures, instead of consisting of the secure salt followed by the unique value generated from the URL, are now the unique value generated from the policy value (which will follow them) succeeded by the URL. CSP headers are now _always_ cleared on FF, regardless of whether the page is whitelisted or not. This means whitelisting takes effect on page reload, rather than only when caching occurs. However, it obviously presents security issues; refinment will occur in a future commit.
-rw-r--r--background/policy_injector.js29
-rw-r--r--common/misc.js26
-rw-r--r--content/main.js11
3 files changed, 32 insertions, 34 deletions
diff --git a/background/policy_injector.js b/background/policy_injector.js
index 9e8ed61..8a767fb 100644
--- a/background/policy_injector.js
+++ b/background/policy_injector.js
@@ -12,6 +12,7 @@
* IMPORT get_storage
* IMPORT browser
* IMPORT is_chrome
+ * IMPORT is_mozilla
* IMPORT gen_unique
* IMPORT gen_nonce
* IMPORT url_item
@@ -45,23 +46,24 @@ function is_our_header(header, rule)
function url_inject(details)
{
const targets = url_extract_policy(details.url);
- if (targets.policy) {
+ if (targets.valid_sig) {
return;
- } else if (targets.signed) {
+ } else if (targets.policy) {
/* Redirect; update policy */
targets.target = targets.target2;
delete targets.target2
}
- let redirect_url = targets.base_url + targets.sig;
let [pattern, settings] = query_best(targets.base_url);
if (!pattern)
/* Defaults */
settings = {};
const policy = {allow: settings.allow, nonce: gen_nonce()};
+ const policy_string = encodeURIComponent(JSON.stringify(policy));
+ const sig = gen_unique(policy_string + targets.base_url);
- redirect_url += encodeURIComponent(JSON.stringify(policy));
+ let redirect_url = targets.base_url + '#' + sig + policy_string;
if (targets.target)
redirect_url += targets.target;
if (targets.target2)
@@ -73,31 +75,26 @@ function url_inject(details)
function inject(details)
{
const targets = url_extract_policy(details.url);
- if (!targets.policy)
+ if (!targets.valid_sig)
/* Block unsigned requests */
return {cancel: true};
const rule = csp_rule(targets.policy.nonce);
- var headers;
+ var headers = details.responseHeaders;
- if (targets.policy.allow) {
+ if (!targets.policy.allow || is_mozilla)
/*
- * Chrome doesn't have the buggy behavior of repeatedly injecting a
- * header we injected once. Firefox does and we have to remove it there.
+ * Chrome doesn't have the buggy behavior of caching headers
+ * we injected. Firefox does and we have to remove it there.
*/
- if (is_chrome)
- return {cancel: false};
-
- headers = details.responseHeaders.filter(h => !is_our_header(h, rule));
- } else {
- headers = details.responseHeaders.filter(h => !is_csp_header(h));
+ headers = headers.filter(h => !is_csp_header(h));
+ if (!targets.policy.allow)
headers.push({
name : header_name,
value : rule
});
- }
return {responseHeaders: headers};
}
diff --git a/common/misc.js b/common/misc.js
index 825a117..036eb45 100644
--- a/common/misc.js
+++ b/common/misc.js
@@ -35,9 +35,9 @@ function gen_unique(url)
function get_secure_salt()
{
if (is_chrome)
- return browser.runtime.getManifest().key.substring(0, 36);
+ return browser.runtime.getManifest().key.substring(0, 50);
else
- return browser.runtime.getURL("dummy").substr(16, 36);
+ return browser.runtime.getURL("dummy");
}
/*
@@ -107,19 +107,19 @@ function is_privileged_url(url)
/* Extract any policy present in the URL */
function url_extract_policy(url)
{
+ var policy_string;
const targets = url_extract_target(url);
- const key = '#' + get_secure_salt();
- targets.sig = key + gen_unique(targets.base_url);
- if (targets.target && targets.target.startsWith(key)) {
- targets.signed = true;
- if (targets.target.startsWith(targets.sig))
- try {
- const policy_string = targets.target.substring(101);
- targets.policy = JSON.parse(decodeURIComponent(policy_string));
- } catch (e) {
- /* TODO what should happen here? */
- }
+ try {
+ policy_string = targets.target.substring(65);
+ targets.policy = JSON.parse(decodeURIComponent(policy_string));
+ } catch (e) {
+ /* TODO what should happen here? */
+ }
+
+ if (targets.policy) {
+ const sig = gen_unique(policy_string + targets.base_url);
+ targets.valid_sig = targets.target.substring(1, 65) === sig;
}
return targets;
diff --git a/content/main.js b/content/main.js
index e75f61d..317b319 100644
--- a/content/main.js
+++ b/content/main.js
@@ -100,15 +100,16 @@ function inject_csp(head)
if (!is_privileged_url(document.URL)) {
const targets = url_extract_policy(document.URL);
- targets.policy = targets.policy || {};
- const nonce = targets.policy.nonce || gen_nonce();
-
- if (targets.signed)
+ if (targets.policy) {
if (targets.target2 !== undefined)
window.location.href = targets.base_url + targets.target2;
else
history.replaceState(null, "", targets.base_url);
-
+ }
+
+ targets.policy = targets.valid_sig ? targets.policy : {};
+
+ const nonce = targets.policy.nonce || gen_nonce();
start_activity_info_server();
handle_page_actions(nonce);
4.14-x86_64.conf, gnu/packages/aux-files/linux-libre/4.19-i686.conf, gnu/packages/aux-files/linux-libre/4.19-x86_64.conf, gnu/packages/aux-files/linux-libre/5.4-i686.conf, gnu/packages/aux-files/linux-libre/5.4-x86_64.conf, gnu/packages/aux-files/linux-libre/5.10-i686.conf, gnu/packages/aux-files/linux-libre/5.10-x86_64.conf, gnu/packages/aux-files/linux-libre/5.15-i686.conf, gnu/packages/aux-files/linux-libre/5.15-x86_64.conf: Mark simple framebuffers as generic system ones and enable ‘Google’ firmware drivers to enable Coreboot table support and its dependent framebuffer driver module. * gnu/system/linux-initrd.scm (default-initrd-modules): Add the framebuffer_coreboot and simplefb modules on x86 systems. Tobias Geerinckx-Rice via Guix-patches via 2021-12-05Merge remote-tracking branch 'origin/master' into core-updates-frozenRicardo Wurmus 2021-12-03gnu: emacs: Load package descriptors from packages referenced by subdirs.el•••* gnu/packages/aux-files/emacs/guix-emacs.el (guix-emacs--non-core-load-path): New procedure. (guix-emacs-autoload-packages): Use it here. (guix-emacs-load-package-descriptors): New procedure. * gnu/packages/emacs.scm (emacs)[install-site-start]: Install advice to run ‘guix-emacs-load-package-descriptors’. Liliana Marie Prikler 2021-11-26gnu: Remove linux-libre 5.14.•••* gnu/packages/linux.scm (linux-libre-5.14-version, linux-libre-5.14-gnu-revision, deblob-scripts-5.14, linux-libre-5.14-pristine-source, linux-libre-5.14-source, linux-libre-headers-5.14, linux-libre-5.14): Remove variables. * gnu/packages/aux-files/linux-libre/5.14-arm.conf, gnu/packages/aux-files/linux-libre/5.14-arm64.conf, gnu/packages/aux-files/linux-libre/5.14-i686.conf, gnu/packages/aux-files/linux-libre/5.14-x86_64.conf: Delete files. * Makefile.am (AUX_FILES): Remove them. Leo Famulari 2021-11-26gnu: Add linux-libre 5.15.5.•••* gnu/packages/linux.scm (linux-libre-5.15-version, linux-libre-5.15-gnu-revision, deblob-scripts-5.15, linux-libre-5.15-pristine-source, linux-libre-5.15-source, linux-libre-headers-5.15, linux-libre-5.15): New variables. * gnu/packages/aux-files/linux-libre/5.15-arm.conf, gnu/packages/aux-files/linux-libre/5.15-arm64.conf, gnu/packages/aux-files/linux-libre/5.15-i686.conf, gnu/packages/aux-files/linux-libre/5.15-x86_64.conf: New files. * Makefile.am (AUX_FILES): Add them Leo Famulari 2021-11-11aux-files: sitecustomize: Cleanup and add explanatory comments.•••Fixes <https://issues.guix.gnu.org/50105>. * gnu/packages/aux-files/python/sitecustomize.py: Add a comment explaining the general idea, and use sys.prefix instead of sys.executable. (major_minor): Use the unpacking operator (*) to provide the arguments. (site_packages_prefix): Use os.path.join to form the path. (python_site): Likewise. Use sys.prefix instead of sys.executable. (all_sites_raw): Split on os.path.pathsep. (sys.path): Directly splice the result in the list. Suggested-by: Hartmut Goebel <h.goebel@crazy-compilers.com> Reported-by: Mathieu Othacehe <othacehe@gnu.org> Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Maxim Cournoyer 2021-10-12Merge remote-tracking branch 'origin/master' into core-updates-frozen.Mathieu Othacehe 2021-09-22gnu: linux-libre: Update to 5.14.7.•••* gnu/packages/linux.scm (linux-libre-5.13-version, linux-libre-5.13-gnu-revision, linux-libre-5.13-pristine-source, linux-libre-5.13-source, linux-libre-headers-5.13, linux-libre-5.13): Remove variables. (linux-libre-version, linux-libre-gnu-revision, linux-libre-pristine-source, linux-libre-source, linux-libre, linux-libre-with-bpf): Use 5.14. * gnu/packages/aux-files/linux-libre/5.13-arm.conf, gnu/packages/aux-files/linux-libre/5.13-arm64.conf, gnu/packages/aux-files/linux-libre/5.13-i686.conf, gnu/packages/aux-files/linux-libre/5.13-x86_64.conf: Delete files. * Makefile.am (AUX_FILES): Remove them. Leo Famulari 2021-09-17Merge branch 'master' into core-updates-frozen••• Conflicts: gnu/packages/bioinformatics.scm gnu/packages/chez.scm gnu/packages/docbook.scm gnu/packages/ebook.scm gnu/packages/gnome.scm gnu/packages/linux.scm gnu/packages/networking.scm gnu/packages/python-web.scm gnu/packages/python-xyz.scm gnu/packages/tex.scm gnu/packages/version-control.scm gnu/packages/xml.scm guix/build-system/dune.scm guix/build-system/go.scm guix/build-system/linux-module.scm guix/packages.scm Marius Bakke 2021-09-07Merge branch 'master' into core-updates-frozenLudovic Courtès 2021-09-06gnu: Add linux-libre 5.14.1.•••* gnu/packages/linux.scm (linux-libre-5.14-version, deblob-scripts-5.14, linux-libre-5.14-pristine-source, linux-libre-5.14-source, linux-libre-headers-5.14, linux-libre-5.14): New variables. * gnu/packages/aux-files/linux-libre/5.14-arm.conf, gnu/packages/aux-files/linux-libre/5.14-arm64.conf, gnu/packages/aux-files/linux-libre/5.14-i686.conf, gnu/packages/aux-files/linux-libre/5.14-x86_64.conf: New files. * Makefile.am (AUX_FILES): Add them. Leo Famulari 2021-07-30build-system/python: Handle missing metadata on Python 2.•••* gnu/packages/aux-files/python/sanity-check.py: Catch the less specific EnvironmentError rather than FileNotFoundError as the latter is Python 3 only. Marius Bakke 2021-07-29Merge branch 'master' into core-updates-frozen••• Conflicts: gnu/packages/bioinformatics.scm gnu/packages/cmake.scm gnu/packages/curl.scm gnu/packages/emacs-xyz.scm gnu/packages/gpodder.scm gnu/packages/music.scm gnu/packages/patches/glibc-bootstrap-system.patch gnu/packages/python-xyz.scm gnu/packages/shells.scm gnu/packages/statistics.scm Marius Bakke 2021-07-28gnu: linux-libre: Update to 5.13.6.•••* gnu/packages/linux.scm (linux-libre-5.12-version, deblob-scripts-5.12 linux-libre-5.12-pristine-source, linux-libre-5.12-source, linux-libre-headers-5.12, linux-libre-5.12): Remove variables. (linux-libre-version, linux-libre-pristine-source, linux-libre-source, linux-libre): Update to the 5.13 kernel series. (linux-libre-with-bpf): Update to 5.13 kernel series. * gnu/packages/aux-files/linux-libre/5.12-arm.conf, gnu/packages/aux-files/linux-libre/5.12-arm64.conf, gnu/packages/aux-files/linux-libre/5.12-i686.conf, gnu/packages/aux-files/linux-libre/5.12-x86_64.conf: Delete files. * Makefile.am (AUX_FILES): Remove them. Leo Famulari 2021-08-14gnu: linux-libre: Add perf probe support.•••* gnu/packages/aux-files/linux-libre/5.10-i686.conf: Enable CONFIG_UPROBE_EVENTS option. * gnu/packages/aux-files/linux-libre/5.10-x86_64.conf: Ditto. * gnu/packages/aux-files/linux-libre/5.13-i686.conf: Ditto. * gnu/packages/aux-files/linux-libre/5.13-x86_64.conf: Ditto. * gnu/packages/aux-files/linux-libre/5.4-i686.conf: Ditto. * gnu/packages/aux-files/linux-libre/5.4-x86_64.conf: Ditto. Mathieu Othacehe