summaryrefslogtreecommitdiff
path: root/src/lib/CSP.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/CSP.js')
-rw-r--r--src/lib/CSP.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/CSP.js b/src/lib/CSP.js
new file mode 100644
index 0000000..8550f09
--- /dev/null
+++ b/src/lib/CSP.js
@@ -0,0 +1,22 @@
+"use strict";
+
+class CSP {
+
+ build(...directives) {
+ return directives.join(';');
+ }
+
+ buildBlocker(...types) {
+ return this.build(...(types.map(type => `${type.name || type}-src ${type.value || "'none'"}`)));
+ }
+
+ blocks(header, type) {
+ return `;${header};`.includes(`;${type}-src 'none';`)
+ }
+
+ asHeader(value) {
+ return {name: CSP.headerName, value};
+ }
+}
+
+CSP.headerName = "content-security-policy";