Revision 57e4ed2b
Added by jahoti about 2 years ago
common/misc.js | ||
---|---|---|
154 | 154 |
return gen_unique(time + policy); |
155 | 155 |
} |
156 | 156 |
|
157 |
/* Parse a CSP header */ |
|
158 |
function parse_csp(csp) { |
|
159 |
let directive, directive_array; |
|
160 |
let directives = {}; |
|
161 |
for (directive of csp.split(';')) { |
|
162 |
directive = directive.trim; |
|
163 |
if (directive === '') |
|
164 |
continue; |
|
165 |
|
|
166 |
directive_array = directive.split(/\s+/); |
|
167 |
directive = directive_array.shift(); |
|
168 |
/* The "true" case should never occur; nevertheless... */ |
|
169 |
directives[directive] = directive in directives ? |
|
170 |
directives[directive].concat(directive_array) : |
|
171 |
directive_array; |
|
172 |
} |
|
173 |
return directives; |
|
174 |
} |
|
175 |
|
|
157 | 176 |
/* |
158 | 177 |
* EXPORTS_START |
159 | 178 |
* EXPORT gen_nonce |
... | ... | |
165 | 184 |
* EXPORT nice_name |
166 | 185 |
* EXPORT open_in_settings |
167 | 186 |
* EXPORT is_privileged_url |
187 |
* EXPORT parse_csp |
|
168 | 188 |
* EXPORTS_END |
169 | 189 |
*/ |
Also available in: Unified diff
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.