2018-05-08 17:49:59 +01:00
|
|
|
import * as config from "./config"
|
|
|
|
|
2018-05-08 18:15:00 +01:00
|
|
|
export function addurltocsp(response) {
|
2017-11-21 13:59:57 +00:00
|
|
|
let headers = response["responseHeaders"]
|
2018-05-08 18:15:00 +01:00
|
|
|
let cspind = headers.findIndex(
|
|
|
|
header => header.name == "Content-Security-Policy",
|
|
|
|
)
|
2017-11-21 13:59:57 +00:00
|
|
|
// if it's found
|
|
|
|
if (cspind > -1) {
|
|
|
|
// Split the csp header up so we can manage it individually.
|
|
|
|
let csparr = [headers[cspind]["value"].split("; ")][0]
|
|
|
|
|
2018-05-08 18:15:00 +01:00
|
|
|
for (let i = 0; i < csparr.length; i++) {
|
|
|
|
// Add 'unsafe-inline' as a directive since we use it
|
2017-11-21 13:59:57 +00:00
|
|
|
if (csparr[i].indexOf("style-src") > -1) {
|
|
|
|
if (csparr[i].indexOf("'self'") > -1) {
|
2018-05-08 18:15:00 +01:00
|
|
|
csparr[i] = csparr[i].replace(
|
|
|
|
"'self'",
|
|
|
|
"'self' 'unsafe-inline'",
|
|
|
|
)
|
2017-11-21 13:59:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Remove the element if it's a sandbox directive
|
|
|
|
if (csparr[i] === "sandbox") {
|
2018-05-08 18:15:00 +01:00
|
|
|
csparr.splice(i, 1)
|
2017-11-21 13:59:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Join the header up after clobberin'
|
|
|
|
headers[cspind]["value"] = csparr.join("; ")
|
|
|
|
}
|
2018-05-08 18:15:00 +01:00
|
|
|
return { responseHeaders: headers }
|
2018-05-08 17:49:59 +01:00
|
|
|
}
|