summaryrefslogtreecommitdiff
path: root/common/misc.js
diff options
context:
space:
mode:
Diffstat (limited to 'common/misc.js')
-rw-r--r--common/misc.js20
1 files changed, 20 insertions, 0 deletions
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
*/