summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjahoti <jahoti@tilde.team>2021-07-21 00:00:00 +0000
committerWojtek Kosior <koszko@koszko.org>2021-07-26 11:09:57 +0200
commit57e4ed2b06d15747b20737bad14bcdd2d73fd8a6 (patch)
tree03219829cf07db1f5d3e695c2380384a17193c8f
parent081739e7dcaeed1e0655a49ebdebb02d653d9042 (diff)
downloadbrowser-extension-57e4ed2b06d15747b20737bad14bcdd2d73fd8a6.tar.gz
browser-extension-57e4ed2b06d15747b20737bad14bcdd2d73fd8a6.zip
Remove unnecessary imports of url_item and add a CSP header-parsing function
The parsing function isn't used yet; however, it will eventually be as a less destructive alternative to handling headers as indivisible units.
-rw-r--r--background/policy_injector.js1
-rw-r--r--common/misc.js20
-rw-r--r--content/main.js1
3 files changed, 20 insertions, 2 deletions
diff --git a/background/policy_injector.js b/background/policy_injector.js
index 01da094..9a994f8 100644
--- a/background/policy_injector.js
+++ b/background/policy_injector.js
@@ -16,7 +16,6 @@
* IMPORT gen_unique
* IMPORT gen_nonce
* IMPORT is_privileged_url
- * IMPORT url_item
* IMPORT url_extract_target
* IMPORT sign_policy
* IMPORT get_query_best
diff --git a/common/misc.js b/common/misc.js
index a59ec14..6af2327 100644
--- a/common/misc.js
+++ b/common/misc.js
@@ -154,6 +154,25 @@ function sign_policy(policy, now, hours_offset) {
return gen_unique(time + policy);
}
+/* Parse a CSP header */
+function parse_csp(csp) {
+ let directive, directive_array;
+ let directives = {};
+ for (directive of csp.split(';')) {
+ directive = directive.trim;
+ if (directive === '')
+ continue;
+
+ directive_array = directive.split(/\s+/);
+ directive = directive_array.shift();
+ /* The "true" case should never occur; nevertheless... */
+ directives[directive] = directive in directives ?
+ directives[directive].concat(directive_array) :
+ directive_array;
+ }
+ return directives;
+}
+
/*
* EXPORTS_START
* EXPORT gen_nonce
@@ -165,5 +184,6 @@ function sign_policy(policy, now, hours_offset) {
* EXPORT nice_name
* EXPORT open_in_settings
* EXPORT is_privileged_url
+ * EXPORT parse_csp
* EXPORTS_END
*/
diff --git a/content/main.js b/content/main.js
index 8f8375e..9ed557c 100644
--- a/content/main.js
+++ b/content/main.js
@@ -9,7 +9,6 @@
/*
* IMPORTS_START
* IMPORT handle_page_actions
- * IMPORT url_item
* IMPORT url_extract_target
* IMPORT gen_unique
* IMPORT gen_nonce