summaryrefslogtreecommitdiff
path: root/src/lib/CSP.js
blob: 79590bc6b2437246999314066e0c4f236a80d9cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"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.isEmbedType = type => /\b(?:application|video|audio)\b/.test(type);
CSP.headerName = "content-security-policy";