summaryrefslogtreecommitdiff
path: root/src/lib/CSP.js
blob: 8550f09c44519c76e2393757ebe691f0c801915e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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";