-
Notifications
You must be signed in to change notification settings - Fork 0
/
csp.js
executable file
·91 lines (86 loc) · 2.84 KB
/
csp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require('yargs')
.usage('Usage: $0 <command> [options]')
.command('directives', 'Create csp directives', yargs => {
return yargs
.option('input', {
alias: 'i',
type: 'string',
desc: 'Standard CSP log in JSON format',
demandOption: true
})
.option('output', {
alias: 'o',
type: 'string',
desc: 'Output file in out/ with directives in JSON format'
})
.option('repeats', {
default: 3,
alias: 'r',
type: 'number',
desc: 'Number of domains repeats for wildcard replacing'
})
.option('autoSchema', {
default: false,
alias: 'as',
type: 'boolean',
desc: 'Add https and http protocol to generated domain names'
})
.option('whiteList', {
alias: 'wl',
type: 'string',
desc: 'Approved domains list in JSON format'
})
.option('defaults', {
default: './defaults.json',
alias: 'd',
type: 'string',
desc: 'Default CSP directives'
});
}, args => {
const {input, output, repeats, autoSchema} = args;
let {whiteList} = args;
let defaults;
if (args.defaults) {
defaults = require(args.defaults);
}
if (args.whiteList) {
whiteList = require(args.whiteList);
}
require('./commands/directives')(input, {output, repeats, autoSchema, defaults, whiteList});
})
.command('rules', 'Create csp header from directives', yargs => {
return yargs
.option('input', {
alias: 'i',
type: 'string',
desc: 'Directives created by "generate directives" command',
demandOption: true
})
.option('output', {
alias: 'o',
type: 'string',
desc: 'Output file in out/ with rules'
})
.option('whiteList', {
alias: 'wl',
type: 'string',
desc: 'Approved domains list in JSON format'
})
.option('reportUri', {
alias: 'r',
type: 'string',
desc: 'Report URI'
});
}, args => {
const {input, output, reportUri} = args;
let whiteList;
if (args.whiteList) {
whiteList = require(args.whiteList);
}
require('./commands/rules')(input, {output, whiteList, reportUri});
})
.help('h')
.alias('h', 'help')
.showHelpOnFail(true)
.demandCommand(1, '')
.argv;