From 57e4ed2b06d15747b20737bad14bcdd2d73fd8a6 Mon Sep 17 00:00:00 2001 From: jahoti Date: Wed, 21 Jul 2021 00:00:00 +0000 Subject: 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. --- background/policy_injector.js | 1 - common/misc.js | 20 ++++++++++++++++++++ content/main.js | 1 - 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 -- cgit v1.2.3