@jamesbrightman/pretty-csp 0.0.0-stage → 0.1.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 +11 -0
- package/LICENSE +21 -0
- package/README.md +76 -2
- package/dist/chunk-KWWYRHIP.js +224 -0
- package/dist/chunk-KWWYRHIP.js.map +1 -0
- package/dist/chunk-MDUQKU6Y.js +67 -0
- package/dist/chunk-MDUQKU6Y.js.map +1 -0
- package/dist/chunk-TE3J7Y25.js +875 -0
- package/dist/chunk-TE3J7Y25.js.map +1 -0
- package/dist/cli.cjs +1667 -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 +637 -0
- package/dist/cli.js.map +1 -0
- package/dist/index-D6PmUWjD.d.cts +451 -0
- package/dist/index-D6PmUWjD.d.ts +451 -0
- package/dist/index.cjs +1146 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +79 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.cjs +310 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +35 -0
- package/dist/testing.d.ts +35 -0
- package/dist/testing.js +10 -0
- package/dist/testing.js.map +1 -0
- package/package.json +91 -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
package/dist/testing.cjs
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/testing/index.ts
|
|
21
|
+
var testing_exports = {};
|
|
22
|
+
__export(testing_exports, {
|
|
23
|
+
cspMatchers: () => cspMatchers,
|
|
24
|
+
cspSnapshot: () => cspSnapshot
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(testing_exports);
|
|
27
|
+
|
|
28
|
+
// src/audit/index.ts
|
|
29
|
+
var sourceFindings = (policy, directive, source, ruleId, severity, message, fix) => {
|
|
30
|
+
const owners = policy.explain().filter((row) => row.directive === directive && row.source === source);
|
|
31
|
+
return owners.length ? owners.map(({ ruleSet }) => ({
|
|
32
|
+
ruleId,
|
|
33
|
+
severity,
|
|
34
|
+
message,
|
|
35
|
+
fix,
|
|
36
|
+
directive,
|
|
37
|
+
source,
|
|
38
|
+
ruleSet
|
|
39
|
+
})) : [{ ruleId, severity, message, fix, directive, source }];
|
|
40
|
+
};
|
|
41
|
+
function audit(policy, options = {}) {
|
|
42
|
+
const object = policy.toObject();
|
|
43
|
+
const findings = [];
|
|
44
|
+
const add = (id, severity, message, fix, directive) => findings.push({
|
|
45
|
+
ruleId: id,
|
|
46
|
+
severity,
|
|
47
|
+
message,
|
|
48
|
+
fix,
|
|
49
|
+
...directive ? { directive } : {}
|
|
50
|
+
});
|
|
51
|
+
if (!object["script-src"] && !object["default-src"])
|
|
52
|
+
add(
|
|
53
|
+
"missing-script-src",
|
|
54
|
+
"high",
|
|
55
|
+
"Some script execution is unrestricted.",
|
|
56
|
+
"Restrict script-src or default-src.",
|
|
57
|
+
"script-src"
|
|
58
|
+
);
|
|
59
|
+
for (const directive of [
|
|
60
|
+
"script-src",
|
|
61
|
+
"script-src-elem",
|
|
62
|
+
"script-src-attr",
|
|
63
|
+
"default-src"
|
|
64
|
+
]) {
|
|
65
|
+
const sources = object[directive];
|
|
66
|
+
if (!sources) continue;
|
|
67
|
+
const isFallback = directive === "default-src" && object["script-src"] !== void 0;
|
|
68
|
+
if (isFallback) continue;
|
|
69
|
+
const hasNonceOrHash = sources.some(
|
|
70
|
+
(s) => /^'(nonce-|sha(?:256|384|512)-)/i.test(s)
|
|
71
|
+
);
|
|
72
|
+
for (const source of sources.filter(
|
|
73
|
+
(s) => s.toLowerCase() === "'unsafe-inline'" && !hasNonceOrHash
|
|
74
|
+
))
|
|
75
|
+
findings.push(
|
|
76
|
+
...sourceFindings(
|
|
77
|
+
policy,
|
|
78
|
+
directive,
|
|
79
|
+
source,
|
|
80
|
+
"script-unsafe-inline",
|
|
81
|
+
"high",
|
|
82
|
+
"Inline scripts are permitted.",
|
|
83
|
+
"Use nonces or hashes and remove unsafe-inline."
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
for (const source of sources.filter(
|
|
87
|
+
(s) => s.toLowerCase() === "'unsafe-eval'"
|
|
88
|
+
))
|
|
89
|
+
findings.push(
|
|
90
|
+
...sourceFindings(
|
|
91
|
+
policy,
|
|
92
|
+
directive,
|
|
93
|
+
source,
|
|
94
|
+
"script-unsafe-eval",
|
|
95
|
+
"high",
|
|
96
|
+
"Dynamic JavaScript evaluation is permitted.",
|
|
97
|
+
"Remove unsafe-eval and replace dynamic evaluation."
|
|
98
|
+
)
|
|
99
|
+
);
|
|
100
|
+
if (directive !== "script-src-attr" && sources.some((source) => source.toLowerCase() === "'strict-dynamic'")) {
|
|
101
|
+
for (const source of sources) {
|
|
102
|
+
if (source.toLowerCase() === "'self'" || source === "*" || /^[a-z][a-z0-9+.-]*:$/i.test(source) || /^(?:[a-z][a-z0-9+.-]*:\/\/)?(?:\*|[a-z0-9*.-]+)(?::(?:\*|\d+))?(?:\/[^\s]*)?$/i.test(
|
|
103
|
+
source
|
|
104
|
+
)) {
|
|
105
|
+
findings.push(
|
|
106
|
+
...sourceFindings(
|
|
107
|
+
policy,
|
|
108
|
+
directive,
|
|
109
|
+
source,
|
|
110
|
+
"ignored-by-strict-dynamic",
|
|
111
|
+
"info",
|
|
112
|
+
"Modern browsers ignore this source for scripts under strict-dynamic.",
|
|
113
|
+
"Remove it if legacy browser fallback is not needed."
|
|
114
|
+
)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const source of sources)
|
|
120
|
+
if (["*", "https:", "http:", "data:"].includes(source.toLowerCase()) || /^(?:https?:\/\/)?\*(?::(?:\*|\d+))?(?:\/[^\s]*)?$/i.test(source))
|
|
121
|
+
findings.push(
|
|
122
|
+
...sourceFindings(
|
|
123
|
+
policy,
|
|
124
|
+
directive,
|
|
125
|
+
source,
|
|
126
|
+
"script-wildcard",
|
|
127
|
+
"high",
|
|
128
|
+
"A broad script source may permit attacker-controlled scripts.",
|
|
129
|
+
"Restrict script sources and prefer nonces or hashes."
|
|
130
|
+
)
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
const objects = object["object-src"] ?? object["default-src"];
|
|
134
|
+
if (!objects || objects.length !== 1 || objects[0]?.toLowerCase() !== "'none'")
|
|
135
|
+
add(
|
|
136
|
+
"missing-object-src",
|
|
137
|
+
"high",
|
|
138
|
+
"Object embedding is not explicitly blocked.",
|
|
139
|
+
"Set object-src to 'none'.",
|
|
140
|
+
"object-src"
|
|
141
|
+
);
|
|
142
|
+
const broad = (sources) => !sources || sources.some(
|
|
143
|
+
(source) => source === "*" || /^[a-z][a-z0-9+.-]*:$/i.test(source) || /^(?:https?:\/\/)?\*(?::(?:\*|\d+))?(?:\/[^\s]*)?$/i.test(source)
|
|
144
|
+
);
|
|
145
|
+
if (broad(object["base-uri"]))
|
|
146
|
+
add(
|
|
147
|
+
"missing-base-uri",
|
|
148
|
+
"medium",
|
|
149
|
+
"The document base URL is not sufficiently restricted.",
|
|
150
|
+
"Set base-uri to 'none' or 'self'.",
|
|
151
|
+
"base-uri"
|
|
152
|
+
);
|
|
153
|
+
if (broad(object["frame-ancestors"]))
|
|
154
|
+
add(
|
|
155
|
+
"missing-frame-ancestors",
|
|
156
|
+
"medium",
|
|
157
|
+
"Embedding by other sites is not sufficiently restricted.",
|
|
158
|
+
"Restrict frame-ancestors to trusted origins.",
|
|
159
|
+
"frame-ancestors"
|
|
160
|
+
);
|
|
161
|
+
const knownBypassDomains = [
|
|
162
|
+
"google.com",
|
|
163
|
+
"googleapis.com",
|
|
164
|
+
"googleusercontent.com",
|
|
165
|
+
"gstatic.com"
|
|
166
|
+
];
|
|
167
|
+
for (const row of policy.explain()) {
|
|
168
|
+
if (["script-src", "script-src-elem", "default-src"].includes(row.directive)) {
|
|
169
|
+
const host = row.source.match(/^(?:https?:\/\/)?(?:\*\.)?([a-z0-9.-]+)/i)?.[1]?.toLowerCase();
|
|
170
|
+
if (host && knownBypassDomains.some(
|
|
171
|
+
(domain) => host === domain || host.endsWith(`.${domain}`)
|
|
172
|
+
)) {
|
|
173
|
+
findings.push({
|
|
174
|
+
ruleId: "bypass-host",
|
|
175
|
+
severity: "medium",
|
|
176
|
+
directive: row.directive,
|
|
177
|
+
source: row.source,
|
|
178
|
+
ruleSet: row.ruleSet,
|
|
179
|
+
message: "This script host may expose JSONP or script gadgets that weaken host allowlists.",
|
|
180
|
+
fix: "Review the host for JSONP endpoints and script gadgets; prefer nonce or hash authorization."
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (/^http:/i.test(row.source))
|
|
185
|
+
findings.push({
|
|
186
|
+
ruleId: "insecure-scheme",
|
|
187
|
+
severity: "medium",
|
|
188
|
+
directive: row.directive,
|
|
189
|
+
source: row.source,
|
|
190
|
+
ruleSet: row.ruleSet,
|
|
191
|
+
message: "An insecure HTTP source is permitted.",
|
|
192
|
+
fix: "Use HTTPS where possible."
|
|
193
|
+
});
|
|
194
|
+
if (/^(?:https?:\/\/)?\*\.[a-z0-9-]+(?::(?:\*|\d+))?(?:\/|$)/i.test(
|
|
195
|
+
row.source
|
|
196
|
+
) || /^https?:\/\/\*\.(?:amazonaws\.com|azurewebsites\.net)(?:[/:]|$)/i.test(
|
|
197
|
+
row.source
|
|
198
|
+
))
|
|
199
|
+
findings.push({
|
|
200
|
+
ruleId: "broad-wildcard",
|
|
201
|
+
severity: "medium",
|
|
202
|
+
directive: row.directive,
|
|
203
|
+
source: row.source,
|
|
204
|
+
ruleSet: row.ruleSet,
|
|
205
|
+
message: "A wildcard covers an unusually broad or shared domain.",
|
|
206
|
+
fix: "List the specific trusted hosts."
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (!object["report-uri"] && !object["report-to"])
|
|
210
|
+
add(
|
|
211
|
+
"no-reporting",
|
|
212
|
+
"low",
|
|
213
|
+
"No reporting destination is configured.",
|
|
214
|
+
"Configure reporting and its endpoint."
|
|
215
|
+
);
|
|
216
|
+
const today = (options.now ?? /* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
217
|
+
for (const set of policy.config.ruleSets.filter((s) => s.enabled)) {
|
|
218
|
+
if (!set.owner)
|
|
219
|
+
findings.push({
|
|
220
|
+
ruleId: "ruleset-metadata",
|
|
221
|
+
severity: "low",
|
|
222
|
+
ruleSet: set.name,
|
|
223
|
+
message: "Rule set has no owner.",
|
|
224
|
+
fix: "Assign an owner."
|
|
225
|
+
});
|
|
226
|
+
if (set.reviewBy && set.reviewBy < today)
|
|
227
|
+
findings.push({
|
|
228
|
+
ruleId: "ruleset-metadata",
|
|
229
|
+
severity: "low",
|
|
230
|
+
ruleSet: set.name,
|
|
231
|
+
message: "Rule set review date has passed.",
|
|
232
|
+
fix: "Review permissions regularly."
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
for (const rule of options.rules ?? []) findings.push(...rule.check(policy));
|
|
236
|
+
for (const suppression of options.suppressions ?? [])
|
|
237
|
+
if (!suppression.reason.trim() || !suppression.ruleId || !suppression.ruleSet)
|
|
238
|
+
throw new Error(
|
|
239
|
+
"Audit suppressions require a rule id, rule set and reason"
|
|
240
|
+
);
|
|
241
|
+
return findings.filter(
|
|
242
|
+
(finding) => !(options.suppressions ?? []).some(
|
|
243
|
+
(s) => s.ruleId === finding.ruleId && s.ruleSet === finding.ruleSet
|
|
244
|
+
)
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/testing/index.ts
|
|
249
|
+
var cspMatchers = {
|
|
250
|
+
toAllow(policy, directive, url, options) {
|
|
251
|
+
const result = policy.allows(directive, url, options);
|
|
252
|
+
if (result.status === "indeterminate")
|
|
253
|
+
throw new Error(
|
|
254
|
+
`Cannot assert ${directive} ${url}: indeterminate; ${result.reason ?? "decision is indeterminate"}`
|
|
255
|
+
);
|
|
256
|
+
return {
|
|
257
|
+
pass: result.status === "allowed",
|
|
258
|
+
message: () => `Expected ${directive} ${url} ${result.status === "allowed" ? "not " : ""}to be allowed; decision: ${result.status}${result.reason ? ` (${result.reason})` : ""}`
|
|
259
|
+
};
|
|
260
|
+
},
|
|
261
|
+
toBlock(policy, directive, url, options) {
|
|
262
|
+
const result = policy.allows(directive, url, options);
|
|
263
|
+
if (result.status === "indeterminate")
|
|
264
|
+
throw new Error(
|
|
265
|
+
`Cannot assert ${directive} ${url}: indeterminate; ${result.reason ?? "decision is indeterminate"}`
|
|
266
|
+
);
|
|
267
|
+
return {
|
|
268
|
+
pass: result.status === "blocked",
|
|
269
|
+
message: () => `Expected ${directive} ${url} ${result.status === "blocked" ? "not " : ""}to be blocked; decision: ${result.status}${result.reason ? ` (${result.reason})` : ""}`
|
|
270
|
+
};
|
|
271
|
+
},
|
|
272
|
+
toMatchCspSnapshot(policy, expected) {
|
|
273
|
+
const actual = cspSnapshot(policy);
|
|
274
|
+
const pass = this.equals(actual, expected);
|
|
275
|
+
return {
|
|
276
|
+
pass,
|
|
277
|
+
message: () => pass ? "Expected CSP snapshot to differ from the supplied snapshot" : "CSP snapshot differs; review and update the committed snapshot"
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
toPassAudit(policy, options = {}) {
|
|
281
|
+
const ranks = {
|
|
282
|
+
info: 0,
|
|
283
|
+
low: 1,
|
|
284
|
+
medium: 2,
|
|
285
|
+
high: 3
|
|
286
|
+
};
|
|
287
|
+
const threshold = ranks[options.maxSeverity ?? "low"];
|
|
288
|
+
const failing = audit(policy).filter(
|
|
289
|
+
(finding) => ranks[finding.severity] > threshold
|
|
290
|
+
);
|
|
291
|
+
return {
|
|
292
|
+
pass: failing.length === 0,
|
|
293
|
+
message: () => failing.length ? `Expected CSP audit to have no findings above ${options.maxSeverity ?? "low"}: ${failing.map((f) => `${f.ruleId} (${f.severity})`).join(", ")}` : "Expected the CSP audit to exceed the permitted severity"
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
function cspSnapshot(policy) {
|
|
298
|
+
return {
|
|
299
|
+
schemaVersion: 1,
|
|
300
|
+
mode: policy.config.mode,
|
|
301
|
+
directives: policy.toObject(),
|
|
302
|
+
contributors: policy.explain()
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
306
|
+
0 && (module.exports = {
|
|
307
|
+
cspMatchers,
|
|
308
|
+
cspSnapshot
|
|
309
|
+
});
|
|
310
|
+
//# sourceMappingURL=testing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/testing/index.ts","../src/audit/index.ts"],"sourcesContent":["import { audit } from '../audit';\nimport type { Severity } from '../audit';\nimport type { Policy } from '../core';\nimport type { MatchOptions } from '../matching';\n\n/** Matchers can be registered with either Jest's or Vitest's `expect.extend`. */\nexport const cspMatchers = {\n toAllow(\n policy: Policy,\n directive: string,\n url: string,\n options?: MatchOptions,\n ) {\n const result = policy.allows(directive, url, options);\n if (result.status === 'indeterminate')\n throw new Error(\n `Cannot assert ${directive} ${url}: indeterminate; ${result.reason ?? 'decision is indeterminate'}`,\n );\n return {\n pass: result.status === 'allowed',\n message: () =>\n `Expected ${directive} ${url} ${result.status === 'allowed' ? 'not ' : ''}to be allowed; decision: ${result.status}${result.reason ? ` (${result.reason})` : ''}`,\n };\n },\n toBlock(\n policy: Policy,\n directive: string,\n url: string,\n options?: MatchOptions,\n ) {\n const result = policy.allows(directive, url, options);\n if (result.status === 'indeterminate')\n throw new Error(\n `Cannot assert ${directive} ${url}: indeterminate; ${result.reason ?? 'decision is indeterminate'}`,\n );\n return {\n pass: result.status === 'blocked',\n message: () =>\n `Expected ${directive} ${url} ${result.status === 'blocked' ? 'not ' : ''}to be blocked; decision: ${result.status}${result.reason ? ` (${result.reason})` : ''}`,\n };\n },\n toMatchCspSnapshot(\n this: { equals(actual: unknown, expected: unknown): boolean },\n policy: Policy,\n expected: ReturnType<typeof cspSnapshot>,\n ) {\n const actual = cspSnapshot(policy);\n const pass = this.equals(actual, expected);\n return {\n pass,\n message: () =>\n pass\n ? 'Expected CSP snapshot to differ from the supplied snapshot'\n : 'CSP snapshot differs; review and update the committed snapshot',\n };\n },\n toPassAudit(policy: Policy, options: { maxSeverity?: Severity } = {}) {\n const ranks: Record<Severity, number> = {\n info: 0,\n low: 1,\n medium: 2,\n high: 3,\n };\n const threshold = ranks[options.maxSeverity ?? 'low'];\n const failing = audit(policy).filter(\n (finding) => ranks[finding.severity] > threshold,\n );\n return {\n pass: failing.length === 0,\n message: () =>\n failing.length\n ? `Expected CSP audit to have no findings above ${options.maxSeverity ?? 'low'}: ${failing.map((f) => `${f.ruleId} (${f.severity})`).join(', ')}`\n : 'Expected the CSP audit to exceed the permitted severity',\n };\n },\n};\n\n/** Stable, provenance-aware input for a test runner's built-in snapshot matcher. */\nexport function cspSnapshot(policy: Policy): {\n schemaVersion: 1;\n mode: 'enforce' | 'report-only';\n directives: Record<string, string[]>;\n contributors: ReturnType<Policy['explain']>;\n} {\n return {\n schemaVersion: 1,\n mode: policy.config.mode,\n directives: policy.toObject(),\n contributors: policy.explain(),\n };\n}\n","import type { Policy } from '../core';\n\nexport type Severity = 'high' | 'medium' | 'low' | 'info';\nexport interface AuditFinding {\n ruleId: string;\n severity: Severity;\n message: string;\n fix: string;\n directive?: string;\n source?: string;\n ruleSet?: string;\n}\nexport interface AuditRule {\n id: string;\n check(policy: Policy): readonly AuditFinding[];\n}\nexport interface AuditSuppression {\n ruleId: string;\n ruleSet: string;\n reason: string;\n}\nexport interface AuditOptions {\n rules?: readonly AuditRule[];\n suppressions?: readonly AuditSuppression[];\n now?: Date;\n}\n\nconst sourceFindings = (\n policy: Policy,\n directive: string,\n source: string,\n ruleId: string,\n severity: Severity,\n message: string,\n fix: string,\n): AuditFinding[] => {\n const owners = policy\n .explain()\n .filter((row) => row.directive === directive && row.source === source);\n return owners.length\n ? owners.map(({ ruleSet }) => ({\n ruleId,\n severity,\n message,\n fix,\n directive,\n source,\n ruleSet,\n }))\n : [{ ruleId, severity, message, fix, directive, source }];\n};\n\n/** Inspect known dangerous policy patterns. Findings are advisory and do not prove a policy safe. */\nexport function audit(\n policy: Policy,\n options: AuditOptions = {},\n): AuditFinding[] {\n const object = policy.toObject();\n const findings: AuditFinding[] = [];\n const add = (\n id: string,\n severity: Severity,\n message: string,\n fix: string,\n directive?: string,\n ) =>\n findings.push({\n ruleId: id,\n severity,\n message,\n fix,\n ...(directive ? { directive } : {}),\n });\n if (!object['script-src'] && !object['default-src'])\n add(\n 'missing-script-src',\n 'high',\n 'Some script execution is unrestricted.',\n 'Restrict script-src or default-src.',\n 'script-src',\n );\n // script-src-elem falls back to script-src, then default-src. Inspect each explicit list.\n for (const directive of [\n 'script-src',\n 'script-src-elem',\n 'script-src-attr',\n 'default-src',\n ]) {\n const sources = object[directive];\n if (!sources) continue;\n const isFallback =\n directive === 'default-src' && object['script-src'] !== undefined;\n if (isFallback) continue;\n const hasNonceOrHash = sources.some((s) =>\n /^'(nonce-|sha(?:256|384|512)-)/i.test(s),\n );\n for (const source of sources.filter(\n (s) => s.toLowerCase() === \"'unsafe-inline'\" && !hasNonceOrHash,\n ))\n findings.push(\n ...sourceFindings(\n policy,\n directive,\n source,\n 'script-unsafe-inline',\n 'high',\n 'Inline scripts are permitted.',\n 'Use nonces or hashes and remove unsafe-inline.',\n ),\n );\n for (const source of sources.filter(\n (s) => s.toLowerCase() === \"'unsafe-eval'\",\n ))\n findings.push(\n ...sourceFindings(\n policy,\n directive,\n source,\n 'script-unsafe-eval',\n 'high',\n 'Dynamic JavaScript evaluation is permitted.',\n 'Remove unsafe-eval and replace dynamic evaluation.',\n ),\n );\n if (\n directive !== 'script-src-attr' &&\n sources.some((source) => source.toLowerCase() === \"'strict-dynamic'\")\n ) {\n for (const source of sources) {\n if (\n source.toLowerCase() === \"'self'\" ||\n source === '*' ||\n /^[a-z][a-z0-9+.-]*:$/i.test(source) ||\n /^(?:[a-z][a-z0-9+.-]*:\\/\\/)?(?:\\*|[a-z0-9*.-]+)(?::(?:\\*|\\d+))?(?:\\/[^\\s]*)?$/i.test(\n source,\n )\n ) {\n findings.push(\n ...sourceFindings(\n policy,\n directive,\n source,\n 'ignored-by-strict-dynamic',\n 'info',\n 'Modern browsers ignore this source for scripts under strict-dynamic.',\n 'Remove it if legacy browser fallback is not needed.',\n ),\n );\n }\n }\n }\n for (const source of sources)\n if (\n ['*', 'https:', 'http:', 'data:'].includes(source.toLowerCase()) ||\n /^(?:https?:\\/\\/)?\\*(?::(?:\\*|\\d+))?(?:\\/[^\\s]*)?$/i.test(source)\n )\n findings.push(\n ...sourceFindings(\n policy,\n directive,\n source,\n 'script-wildcard',\n 'high',\n 'A broad script source may permit attacker-controlled scripts.',\n 'Restrict script sources and prefer nonces or hashes.',\n ),\n );\n }\n const objects = object['object-src'] ?? object['default-src'];\n if (\n !objects ||\n objects.length !== 1 ||\n objects[0]?.toLowerCase() !== \"'none'\"\n )\n add(\n 'missing-object-src',\n 'high',\n 'Object embedding is not explicitly blocked.',\n \"Set object-src to 'none'.\",\n 'object-src',\n );\n const broad = (sources: string[] | undefined) =>\n !sources ||\n sources.some(\n (source) =>\n source === '*' ||\n /^[a-z][a-z0-9+.-]*:$/i.test(source) ||\n /^(?:https?:\\/\\/)?\\*(?::(?:\\*|\\d+))?(?:\\/[^\\s]*)?$/i.test(source),\n );\n if (broad(object['base-uri']))\n add(\n 'missing-base-uri',\n 'medium',\n 'The document base URL is not sufficiently restricted.',\n \"Set base-uri to 'none' or 'self'.\",\n 'base-uri',\n );\n if (broad(object['frame-ancestors']))\n add(\n 'missing-frame-ancestors',\n 'medium',\n 'Embedding by other sites is not sufficiently restricted.',\n 'Restrict frame-ancestors to trusted origins.',\n 'frame-ancestors',\n );\n // Small advisory subset informed by Google CSP Evaluator; maintain and review this data.\n // https://github.com/google/csp-evaluator/tree/master/allowlist_bypasses\n const knownBypassDomains = [\n 'google.com',\n 'googleapis.com',\n 'googleusercontent.com',\n 'gstatic.com',\n ];\n for (const row of policy.explain()) {\n if (\n ['script-src', 'script-src-elem', 'default-src'].includes(row.directive)\n ) {\n const host = row.source\n .match(/^(?:https?:\\/\\/)?(?:\\*\\.)?([a-z0-9.-]+)/i)?.[1]\n ?.toLowerCase();\n if (\n host &&\n knownBypassDomains.some(\n (domain) => host === domain || host.endsWith(`.${domain}`),\n )\n ) {\n findings.push({\n ruleId: 'bypass-host',\n severity: 'medium',\n directive: row.directive,\n source: row.source,\n ruleSet: row.ruleSet,\n message:\n 'This script host may expose JSONP or script gadgets that weaken host allowlists.',\n fix: 'Review the host for JSONP endpoints and script gadgets; prefer nonce or hash authorization.',\n });\n }\n }\n if (/^http:/i.test(row.source))\n findings.push({\n ruleId: 'insecure-scheme',\n severity: 'medium',\n directive: row.directive,\n source: row.source,\n ruleSet: row.ruleSet,\n message: 'An insecure HTTP source is permitted.',\n fix: 'Use HTTPS where possible.',\n });\n if (\n /^(?:https?:\\/\\/)?\\*\\.[a-z0-9-]+(?::(?:\\*|\\d+))?(?:\\/|$)/i.test(\n row.source,\n ) ||\n /^https?:\\/\\/\\*\\.(?:amazonaws\\.com|azurewebsites\\.net)(?:[/:]|$)/i.test(\n row.source,\n )\n )\n findings.push({\n ruleId: 'broad-wildcard',\n severity: 'medium',\n directive: row.directive,\n source: row.source,\n ruleSet: row.ruleSet,\n message: 'A wildcard covers an unusually broad or shared domain.',\n fix: 'List the specific trusted hosts.',\n });\n }\n if (!object['report-uri'] && !object['report-to'])\n add(\n 'no-reporting',\n 'low',\n 'No reporting destination is configured.',\n 'Configure reporting and its endpoint.',\n );\n const today = (options.now ?? new Date()).toISOString().slice(0, 10);\n for (const set of policy.config.ruleSets.filter((s) => s.enabled)) {\n if (!set.owner)\n findings.push({\n ruleId: 'ruleset-metadata',\n severity: 'low',\n ruleSet: set.name,\n message: 'Rule set has no owner.',\n fix: 'Assign an owner.',\n });\n if (set.reviewBy && set.reviewBy < today)\n findings.push({\n ruleId: 'ruleset-metadata',\n severity: 'low',\n ruleSet: set.name,\n message: 'Rule set review date has passed.',\n fix: 'Review permissions regularly.',\n });\n }\n for (const rule of options.rules ?? []) findings.push(...rule.check(policy));\n for (const suppression of options.suppressions ?? [])\n if (\n !suppression.reason.trim() ||\n !suppression.ruleId ||\n !suppression.ruleSet\n )\n throw new Error(\n 'Audit suppressions require a rule id, rule set and reason',\n );\n return findings.filter(\n (finding) =>\n !(options.suppressions ?? []).some(\n (s) => s.ruleId === finding.ruleId && s.ruleSet === finding.ruleSet,\n ),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2BA,IAAM,iBAAiB,CACrB,QACA,WACA,QACA,QACA,UACA,SACA,QACmB;AACnB,QAAM,SAAS,OACZ,QAAQ,EACR,OA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,YAAY,QAK1B;AACA,SAAO;AAAA,IACL,eAAe;AAAA,IACf,MAAM,OAAO,OAAO;AAAA,IACpB,YAAY,OAAO,SAAS;AAAA,IAC5B,cAAc,OAAO,QAAQ;AAAA,EAC/B;AACF;","names":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { P as Policy, M as MatchOptions, S as Severity } from './index-D6PmUWjD.cjs';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
/** Matchers can be registered with either Jest's or Vitest's `expect.extend`. */
|
|
5
|
+
declare const cspMatchers: {
|
|
6
|
+
toAllow(policy: Policy, directive: string, url: string, options?: MatchOptions): {
|
|
7
|
+
pass: boolean;
|
|
8
|
+
message: () => string;
|
|
9
|
+
};
|
|
10
|
+
toBlock(policy: Policy, directive: string, url: string, options?: MatchOptions): {
|
|
11
|
+
pass: boolean;
|
|
12
|
+
message: () => string;
|
|
13
|
+
};
|
|
14
|
+
toMatchCspSnapshot(this: {
|
|
15
|
+
equals(actual: unknown, expected: unknown): boolean;
|
|
16
|
+
}, policy: Policy, expected: ReturnType<typeof cspSnapshot>): {
|
|
17
|
+
pass: boolean;
|
|
18
|
+
message: () => "Expected CSP snapshot to differ from the supplied snapshot" | "CSP snapshot differs; review and update the committed snapshot";
|
|
19
|
+
};
|
|
20
|
+
toPassAudit(policy: Policy, options?: {
|
|
21
|
+
maxSeverity?: Severity;
|
|
22
|
+
}): {
|
|
23
|
+
pass: boolean;
|
|
24
|
+
message: () => string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/** Stable, provenance-aware input for a test runner's built-in snapshot matcher. */
|
|
28
|
+
declare function cspSnapshot(policy: Policy): {
|
|
29
|
+
schemaVersion: 1;
|
|
30
|
+
mode: 'enforce' | 'report-only';
|
|
31
|
+
directives: Record<string, string[]>;
|
|
32
|
+
contributors: ReturnType<Policy['explain']>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { cspMatchers, cspSnapshot };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { P as Policy, M as MatchOptions, S as Severity } from './index-D6PmUWjD.js';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
/** Matchers can be registered with either Jest's or Vitest's `expect.extend`. */
|
|
5
|
+
declare const cspMatchers: {
|
|
6
|
+
toAllow(policy: Policy, directive: string, url: string, options?: MatchOptions): {
|
|
7
|
+
pass: boolean;
|
|
8
|
+
message: () => string;
|
|
9
|
+
};
|
|
10
|
+
toBlock(policy: Policy, directive: string, url: string, options?: MatchOptions): {
|
|
11
|
+
pass: boolean;
|
|
12
|
+
message: () => string;
|
|
13
|
+
};
|
|
14
|
+
toMatchCspSnapshot(this: {
|
|
15
|
+
equals(actual: unknown, expected: unknown): boolean;
|
|
16
|
+
}, policy: Policy, expected: ReturnType<typeof cspSnapshot>): {
|
|
17
|
+
pass: boolean;
|
|
18
|
+
message: () => "Expected CSP snapshot to differ from the supplied snapshot" | "CSP snapshot differs; review and update the committed snapshot";
|
|
19
|
+
};
|
|
20
|
+
toPassAudit(policy: Policy, options?: {
|
|
21
|
+
maxSeverity?: Severity;
|
|
22
|
+
}): {
|
|
23
|
+
pass: boolean;
|
|
24
|
+
message: () => string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/** Stable, provenance-aware input for a test runner's built-in snapshot matcher. */
|
|
28
|
+
declare function cspSnapshot(policy: Policy): {
|
|
29
|
+
schemaVersion: 1;
|
|
30
|
+
mode: 'enforce' | 'report-only';
|
|
31
|
+
directives: Record<string, string[]>;
|
|
32
|
+
contributors: ReturnType<Policy['explain']>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { cspMatchers, cspSnapshot };
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,93 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jamesbrightman/pretty-csp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Readable, testable Content Security Policies",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"packageManager": "pnpm@10.17.1",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md",
|
|
14
|
+
"CHANGELOG.md",
|
|
15
|
+
"CHANGELOG.md",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"website/static/img/*.svg"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist/index.cjs",
|
|
20
|
+
"module": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/index.d.cts",
|
|
30
|
+
"default": "./dist/index.cjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"./testing": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/testing.d.ts",
|
|
36
|
+
"default": "./dist/testing.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/testing.d.cts",
|
|
40
|
+
"default": "./dist/testing.cjs"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"docs:dev": "pnpm build && docusaurus start website --host 127.0.0.1 --no-open",
|
|
47
|
+
"docs:build": "pnpm build && docusaurus build website",
|
|
48
|
+
"docs:preview": "pnpm build && docusaurus serve website --build",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"lint": "eslint .",
|
|
51
|
+
"format:check": "prettier --check .",
|
|
52
|
+
"format": "prettier --write .",
|
|
53
|
+
"test": "vitest run --passWithNoTests",
|
|
54
|
+
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
55
|
+
"changeset": "changeset",
|
|
56
|
+
"release": "npm publish --provenance --access public",
|
|
57
|
+
"prepublishOnly": "pnpm format:check && pnpm lint && pnpm typecheck && pnpm test:coverage && pnpm build"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"jiti": "^2.7.0",
|
|
61
|
+
"tldts": "7.6.4",
|
|
62
|
+
"zod": "^4.0.0"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@changesets/cli": "^2.29.0",
|
|
66
|
+
"@docusaurus/core": "3.10.2",
|
|
67
|
+
"@docusaurus/preset-classic": "3.10.2",
|
|
68
|
+
"@easyops-cn/docusaurus-search-local": "0.55.3",
|
|
69
|
+
"@eslint/js": "^9.0.0",
|
|
70
|
+
"@mdx-js/react": "3.1.1",
|
|
71
|
+
"@types/node": "^20.0.0",
|
|
72
|
+
"@vitest/coverage-v8": "^3.0.0",
|
|
73
|
+
"eslint": "^9.0.0",
|
|
74
|
+
"prettier": "^3.0.0",
|
|
75
|
+
"react": "18.3.1",
|
|
76
|
+
"react-dom": "18.3.1",
|
|
77
|
+
"tsup": "^8.0.0",
|
|
78
|
+
"typescript": "^5.0.0",
|
|
79
|
+
"typescript-eslint": "^8.0.0",
|
|
80
|
+
"vitest": "^3.0.0"
|
|
81
|
+
},
|
|
82
|
+
"bin": {
|
|
83
|
+
"pretty-csp": "./dist/cli.js"
|
|
84
|
+
},
|
|
85
|
+
"repository": {
|
|
86
|
+
"type": "git",
|
|
87
|
+
"url": "https://github.com/JamesBrightman/pretty-csp.git"
|
|
88
|
+
},
|
|
89
|
+
"homepage": "https://jamesbrightman.github.io/pretty-csp/",
|
|
90
|
+
"bugs": {
|
|
91
|
+
"url": "https://github.com/JamesBrightman/pretty-csp/issues"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 470" role="img" aria-labelledby="title desc">
|
|
2
|
+
<title id="title">How pretty-csp works</title>
|
|
3
|
+
<desc id="desc">Start with a base policy, add named rule sets, then review the resulting Content Security Policy header and audit findings.</desc>
|
|
4
|
+
<rect width="1200" height="470" rx="24" fill="#F5E8C8"/>
|
|
5
|
+
<text x="600" y="68" text-anchor="middle" fill="#941F2B" font-family="Lobster, Pacifico, 'Brush Script MT', cursive" font-size="48" font-style="italic">From building blocks to a policy you can review</text>
|
|
6
|
+
<g font-family="Arial, sans-serif" text-anchor="middle">
|
|
7
|
+
<rect x="42" y="132" width="270" height="230" rx="18" fill="#FFF9EA" stroke="#D8B765" stroke-width="3"/>
|
|
8
|
+
<text x="177" y="184" fill="#78313A" font-size="25" font-weight="700">BASE POLICY</text>
|
|
9
|
+
<text x="177" y="228" fill="#3A302D" font-size="18">Set safe defaults</text>
|
|
10
|
+
<text x="177" y="258" fill="#3A302D" font-size="18">and core directives</text>
|
|
11
|
+
<text x="177" y="319" fill="#941F2B" font-family="monospace" font-size="17">default-src 'self'</text>
|
|
12
|
+
|
|
13
|
+
<rect x="350" y="132" width="270" height="230" rx="18" fill="#FFF9EA" stroke="#D8B765" stroke-width="3"/>
|
|
14
|
+
<text x="485" y="184" fill="#78313A" font-size="25" font-weight="700">NAMED RULE SETS</text>
|
|
15
|
+
<text x="485" y="228" fill="#3A302D" font-size="18">Group permissions</text>
|
|
16
|
+
<text x="485" y="258" fill="#3A302D" font-size="18">by purpose and owner</text>
|
|
17
|
+
<text x="485" y="319" fill="#941F2B" font-family="monospace" font-size="17">Images CDN · web team</text>
|
|
18
|
+
|
|
19
|
+
<rect x="658" y="132" width="220" height="230" rx="18" fill="#941F2B"/>
|
|
20
|
+
<text x="768" y="205" fill="#F5E8C8" font-family="Lobster, Pacifico, 'Brush Script MT', cursive" font-size="42" font-style="italic">pretty-csp</text>
|
|
21
|
+
<text x="768" y="250" fill="#FFF9EA" font-size="18" font-weight="700">MERGE & EXPLAIN</text>
|
|
22
|
+
<text x="768" y="294" fill="#FFF9EA" font-size="17">Build · diff · audit</text>
|
|
23
|
+
|
|
24
|
+
<rect x="916" y="132" width="242" height="230" rx="18" fill="#FFF9EA" stroke="#D8B765" stroke-width="3"/>
|
|
25
|
+
<text x="1037" y="184" fill="#78313A" font-size="25" font-weight="700">REVIEW OUTPUT</text>
|
|
26
|
+
<text x="1037" y="228" fill="#3A302D" font-size="18">Header string, readable</text>
|
|
27
|
+
<text x="1037" y="258" fill="#3A302D" font-size="18">explanation and findings</text>
|
|
28
|
+
<text x="1037" y="319" fill="#941F2B" font-family="monospace" font-size="17">policy.explain() · audit()</text>
|
|
29
|
+
</g>
|
|
30
|
+
<g fill="none" stroke="#941F2B" stroke-width="7" stroke-linecap="round" stroke-linejoin="round">
|
|
31
|
+
<path d="M315 247h27m-10-11 11 11-11 11"/><path d="M623 247h27m-10-11 11 11-11 11"/><path d="M881 247h27m-10-11 11 11-11 11"/>
|
|
32
|
+
</g>
|
|
33
|
+
<text x="600" y="425" text-anchor="middle" fill="#78313A" font-family="Arial, sans-serif" font-size="16" letter-spacing="1">The app still owns response headers, nonce propagation and reporting endpoints.</text>
|
|
34
|
+
</svg>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
|
2
|
+
<title>pretty-csp</title>
|
|
3
|
+
<rect width="32" height="32" rx="6" fill="#991F2D"/>
|
|
4
|
+
<path fill="#F5E8C8" d="M10.67 6H14.69L14.25 8.1Q15.64 6.89 17.52 6.89Q19.08 6.89 20.01 7.93Q20.93 8.96 20.93 11.31Q20.93 13.52 20.28 15.77Q19.64 18.02 18.1 19.6Q16.57 21.18 14.05 21.18Q12.26 21.18 11.67 20.17L10.22 26.99L6 28ZM17.1 11.23Q17.1 8.91 15.7 8.91Q15.2 8.91 14.68 9.27Q14.16 9.63 13.77 10.28L12.12 18.1Q12.35 18.75 13.18 18.75Q14.53 18.75 15.41 17.49Q16.29 16.23 16.69 14.48Q17.1 12.74 17.1 11.23Z"/>
|
|
5
|
+
<path fill="#F5E8C8" d="m25 3.4 1.1 2.4 2.6.3-1.9 1.8.5 2.6L25 9.2l-2.3 1.3.5-2.6-1.9-1.8 2.6-.3Z"/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 430" role="img" aria-labelledby="title desc">
|
|
2
|
+
<title id="title">pretty-csp</title>
|
|
3
|
+
<desc id="desc">A retro Americana wordmark in scarlet brush script on a warm cream background, framed by stars.</desc>
|
|
4
|
+
<rect width="1200" height="430" rx="28" fill="#F4E6C3"/>
|
|
5
|
+
<rect x="14" y="14" width="1172" height="402" rx="20" fill="none" stroke="#D8B765" stroke-width="3"/>
|
|
6
|
+
<path d="m105 50 8 18 19 1-15 12 5 19-17-11-16 11 5-19-15-12 19-1zM1090 50l8 18 19 1-15 12 5 19-17-11-16 11 5-19-15-12 19-1z" fill="#941F2B"/>
|
|
7
|
+
<text x="152" y="108" fill="#78313A" font-family="Arial, sans-serif" font-size="22" font-weight="700" letter-spacing="7">A FRIENDLIER LOOK AT</text>
|
|
8
|
+
<text x="46" y="293" fill="#8F1724" font-family="Lobster, Pacifico, 'Brush Script MT', cursive" font-size="208" font-style="italic" font-weight="700" letter-spacing="-8">pretty</text>
|
|
9
|
+
<text x="743" y="276" fill="#78313A" font-family="Georgia, serif" font-size="132" font-weight="700" letter-spacing="-4">CSP</text>
|
|
10
|
+
<path d="M70 334 C230 375 442 376 644 350 C793 331 941 299 1124 298 C1001 345 857 382 675 393 C423 408 202 389 70 334Z" fill="#8F1724"/>
|
|
11
|
+
<text x="752" y="352" fill="#F4E6C3" font-family="Arial, sans-serif" font-size="18" font-weight="700" letter-spacing="3">POLICY TOOLKIT</text>
|
|
12
|
+
</svg>
|