@jamesbrightman/pretty-csp 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -0
- package/LICENSE +21 -0
- package/README.md +112 -2
- package/dist/chunk-JAXLODN4.js +559 -0
- package/dist/chunk-JAXLODN4.js.map +1 -0
- package/dist/chunk-KWWYRHIP.js +224 -0
- package/dist/chunk-KWWYRHIP.js.map +1 -0
- package/dist/chunk-YMAXUCI4.js +66 -0
- package/dist/chunk-YMAXUCI4.js.map +1 -0
- package/dist/cli.cjs +1049 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +328 -0
- package/dist/cli.js.map +1 -0
- package/dist/index-CvwFjLiu.d.cts +426 -0
- package/dist/index-CvwFjLiu.d.ts +426 -0
- package/dist/index.cjs +830 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +42 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.cjs +309 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +38 -0
- package/dist/testing.d.ts +38 -0
- package/dist/testing.js +10 -0
- package/dist/testing.js.map +1 -0
- package/package.json +102 -4
- package/website/static/img/how-it-works.svg +34 -0
- package/website/static/img/pretty-csp-icon.svg +6 -0
- package/website/static/img/pretty-csp-logo.svg +12 -0
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/** Friendly resource names mapped to CSP directives. */
|
|
4
|
+
declare const resourceDirectives: {
|
|
5
|
+
readonly scripts: "script-src";
|
|
6
|
+
readonly connect: "connect-src";
|
|
7
|
+
readonly images: "img-src";
|
|
8
|
+
readonly styles: "style-src";
|
|
9
|
+
readonly fonts: "font-src";
|
|
10
|
+
readonly frames: "frame-src";
|
|
11
|
+
readonly forms: "form-action";
|
|
12
|
+
readonly media: "media-src";
|
|
13
|
+
readonly workers: "worker-src";
|
|
14
|
+
readonly manifest: "manifest-src";
|
|
15
|
+
};
|
|
16
|
+
declare const baseDirectives: {
|
|
17
|
+
readonly default: "default-src";
|
|
18
|
+
readonly objects: "object-src";
|
|
19
|
+
readonly baseUri: "base-uri";
|
|
20
|
+
readonly frameAncestors: "frame-ancestors";
|
|
21
|
+
};
|
|
22
|
+
/** A source string, or a source annotated with a human-readable reason. Risky keywords require a reason. */
|
|
23
|
+
declare const sourceEntrySchema: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
24
|
+
source: z.ZodString;
|
|
25
|
+
reason: z.ZodString;
|
|
26
|
+
}, z.core.$strict>]>;
|
|
27
|
+
/** Rule-set permissions. At least one directive must be supplied. */
|
|
28
|
+
declare const rulesSchema: z.ZodObject<{
|
|
29
|
+
directives: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
30
|
+
source: z.ZodString;
|
|
31
|
+
reason: z.ZodString;
|
|
32
|
+
}, z.core.$strict>]>>>>;
|
|
33
|
+
scripts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
34
|
+
source: z.ZodString;
|
|
35
|
+
reason: z.ZodString;
|
|
36
|
+
}, z.core.$strict>]>>>;
|
|
37
|
+
connect: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
38
|
+
source: z.ZodString;
|
|
39
|
+
reason: z.ZodString;
|
|
40
|
+
}, z.core.$strict>]>>>;
|
|
41
|
+
images: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
42
|
+
source: z.ZodString;
|
|
43
|
+
reason: z.ZodString;
|
|
44
|
+
}, z.core.$strict>]>>>;
|
|
45
|
+
styles: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
46
|
+
source: z.ZodString;
|
|
47
|
+
reason: z.ZodString;
|
|
48
|
+
}, z.core.$strict>]>>>;
|
|
49
|
+
fonts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
50
|
+
source: z.ZodString;
|
|
51
|
+
reason: z.ZodString;
|
|
52
|
+
}, z.core.$strict>]>>>;
|
|
53
|
+
frames: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
54
|
+
source: z.ZodString;
|
|
55
|
+
reason: z.ZodString;
|
|
56
|
+
}, z.core.$strict>]>>>;
|
|
57
|
+
forms: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
58
|
+
source: z.ZodString;
|
|
59
|
+
reason: z.ZodString;
|
|
60
|
+
}, z.core.$strict>]>>>;
|
|
61
|
+
media: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
62
|
+
source: z.ZodString;
|
|
63
|
+
reason: z.ZodString;
|
|
64
|
+
}, z.core.$strict>]>>>;
|
|
65
|
+
workers: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
66
|
+
source: z.ZodString;
|
|
67
|
+
reason: z.ZodString;
|
|
68
|
+
}, z.core.$strict>]>>>;
|
|
69
|
+
manifest: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
70
|
+
source: z.ZodString;
|
|
71
|
+
reason: z.ZodString;
|
|
72
|
+
}, z.core.$strict>]>>>;
|
|
73
|
+
}, z.core.$strict>;
|
|
74
|
+
/** Site-wide directives. */
|
|
75
|
+
declare const baseSchema: z.ZodObject<{
|
|
76
|
+
default: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
77
|
+
source: z.ZodString;
|
|
78
|
+
reason: z.ZodString;
|
|
79
|
+
}, z.core.$strict>]>>>;
|
|
80
|
+
objects: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
81
|
+
source: z.ZodString;
|
|
82
|
+
reason: z.ZodString;
|
|
83
|
+
}, z.core.$strict>]>>>;
|
|
84
|
+
baseUri: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
85
|
+
source: z.ZodString;
|
|
86
|
+
reason: z.ZodString;
|
|
87
|
+
}, z.core.$strict>]>>>;
|
|
88
|
+
frameAncestors: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
89
|
+
source: z.ZodString;
|
|
90
|
+
reason: z.ZodString;
|
|
91
|
+
}, z.core.$strict>]>>>;
|
|
92
|
+
upgradeInsecureRequests: z.ZodOptional<z.ZodBoolean>;
|
|
93
|
+
directives: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
94
|
+
source: z.ZodString;
|
|
95
|
+
reason: z.ZodString;
|
|
96
|
+
}, z.core.$strict>]>>>>;
|
|
97
|
+
scripts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
98
|
+
source: z.ZodString;
|
|
99
|
+
reason: z.ZodString;
|
|
100
|
+
}, z.core.$strict>]>>>;
|
|
101
|
+
connect: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
102
|
+
source: z.ZodString;
|
|
103
|
+
reason: z.ZodString;
|
|
104
|
+
}, z.core.$strict>]>>>;
|
|
105
|
+
images: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
106
|
+
source: z.ZodString;
|
|
107
|
+
reason: z.ZodString;
|
|
108
|
+
}, z.core.$strict>]>>>;
|
|
109
|
+
styles: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
110
|
+
source: z.ZodString;
|
|
111
|
+
reason: z.ZodString;
|
|
112
|
+
}, z.core.$strict>]>>>;
|
|
113
|
+
fonts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
114
|
+
source: z.ZodString;
|
|
115
|
+
reason: z.ZodString;
|
|
116
|
+
}, z.core.$strict>]>>>;
|
|
117
|
+
frames: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
118
|
+
source: z.ZodString;
|
|
119
|
+
reason: z.ZodString;
|
|
120
|
+
}, z.core.$strict>]>>>;
|
|
121
|
+
forms: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
122
|
+
source: z.ZodString;
|
|
123
|
+
reason: z.ZodString;
|
|
124
|
+
}, z.core.$strict>]>>>;
|
|
125
|
+
media: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
126
|
+
source: z.ZodString;
|
|
127
|
+
reason: z.ZodString;
|
|
128
|
+
}, z.core.$strict>]>>>;
|
|
129
|
+
workers: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
130
|
+
source: z.ZodString;
|
|
131
|
+
reason: z.ZodString;
|
|
132
|
+
}, z.core.$strict>]>>>;
|
|
133
|
+
manifest: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
134
|
+
source: z.ZodString;
|
|
135
|
+
reason: z.ZodString;
|
|
136
|
+
}, z.core.$strict>]>>>;
|
|
137
|
+
}, z.core.$strict>;
|
|
138
|
+
/** A named, documented and optionally disabled group of permissions. */
|
|
139
|
+
declare const ruleSetSchema: z.ZodObject<{
|
|
140
|
+
name: z.ZodString;
|
|
141
|
+
purpose: z.ZodString;
|
|
142
|
+
owner: z.ZodOptional<z.ZodString>;
|
|
143
|
+
docs: z.ZodOptional<z.ZodURL>;
|
|
144
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
145
|
+
reviewBy: z.ZodOptional<z.ZodISODate>;
|
|
146
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
147
|
+
rules: z.ZodObject<{
|
|
148
|
+
directives: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
149
|
+
source: z.ZodString;
|
|
150
|
+
reason: z.ZodString;
|
|
151
|
+
}, z.core.$strict>]>>>>;
|
|
152
|
+
scripts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
153
|
+
source: z.ZodString;
|
|
154
|
+
reason: z.ZodString;
|
|
155
|
+
}, z.core.$strict>]>>>;
|
|
156
|
+
connect: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
157
|
+
source: z.ZodString;
|
|
158
|
+
reason: z.ZodString;
|
|
159
|
+
}, z.core.$strict>]>>>;
|
|
160
|
+
images: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
161
|
+
source: z.ZodString;
|
|
162
|
+
reason: z.ZodString;
|
|
163
|
+
}, z.core.$strict>]>>>;
|
|
164
|
+
styles: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
165
|
+
source: z.ZodString;
|
|
166
|
+
reason: z.ZodString;
|
|
167
|
+
}, z.core.$strict>]>>>;
|
|
168
|
+
fonts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
169
|
+
source: z.ZodString;
|
|
170
|
+
reason: z.ZodString;
|
|
171
|
+
}, z.core.$strict>]>>>;
|
|
172
|
+
frames: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
173
|
+
source: z.ZodString;
|
|
174
|
+
reason: z.ZodString;
|
|
175
|
+
}, z.core.$strict>]>>>;
|
|
176
|
+
forms: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
177
|
+
source: z.ZodString;
|
|
178
|
+
reason: z.ZodString;
|
|
179
|
+
}, z.core.$strict>]>>>;
|
|
180
|
+
media: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
181
|
+
source: z.ZodString;
|
|
182
|
+
reason: z.ZodString;
|
|
183
|
+
}, z.core.$strict>]>>>;
|
|
184
|
+
workers: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
185
|
+
source: z.ZodString;
|
|
186
|
+
reason: z.ZodString;
|
|
187
|
+
}, z.core.$strict>]>>>;
|
|
188
|
+
manifest: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
189
|
+
source: z.ZodString;
|
|
190
|
+
reason: z.ZodString;
|
|
191
|
+
}, z.core.$strict>]>>>;
|
|
192
|
+
}, z.core.$strict>;
|
|
193
|
+
}, z.core.$strict>;
|
|
194
|
+
/** Complete configuration. Zod catches duplicate names and invalid rule sets. */
|
|
195
|
+
declare const policyConfigSchema: z.ZodObject<{
|
|
196
|
+
base: z.ZodDefault<z.ZodObject<{
|
|
197
|
+
default: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
198
|
+
source: z.ZodString;
|
|
199
|
+
reason: z.ZodString;
|
|
200
|
+
}, z.core.$strict>]>>>;
|
|
201
|
+
objects: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
202
|
+
source: z.ZodString;
|
|
203
|
+
reason: z.ZodString;
|
|
204
|
+
}, z.core.$strict>]>>>;
|
|
205
|
+
baseUri: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
206
|
+
source: z.ZodString;
|
|
207
|
+
reason: z.ZodString;
|
|
208
|
+
}, z.core.$strict>]>>>;
|
|
209
|
+
frameAncestors: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
210
|
+
source: z.ZodString;
|
|
211
|
+
reason: z.ZodString;
|
|
212
|
+
}, z.core.$strict>]>>>;
|
|
213
|
+
upgradeInsecureRequests: z.ZodOptional<z.ZodBoolean>;
|
|
214
|
+
directives: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
215
|
+
source: z.ZodString;
|
|
216
|
+
reason: z.ZodString;
|
|
217
|
+
}, z.core.$strict>]>>>>;
|
|
218
|
+
scripts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
219
|
+
source: z.ZodString;
|
|
220
|
+
reason: z.ZodString;
|
|
221
|
+
}, z.core.$strict>]>>>;
|
|
222
|
+
connect: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
223
|
+
source: z.ZodString;
|
|
224
|
+
reason: z.ZodString;
|
|
225
|
+
}, z.core.$strict>]>>>;
|
|
226
|
+
images: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
227
|
+
source: z.ZodString;
|
|
228
|
+
reason: z.ZodString;
|
|
229
|
+
}, z.core.$strict>]>>>;
|
|
230
|
+
styles: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
231
|
+
source: z.ZodString;
|
|
232
|
+
reason: z.ZodString;
|
|
233
|
+
}, z.core.$strict>]>>>;
|
|
234
|
+
fonts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
235
|
+
source: z.ZodString;
|
|
236
|
+
reason: z.ZodString;
|
|
237
|
+
}, z.core.$strict>]>>>;
|
|
238
|
+
frames: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
239
|
+
source: z.ZodString;
|
|
240
|
+
reason: z.ZodString;
|
|
241
|
+
}, z.core.$strict>]>>>;
|
|
242
|
+
forms: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
243
|
+
source: z.ZodString;
|
|
244
|
+
reason: z.ZodString;
|
|
245
|
+
}, z.core.$strict>]>>>;
|
|
246
|
+
media: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
247
|
+
source: z.ZodString;
|
|
248
|
+
reason: z.ZodString;
|
|
249
|
+
}, z.core.$strict>]>>>;
|
|
250
|
+
workers: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
251
|
+
source: z.ZodString;
|
|
252
|
+
reason: z.ZodString;
|
|
253
|
+
}, z.core.$strict>]>>>;
|
|
254
|
+
manifest: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
255
|
+
source: z.ZodString;
|
|
256
|
+
reason: z.ZodString;
|
|
257
|
+
}, z.core.$strict>]>>>;
|
|
258
|
+
}, z.core.$strict>>;
|
|
259
|
+
ruleSets: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
260
|
+
name: z.ZodString;
|
|
261
|
+
purpose: z.ZodString;
|
|
262
|
+
owner: z.ZodOptional<z.ZodString>;
|
|
263
|
+
docs: z.ZodOptional<z.ZodURL>;
|
|
264
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
265
|
+
reviewBy: z.ZodOptional<z.ZodISODate>;
|
|
266
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
267
|
+
rules: z.ZodObject<{
|
|
268
|
+
directives: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
269
|
+
source: z.ZodString;
|
|
270
|
+
reason: z.ZodString;
|
|
271
|
+
}, z.core.$strict>]>>>>;
|
|
272
|
+
scripts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
273
|
+
source: z.ZodString;
|
|
274
|
+
reason: z.ZodString;
|
|
275
|
+
}, z.core.$strict>]>>>;
|
|
276
|
+
connect: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
277
|
+
source: z.ZodString;
|
|
278
|
+
reason: z.ZodString;
|
|
279
|
+
}, z.core.$strict>]>>>;
|
|
280
|
+
images: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
281
|
+
source: z.ZodString;
|
|
282
|
+
reason: z.ZodString;
|
|
283
|
+
}, z.core.$strict>]>>>;
|
|
284
|
+
styles: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
285
|
+
source: z.ZodString;
|
|
286
|
+
reason: z.ZodString;
|
|
287
|
+
}, z.core.$strict>]>>>;
|
|
288
|
+
fonts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
289
|
+
source: z.ZodString;
|
|
290
|
+
reason: z.ZodString;
|
|
291
|
+
}, z.core.$strict>]>>>;
|
|
292
|
+
frames: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
293
|
+
source: z.ZodString;
|
|
294
|
+
reason: z.ZodString;
|
|
295
|
+
}, z.core.$strict>]>>>;
|
|
296
|
+
forms: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
297
|
+
source: z.ZodString;
|
|
298
|
+
reason: z.ZodString;
|
|
299
|
+
}, z.core.$strict>]>>>;
|
|
300
|
+
media: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
301
|
+
source: z.ZodString;
|
|
302
|
+
reason: z.ZodString;
|
|
303
|
+
}, z.core.$strict>]>>>;
|
|
304
|
+
workers: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
305
|
+
source: z.ZodString;
|
|
306
|
+
reason: z.ZodString;
|
|
307
|
+
}, z.core.$strict>]>>>;
|
|
308
|
+
manifest: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
309
|
+
source: z.ZodString;
|
|
310
|
+
reason: z.ZodString;
|
|
311
|
+
}, z.core.$strict>]>>>;
|
|
312
|
+
}, z.core.$strict>;
|
|
313
|
+
}, z.core.$strict>>>;
|
|
314
|
+
reporting: z.ZodOptional<z.ZodObject<{
|
|
315
|
+
uri: z.ZodOptional<z.ZodURL>;
|
|
316
|
+
to: z.ZodOptional<z.ZodString>;
|
|
317
|
+
}, z.core.$strict>>;
|
|
318
|
+
}, z.core.$strict>;
|
|
319
|
+
type SourceEntry = z.output<typeof sourceEntrySchema>;
|
|
320
|
+
type Rules = z.output<typeof rulesSchema>;
|
|
321
|
+
type ResourceKey = keyof typeof resourceDirectives;
|
|
322
|
+
type RuleSetInput = z.input<typeof ruleSetSchema>;
|
|
323
|
+
type RuleSet = z.output<typeof ruleSetSchema>;
|
|
324
|
+
type PolicyConfig = z.input<typeof policyConfigSchema>;
|
|
325
|
+
type NormalizedPolicyConfig = z.output<typeof policyConfigSchema>;
|
|
326
|
+
type DirectiveName = (typeof resourceDirectives)[ResourceKey] | (typeof baseDirectives)[keyof typeof baseDirectives] | 'upgrade-insecure-requests' | 'report-uri' | 'report-to';
|
|
327
|
+
|
|
328
|
+
/** Request metadata needed to evaluate checks which cannot be decided from a URL alone. */
|
|
329
|
+
interface MatchOptions {
|
|
330
|
+
/** Origin of the protected document, required for 'self' and schemeless sources. */
|
|
331
|
+
origin?: string;
|
|
332
|
+
/** Number of redirects before this URL; paths are not checked after a redirect. */
|
|
333
|
+
redirectCount?: number;
|
|
334
|
+
/** Nonce on the request; supply an empty string if the request has none. */
|
|
335
|
+
nonce?: string;
|
|
336
|
+
/** Rendered policy nonce for a dynamic nonce placeholder. */
|
|
337
|
+
policyNonce?: string;
|
|
338
|
+
/** Integrity metadata tokens on the request; supply an empty array if absent. */
|
|
339
|
+
integrity?: readonly string[];
|
|
340
|
+
/** Whether a script was parser-inserted. */
|
|
341
|
+
parserInserted?: boolean;
|
|
342
|
+
}
|
|
343
|
+
/** A conservative CSP decision. `indeterminate` never implies browser permission. */
|
|
344
|
+
interface AllowsResult {
|
|
345
|
+
status: 'allowed' | 'blocked' | 'indeterminate';
|
|
346
|
+
allowed: boolean | null;
|
|
347
|
+
effectiveDirective?: string;
|
|
348
|
+
matchedSource?: string;
|
|
349
|
+
reason?: string;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Evaluate a URL against a CSP directive. This deliberately returns indeterminate when
|
|
353
|
+
* relevant request context is unavailable. It is not a full browser simulation.
|
|
354
|
+
* Algorithms: https://www.w3.org/TR/CSP3/#match-url-to-source-list and #directive-fallback-list
|
|
355
|
+
*/
|
|
356
|
+
declare function matchPolicy(directives: Readonly<Record<string, readonly string[]>>, directive: string, input: string, options?: MatchOptions): AllowsResult;
|
|
357
|
+
|
|
358
|
+
/** Reject literal risky strings in input lists while allowing annotated source objects.
|
|
359
|
+
* Dynamic strings remain subject to runtime Zod validation. */
|
|
360
|
+
type RequireRiskReasons<T> = T extends {
|
|
361
|
+
source: string;
|
|
362
|
+
} ? T : T extends string ? Lowercase<T> extends "'unsafe-inline'" | "'unsafe-eval'" | "'unsafe-hashes'" ? never : T : T extends object ? {
|
|
363
|
+
[K in keyof T]: K extends 'name' | 'purpose' | 'owner' | 'docs' | 'tags' | 'reviewBy' | 'enabled' | 'reporting' ? T[K] : RequireRiskReasons<T[K]>;
|
|
364
|
+
} : T;
|
|
365
|
+
interface ExplainRow {
|
|
366
|
+
directive: string;
|
|
367
|
+
source: string;
|
|
368
|
+
ruleSet: string;
|
|
369
|
+
reason?: string;
|
|
370
|
+
}
|
|
371
|
+
interface HeaderOptions {
|
|
372
|
+
nonce?: string;
|
|
373
|
+
pretty?: boolean;
|
|
374
|
+
}
|
|
375
|
+
/** Validate and freeze a rule set. */
|
|
376
|
+
declare function defineRuleSet<const T extends RuleSetInput>(input: T & RequireRiskReasons<T>): RuleSet;
|
|
377
|
+
/** Immutable CSP configuration and its deterministic merged representation. */
|
|
378
|
+
declare class Policy {
|
|
379
|
+
readonly config: NormalizedPolicyConfig;
|
|
380
|
+
constructor(input: PolicyConfig);
|
|
381
|
+
/** Sources and their contributing rule sets. Duplicate values retain all contributors. */
|
|
382
|
+
explain(): ExplainRow[];
|
|
383
|
+
/** Merged sources, deduplicated without changing path syntax. */
|
|
384
|
+
toObject(): Record<string, string[]>;
|
|
385
|
+
/** Evaluate a URL with explicit uncertainty when browser context is missing. */
|
|
386
|
+
allows(directive: string, url: string, options?: MatchOptions): AllowsResult & {
|
|
387
|
+
contributors?: ExplainRow[];
|
|
388
|
+
};
|
|
389
|
+
/** Render a header value. Pretty output is for display only and is not a valid HTTP header value. */
|
|
390
|
+
toHeader(options?: HeaderOptions): string;
|
|
391
|
+
/** Add one or several rule sets in a single validated, immutable update. */
|
|
392
|
+
withRuleSet<const T extends readonly RuleSetInput[]>(ruleSets: T & (T extends RequireRiskReasons<T> ? unknown : never)): Policy;
|
|
393
|
+
withRuleSet<const T extends RuleSetInput>(ruleSet: T & RequireRiskReasons<T>): Policy;
|
|
394
|
+
without(name: string): Policy;
|
|
395
|
+
}
|
|
396
|
+
/** Validate and construct a policy. */
|
|
397
|
+
declare function definePolicy<const T extends PolicyConfig>(input: T & RequireRiskReasons<T>): Policy;
|
|
398
|
+
|
|
399
|
+
type Severity = 'high' | 'medium' | 'low' | 'info';
|
|
400
|
+
interface AuditFinding {
|
|
401
|
+
ruleId: string;
|
|
402
|
+
severity: Severity;
|
|
403
|
+
message: string;
|
|
404
|
+
fix: string;
|
|
405
|
+
directive?: string;
|
|
406
|
+
source?: string;
|
|
407
|
+
ruleSet?: string;
|
|
408
|
+
}
|
|
409
|
+
interface AuditRule {
|
|
410
|
+
id: string;
|
|
411
|
+
check(policy: Policy): readonly AuditFinding[];
|
|
412
|
+
}
|
|
413
|
+
interface AuditSuppression {
|
|
414
|
+
ruleId: string;
|
|
415
|
+
ruleSet: string;
|
|
416
|
+
reason: string;
|
|
417
|
+
}
|
|
418
|
+
interface AuditOptions {
|
|
419
|
+
rules?: readonly AuditRule[];
|
|
420
|
+
suppressions?: readonly AuditSuppression[];
|
|
421
|
+
now?: Date;
|
|
422
|
+
}
|
|
423
|
+
/** Inspect known dangerous policy patterns. Findings are advisory and do not prove a policy safe. */
|
|
424
|
+
declare function audit(policy: Policy, options?: AuditOptions): AuditFinding[];
|
|
425
|
+
|
|
426
|
+
export { type AllowsResult as A, type DirectiveName as D, type ExplainRow as E, type HeaderOptions as H, type MatchOptions as M, type NormalizedPolicyConfig as N, Policy as P, type RequireRiskReasons as R, type Severity as S, type AuditFinding as a, type AuditOptions as b, type AuditRule as c, type AuditSuppression as d, type PolicyConfig as e, type ResourceKey as f, type RuleSet as g, type RuleSetInput as h, type Rules as i, type SourceEntry as j, audit as k, baseDirectives as l, baseSchema as m, definePolicy as n, defineRuleSet as o, matchPolicy as p, policyConfigSchema as q, resourceDirectives as r, ruleSetSchema as s, rulesSchema as t, sourceEntrySchema as u };
|