@hoajs/secure-headers 0.1.0 → 0.1.1

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 CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.1.1 / 2026-02-11
2
+
3
+ - refactor: use tsdown instead of tsup
4
+ - chore(deps): update deps
5
+
1
6
  ## v0.1.0 / 2025-10-29
2
7
 
3
8
  - init
@@ -0,0 +1,571 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ let hoa = require("hoa");
3
+
4
+ //#region src/contentSecurityPolicy.ts
5
+ const dangerouslyDisableDefaultSrc = Symbol("dangerouslyDisableDefaultSrc");
6
+ const SHOULD_BE_QUOTED = new Set([
7
+ "none",
8
+ "self",
9
+ "strict-dynamic",
10
+ "report-sample",
11
+ "inline-speculation-rules",
12
+ "unsafe-inline",
13
+ "unsafe-eval",
14
+ "unsafe-hashes",
15
+ "wasm-unsafe-eval"
16
+ ]);
17
+ const getDefaultDirectives = () => ({
18
+ "default-src": ["'self'"],
19
+ "base-uri": ["'self'"],
20
+ "font-src": [
21
+ "'self'",
22
+ "https:",
23
+ "data:"
24
+ ],
25
+ "form-action": ["'self'"],
26
+ "frame-ancestors": ["'self'"],
27
+ "img-src": ["'self'", "data:"],
28
+ "object-src": ["'none'"],
29
+ "script-src": ["'self'"],
30
+ "script-src-attr": ["'none'"],
31
+ "style-src": [
32
+ "'self'",
33
+ "https:",
34
+ "'unsafe-inline'"
35
+ ],
36
+ "upgrade-insecure-requests": []
37
+ });
38
+ const dashify$1 = (str) => str.replace(/[A-Z]/g, (capitalLetter) => "-" + capitalLetter.toLowerCase());
39
+ const assertDirectiveValueIsValid = (directiveName, directiveValue) => {
40
+ if (/;|,/.test(directiveValue)) throw new Error(`Content-Security-Policy received an invalid directive value for ${JSON.stringify(directiveName)}`);
41
+ };
42
+ const assertDirectiveValueEntryIsValid = (directiveName, directiveValueEntry) => {
43
+ if (SHOULD_BE_QUOTED.has(directiveValueEntry) || directiveValueEntry.startsWith("nonce-") || directiveValueEntry.startsWith("sha256-") || directiveValueEntry.startsWith("sha384-") || directiveValueEntry.startsWith("sha512-")) throw new Error(`Content-Security-Policy received an invalid directive value for ${JSON.stringify(directiveName)}. ${JSON.stringify(directiveValueEntry)} should be quoted`);
44
+ };
45
+ function normalizeDirectives$1(options) {
46
+ const defaultDirectives = getDefaultDirectives();
47
+ const { useDefaults = true, directives: rawDirectives = defaultDirectives } = options;
48
+ const result = /* @__PURE__ */ new Map();
49
+ const directiveNamesSeen = /* @__PURE__ */ new Set();
50
+ const directivesExplicitlyDisabled = /* @__PURE__ */ new Set();
51
+ for (const rawDirectiveName in rawDirectives) {
52
+ if (!Object.hasOwn(rawDirectives, rawDirectiveName)) continue;
53
+ if (rawDirectiveName.length === 0 || /[^a-zA-Z0-9-]/.test(rawDirectiveName)) throw new Error(`Content-Security-Policy received an invalid directive name ${JSON.stringify(rawDirectiveName)}`);
54
+ const directiveName = dashify$1(rawDirectiveName);
55
+ if (directiveNamesSeen.has(directiveName)) throw new Error(`Content-Security-Policy received a duplicate directive ${JSON.stringify(directiveName)}`);
56
+ directiveNamesSeen.add(directiveName);
57
+ const rawDirectiveValue = rawDirectives[rawDirectiveName];
58
+ let directiveValue;
59
+ if (rawDirectiveValue === null) {
60
+ if (directiveName === "default-src") throw new Error("Content-Security-Policy needs a default-src but it was set to `null`. If you really want to disable it, set it to `contentSecurityPolicy.dangerouslyDisableDefaultSrc`.");
61
+ directivesExplicitlyDisabled.add(directiveName);
62
+ continue;
63
+ } else if (typeof rawDirectiveValue === "string") directiveValue = [rawDirectiveValue];
64
+ else if (!rawDirectiveValue) throw new Error(`Content-Security-Policy received an invalid directive value for ${JSON.stringify(directiveName)}`);
65
+ else if (rawDirectiveValue === dangerouslyDisableDefaultSrc) if (directiveName === "default-src") {
66
+ directivesExplicitlyDisabled.add("default-src");
67
+ continue;
68
+ } else throw new Error(`Content-Security-Policy: tried to disable ${JSON.stringify(directiveName)} as if it were default-src; simply omit the key`);
69
+ else directiveValue = rawDirectiveValue;
70
+ for (const element of directiveValue) {
71
+ if (typeof element !== "string") continue;
72
+ assertDirectiveValueIsValid(directiveName, element);
73
+ assertDirectiveValueEntryIsValid(directiveName, element);
74
+ }
75
+ result.set(directiveName, directiveValue);
76
+ }
77
+ if (useDefaults) Object.entries(defaultDirectives).forEach(([defaultDirectiveName, defaultDirectiveValue]) => {
78
+ if (!result.has(defaultDirectiveName) && !directivesExplicitlyDisabled.has(defaultDirectiveName)) result.set(defaultDirectiveName, defaultDirectiveValue);
79
+ });
80
+ if (!result.size) throw new Error("Content-Security-Policy has no directives. Either set some or disable the header");
81
+ if (!result.has("default-src") && !directivesExplicitlyDisabled.has("default-src")) throw new Error("Content-Security-Policy needs a default-src but none was provided. If you really want to disable it, set it to `contentSecurityPolicy.dangerouslyDisableDefaultSrc`.");
82
+ return result;
83
+ }
84
+ function getHeaderValue$1(ctx, normalizedDirectives) {
85
+ const result = [];
86
+ for (const [directiveName, rawDirectiveValue] of normalizedDirectives) {
87
+ let directiveValue = "";
88
+ for (const element of rawDirectiveValue) if (typeof element === "function") {
89
+ const newElement = element(ctx);
90
+ assertDirectiveValueEntryIsValid(directiveName, newElement);
91
+ directiveValue += " " + newElement;
92
+ } else directiveValue += " " + element;
93
+ if (directiveValue) {
94
+ assertDirectiveValueIsValid(directiveName, directiveValue);
95
+ result.push(`${directiveName}${directiveValue}`);
96
+ } else result.push(directiveName);
97
+ }
98
+ return result.join(";");
99
+ }
100
+ const contentSecurityPolicy = function contentSecurityPolicy(options = {}) {
101
+ const headerName = options.reportOnly ? "Content-Security-Policy-Report-Only" : "Content-Security-Policy";
102
+ const normalizedDirectives = normalizeDirectives$1(options);
103
+ return async function contentSecurityPolicyMiddleware(ctx, next) {
104
+ const result = getHeaderValue$1(ctx, normalizedDirectives);
105
+ ctx.res.set(headerName, result);
106
+ await next();
107
+ };
108
+ };
109
+ contentSecurityPolicy.getDefaultDirectives = getDefaultDirectives;
110
+ contentSecurityPolicy.dangerouslyDisableDefaultSrc = dangerouslyDisableDefaultSrc;
111
+
112
+ //#endregion
113
+ //#region src/crossOriginEmbedderPolicy.ts
114
+ const ALLOWED_POLICIES$2 = new Set([
115
+ "require-corp",
116
+ "credentialless",
117
+ "unsafe-none"
118
+ ]);
119
+ function getHeaderValueFromOptions$6({ policy = "require-corp" }) {
120
+ if (ALLOWED_POLICIES$2.has(policy)) return policy;
121
+ else throw new Error(`Cross-Origin-Embedder-Policy does not support the ${JSON.stringify(policy)} policy`);
122
+ }
123
+ function crossOriginEmbedderPolicy(options = {}) {
124
+ const headerValue = getHeaderValueFromOptions$6(options);
125
+ return async function crossOriginEmbedderPolicyMiddleware(ctx, next) {
126
+ ctx.res.set("Cross-Origin-Embedder-Policy", headerValue);
127
+ await next();
128
+ };
129
+ }
130
+
131
+ //#endregion
132
+ //#region src/crossOriginOpenerPolicy.ts
133
+ const ALLOWED_POLICIES$1 = new Set([
134
+ "same-origin",
135
+ "same-origin-allow-popups",
136
+ "unsafe-none"
137
+ ]);
138
+ function getHeaderValueFromOptions$5({ policy = "same-origin" }) {
139
+ if (ALLOWED_POLICIES$1.has(policy)) return policy;
140
+ else throw new Error(`Cross-Origin-Opener-Policy does not support the ${JSON.stringify(policy)} policy`);
141
+ }
142
+ function crossOriginOpenerPolicy(options = {}) {
143
+ const headerValue = getHeaderValueFromOptions$5(options);
144
+ return async function crossOriginOpenerPolicyMiddleware(ctx, next) {
145
+ ctx.res.set("Cross-Origin-Opener-Policy", headerValue);
146
+ await next();
147
+ };
148
+ }
149
+
150
+ //#endregion
151
+ //#region src/crossOriginResourcePolicy.ts
152
+ const ALLOWED_POLICIES = new Set([
153
+ "same-origin",
154
+ "same-site",
155
+ "cross-origin"
156
+ ]);
157
+ function getHeaderValueFromOptions$4({ policy = "same-origin" }) {
158
+ if (ALLOWED_POLICIES.has(policy)) return policy;
159
+ else throw new Error(`Cross-Origin-Resource-Policy does not support the ${JSON.stringify(policy)} policy`);
160
+ }
161
+ function crossOriginResourcePolicy(options = {}) {
162
+ const headerValue = getHeaderValueFromOptions$4(options);
163
+ return async function crossOriginResourcePolicyMiddleware(ctx, next) {
164
+ ctx.res.set("Cross-Origin-Resource-Policy", headerValue);
165
+ await next();
166
+ };
167
+ }
168
+
169
+ //#endregion
170
+ //#region src/originAgentCluster.ts
171
+ function originAgentCluster() {
172
+ return async function originAgentClusterMiddleware(ctx, next) {
173
+ ctx.res.set("Origin-Agent-Cluster", "?1");
174
+ await next();
175
+ };
176
+ }
177
+
178
+ //#endregion
179
+ //#region src/referrerPolicy.ts
180
+ const ALLOWED_TOKENS = new Set([
181
+ "no-referrer",
182
+ "no-referrer-when-downgrade",
183
+ "same-origin",
184
+ "origin",
185
+ "strict-origin",
186
+ "origin-when-cross-origin",
187
+ "strict-origin-when-cross-origin",
188
+ "unsafe-url",
189
+ ""
190
+ ]);
191
+ function getHeaderValueFromOptions$3({ policy = ["no-referrer"] }) {
192
+ const tokens = typeof policy === "string" ? [policy] : policy;
193
+ if (tokens.length === 0) throw new Error("Referrer-Policy received no policy tokens");
194
+ const tokensSeen = /* @__PURE__ */ new Set();
195
+ tokens.forEach((token) => {
196
+ if (!ALLOWED_TOKENS.has(token)) throw new Error(`Referrer-Policy received an unexpected policy token ${JSON.stringify(token)}`);
197
+ else if (tokensSeen.has(token)) throw new Error(`Referrer-Policy received a duplicate policy token ${JSON.stringify(token)}`);
198
+ tokensSeen.add(token);
199
+ });
200
+ return tokens.join(",");
201
+ }
202
+ function referrerPolicy(options = {}) {
203
+ const headerValue = getHeaderValueFromOptions$3(options);
204
+ return async function referrerPolicyMiddleware(ctx, next) {
205
+ ctx.res.set("Referrer-Policy", headerValue);
206
+ await next();
207
+ };
208
+ }
209
+
210
+ //#endregion
211
+ //#region src/strictTransportSecurity.ts
212
+ const DEFAULT_MAX_AGE = 365 * 24 * 60 * 60;
213
+ function parseMaxAge(value = DEFAULT_MAX_AGE) {
214
+ if (value >= 0 && Number.isFinite(value)) return Math.floor(value);
215
+ else throw new Error(`Strict-Transport-Security: ${JSON.stringify(value)} is not a valid value for maxAge. Please choose a positive integer.`);
216
+ }
217
+ function getHeaderValueFromOptions$2(options) {
218
+ if ("maxage" in options) throw new Error("Strict-Transport-Security received an unsupported property, `maxage`. Did you mean to pass `maxAge`?");
219
+ if ("includeSubdomains" in options) throw new Error("Strict-Transport-Security middleware should use `includeSubDomains` instead of `includeSubdomains`. (The correct one has an uppercase \"D\".)");
220
+ const directives = [`max-age=${parseMaxAge(options.maxAge)}`];
221
+ if (options.includeSubDomains === void 0 || options.includeSubDomains) directives.push("includeSubDomains");
222
+ if (options.preload) directives.push("preload");
223
+ return directives.join("; ");
224
+ }
225
+ function strictTransportSecurity(options = {}) {
226
+ const headerValue = getHeaderValueFromOptions$2(options);
227
+ return async function strictTransportSecurityMiddleware(ctx, next) {
228
+ ctx.res.set("Strict-Transport-Security", headerValue);
229
+ await next();
230
+ };
231
+ }
232
+
233
+ //#endregion
234
+ //#region src/xContentTypeOptions.ts
235
+ function xContentTypeOptions() {
236
+ return async function xContentTypeOptionsMiddleware(ctx, next) {
237
+ ctx.res.set("X-Content-Type-Options", "nosniff");
238
+ await next();
239
+ };
240
+ }
241
+
242
+ //#endregion
243
+ //#region src/xDnsPrefetchControl.ts
244
+ function xDnsPrefetchControl(options = {}) {
245
+ const headerValue = options.allow ? "on" : "off";
246
+ return async function xDnsPrefetchControlMiddleware(ctx, next) {
247
+ ctx.res.set("X-DNS-Prefetch-Control", headerValue);
248
+ await next();
249
+ };
250
+ }
251
+
252
+ //#endregion
253
+ //#region src/xDownloadOptions.ts
254
+ function xDownloadOptions() {
255
+ return async function xDownloadOptionsMiddleware(ctx, next) {
256
+ ctx.res.set("X-Download-Options", "noopen");
257
+ await next();
258
+ };
259
+ }
260
+
261
+ //#endregion
262
+ //#region src/xFrameOptions.ts
263
+ function getHeaderValueFromOptions$1({ action = "sameorigin" }) {
264
+ const normalizedAction = typeof action === "string" ? action.toUpperCase() : action;
265
+ switch (normalizedAction) {
266
+ case "SAME-ORIGIN": return "SAMEORIGIN";
267
+ case "DENY":
268
+ case "SAMEORIGIN": return normalizedAction;
269
+ default: throw new Error(`X-Frame-Options received an invalid action ${JSON.stringify(action)}`);
270
+ }
271
+ }
272
+ function xFrameOptions(options = {}) {
273
+ const headerValue = getHeaderValueFromOptions$1(options);
274
+ return async function xFrameOptionsMiddleware(ctx, next) {
275
+ ctx.res.set("X-Frame-Options", headerValue);
276
+ await next();
277
+ };
278
+ }
279
+
280
+ //#endregion
281
+ //#region src/xPermittedCrossDomainPolicies.ts
282
+ const ALLOWED_PERMITTED_POLICIES = new Set([
283
+ "none",
284
+ "master-only",
285
+ "by-content-type",
286
+ "all"
287
+ ]);
288
+ function getHeaderValueFromOptions({ permittedPolicies = "none" }) {
289
+ if (ALLOWED_PERMITTED_POLICIES.has(permittedPolicies)) return permittedPolicies;
290
+ else throw new Error(`X-Permitted-Cross-Domain-Policies does not support ${JSON.stringify(permittedPolicies)}`);
291
+ }
292
+ function xPermittedCrossDomainPolicies(options = {}) {
293
+ const headerValue = getHeaderValueFromOptions(options);
294
+ return async function xPermittedCrossDomainPoliciesMiddleware(ctx, next) {
295
+ ctx.res.set("X-Permitted-Cross-Domain-Policies", headerValue);
296
+ await next();
297
+ };
298
+ }
299
+
300
+ //#endregion
301
+ //#region src/xXssProtection.ts
302
+ function xXssProtection() {
303
+ return async function xXssProtectionMiddleware(ctx, next) {
304
+ ctx.res.set("X-XSS-Protection", "0");
305
+ await next();
306
+ };
307
+ }
308
+
309
+ //#endregion
310
+ //#region src/permissionPolicy.ts
311
+ function dashify(str) {
312
+ return str.replace(/([a-z\d])([A-Z])/g, "$1-$2").toLowerCase();
313
+ }
314
+ const SHOULD_NOT_BE_QUOTED = new Set([
315
+ "*",
316
+ "none",
317
+ "self",
318
+ "src"
319
+ ]);
320
+ function normalizeDirectives(options) {
321
+ const directiveNamesSeen = /* @__PURE__ */ new Set();
322
+ const result = {};
323
+ for (const rawDirectiveName in options) {
324
+ const directiveName = dashify(rawDirectiveName);
325
+ if (directiveNamesSeen.has(directiveName)) throw new Error(`Permission-Policy received a duplicate directive ${JSON.stringify(directiveName)}`);
326
+ directiveNamesSeen.add(directiveName);
327
+ const rawDirectiveValue = options[rawDirectiveName];
328
+ if (typeof rawDirectiveValue === "boolean") result[directiveName] = rawDirectiveValue ? "(*)" : "()";
329
+ else if (Array.isArray(rawDirectiveValue)) if (rawDirectiveValue.length === 0) result[directiveName] = "()";
330
+ else if (rawDirectiveValue.length === 1 && (rawDirectiveValue[0] === "*" || rawDirectiveValue[0] === "none")) result[directiveName] = `(${rawDirectiveValue[0]})`;
331
+ else result[directiveName] = `(${rawDirectiveValue.map((v) => SHOULD_NOT_BE_QUOTED.has(v) ? v : `"${v}"`).join(" ")})`;
332
+ else throw new Error(`Permission-Policy received an invalid directive value for ${JSON.stringify(directiveName)}. ${JSON.stringify(rawDirectiveValue)} should be a boolean or an array of strings.`);
333
+ }
334
+ if (Object.keys(result).length === 0) throw new Error("Permission-Policy has no directives. Either set some or disable the header");
335
+ return result;
336
+ }
337
+ function getHeaderValue(normalizedDirectives) {
338
+ return Object.entries(normalizedDirectives).map(([k, v]) => `${k}=${v}`).join(", ");
339
+ }
340
+ function permissionPolicy(options = {}) {
341
+ const headerValue = getHeaderValue(normalizeDirectives(options));
342
+ return async function permissionPolicyMiddleware(ctx, next) {
343
+ ctx.res.set("Permissions-Policy", headerValue);
344
+ await next();
345
+ };
346
+ }
347
+
348
+ //#endregion
349
+ //#region src/index.ts
350
+ function getMiddlewareFunctionsFromOptions(options) {
351
+ const result = [];
352
+ switch (options.contentSecurityPolicy) {
353
+ case void 0:
354
+ case true:
355
+ result.push(contentSecurityPolicy());
356
+ break;
357
+ case false: break;
358
+ default:
359
+ result.push(contentSecurityPolicy(options.contentSecurityPolicy));
360
+ break;
361
+ }
362
+ switch (options.crossOriginEmbedderPolicy) {
363
+ case void 0:
364
+ case false: break;
365
+ case true:
366
+ result.push(crossOriginEmbedderPolicy());
367
+ break;
368
+ default:
369
+ result.push(crossOriginEmbedderPolicy(options.crossOriginEmbedderPolicy));
370
+ break;
371
+ }
372
+ switch (options.crossOriginOpenerPolicy) {
373
+ case void 0:
374
+ case true:
375
+ result.push(crossOriginOpenerPolicy());
376
+ break;
377
+ case false: break;
378
+ default:
379
+ result.push(crossOriginOpenerPolicy(options.crossOriginOpenerPolicy));
380
+ break;
381
+ }
382
+ switch (options.crossOriginResourcePolicy) {
383
+ case void 0:
384
+ case true:
385
+ result.push(crossOriginResourcePolicy());
386
+ break;
387
+ case false: break;
388
+ default:
389
+ result.push(crossOriginResourcePolicy(options.crossOriginResourcePolicy));
390
+ break;
391
+ }
392
+ switch (options.originAgentCluster) {
393
+ case void 0:
394
+ case true:
395
+ result.push(originAgentCluster());
396
+ break;
397
+ case false: break;
398
+ default:
399
+ console.warn("Origin-Agent-Cluster does not take options. Remove the property to silence this warning.");
400
+ result.push(originAgentCluster());
401
+ break;
402
+ }
403
+ switch (options.referrerPolicy) {
404
+ case void 0:
405
+ case true:
406
+ result.push(referrerPolicy());
407
+ break;
408
+ case false: break;
409
+ default:
410
+ result.push(referrerPolicy(options.referrerPolicy));
411
+ break;
412
+ }
413
+ if ("strictTransportSecurity" in options && "hsts" in options) throw new Error("Strict-Transport-Security option was specified twice. Remove the `hsts` option to fix this error.");
414
+ const strictTransportSecurityOption = options.strictTransportSecurity ?? options.hsts;
415
+ switch (strictTransportSecurityOption) {
416
+ case void 0:
417
+ case true:
418
+ result.push(strictTransportSecurity());
419
+ break;
420
+ case false: break;
421
+ default:
422
+ result.push(strictTransportSecurity(strictTransportSecurityOption));
423
+ break;
424
+ }
425
+ if ("xContentTypeOptions" in options && "noSniff" in options) throw new Error("X-Content-Type-Options option was specified twice. Remove the `noSniff` option to fix this error.");
426
+ switch (options.xContentTypeOptions ?? options.noSniff) {
427
+ case void 0:
428
+ case true:
429
+ result.push(xContentTypeOptions());
430
+ break;
431
+ case false: break;
432
+ default:
433
+ console.warn("X-Content-Type-Options does not take options. Remove the property to silence this warning.");
434
+ result.push(xContentTypeOptions());
435
+ break;
436
+ }
437
+ if ("xDnsPrefetchControl" in options && "dnsPrefetchControl" in options) throw new Error("X-DNS-Prefetch-Control option was specified twice. Remove the `dnsPrefetchControl` option to fix this error.");
438
+ const xDnsPrefetchControlOption = options.xDnsPrefetchControl ?? options.dnsPrefetchControl;
439
+ switch (xDnsPrefetchControlOption) {
440
+ case void 0:
441
+ case true:
442
+ result.push(xDnsPrefetchControl());
443
+ break;
444
+ case false: break;
445
+ default:
446
+ result.push(xDnsPrefetchControl(xDnsPrefetchControlOption));
447
+ break;
448
+ }
449
+ if ("xDownloadOptions" in options && "ieNoOpen" in options) throw new Error("X-Download-Options option was specified twice. Remove the `ieNoOpen` option to fix this error.");
450
+ switch (options.xDownloadOptions ?? options.ieNoOpen) {
451
+ case void 0:
452
+ case true:
453
+ result.push(xDownloadOptions());
454
+ break;
455
+ case false: break;
456
+ default:
457
+ console.warn("X-Download-Options does not take options. Remove the property to silence this warning.");
458
+ result.push(xDownloadOptions());
459
+ break;
460
+ }
461
+ if ("xFrameOptions" in options && "frameguard" in options) throw new Error("X-Frame-Options option was specified twice. Remove the `frameguard` option to fix this error.");
462
+ const xFrameOptionsOption = options.xFrameOptions ?? options.frameguard;
463
+ switch (xFrameOptionsOption) {
464
+ case void 0:
465
+ case true:
466
+ result.push(xFrameOptions());
467
+ break;
468
+ case false: break;
469
+ default:
470
+ result.push(xFrameOptions(xFrameOptionsOption));
471
+ break;
472
+ }
473
+ if ("xPermittedCrossDomainPolicies" in options && "permittedCrossDomainPolicies" in options) throw new Error("X-Permitted-Cross-Domain-Policies option was specified twice. Remove the `permittedCrossDomainPolicies` option to fix this error.");
474
+ const xPermittedCrossDomainPoliciesOption = options.xPermittedCrossDomainPolicies ?? options.permittedCrossDomainPolicies;
475
+ switch (xPermittedCrossDomainPoliciesOption) {
476
+ case void 0:
477
+ case true:
478
+ result.push(xPermittedCrossDomainPolicies());
479
+ break;
480
+ case false: break;
481
+ default:
482
+ result.push(xPermittedCrossDomainPolicies(xPermittedCrossDomainPoliciesOption));
483
+ break;
484
+ }
485
+ if ("xPoweredBy" in options && "hidePoweredBy" in options) throw new Error("X-Powered-By option was specified twice. Remove the `hidePoweredBy` option to fix this error.");
486
+ const xPoweredByOption = options.xPoweredBy ?? options.hidePoweredBy;
487
+ const xPoweredBy = function xPoweredBy() {
488
+ return async function xPoweredByMiddleware(ctx, next) {
489
+ ctx.res.delete("X-Powered-By");
490
+ await next();
491
+ };
492
+ };
493
+ switch (xPoweredByOption) {
494
+ case void 0:
495
+ case true:
496
+ result.push(xPoweredBy());
497
+ break;
498
+ case false: break;
499
+ default:
500
+ console.warn("X-Powered-By does not take options. Remove the property to silence this warning.");
501
+ result.push(xPoweredBy());
502
+ break;
503
+ }
504
+ if ("xXssProtection" in options && "xssFilter" in options) throw new Error("X-XSS-Protection option was specified twice. Remove the `xssFilter` option to fix this error.");
505
+ switch (options.xXssProtection ?? options.xssFilter) {
506
+ case void 0:
507
+ case true:
508
+ result.push(xXssProtection());
509
+ break;
510
+ case false: break;
511
+ default:
512
+ console.warn("X-XSS-Protection does not take options. Remove the property to silence this warning.");
513
+ result.push(xXssProtection());
514
+ break;
515
+ }
516
+ if (options.permissionPolicy && typeof options.permissionPolicy === "object") result.push(permissionPolicy(options.permissionPolicy));
517
+ return result;
518
+ }
519
+ const secureHeaders = Object.assign(function secureHeaders(options = {}) {
520
+ const secureHeadersHandler = (0, hoa.compose)(getMiddlewareFunctionsFromOptions(options));
521
+ return async function secureHeadersMiddleware(ctx, next) {
522
+ await secureHeadersHandler(ctx, next);
523
+ };
524
+ }, {
525
+ contentSecurityPolicy,
526
+ crossOriginEmbedderPolicy,
527
+ crossOriginOpenerPolicy,
528
+ crossOriginResourcePolicy,
529
+ originAgentCluster,
530
+ referrerPolicy,
531
+ strictTransportSecurity,
532
+ xContentTypeOptions,
533
+ xDnsPrefetchControl,
534
+ xDownloadOptions,
535
+ xFrameOptions,
536
+ xPermittedCrossDomainPolicies,
537
+ xXssProtection,
538
+ permissionPolicy,
539
+ dnsPrefetchControl: xDnsPrefetchControl,
540
+ xssFilter: xXssProtection,
541
+ permittedCrossDomainPolicies: xPermittedCrossDomainPolicies,
542
+ ieNoOpen: xDownloadOptions,
543
+ noSniff: xContentTypeOptions,
544
+ frameguard: xFrameOptions,
545
+ hsts: strictTransportSecurity
546
+ });
547
+
548
+ //#endregion
549
+ exports.contentSecurityPolicy = contentSecurityPolicy;
550
+ exports.crossOriginEmbedderPolicy = crossOriginEmbedderPolicy;
551
+ exports.crossOriginOpenerPolicy = crossOriginOpenerPolicy;
552
+ exports.crossOriginResourcePolicy = crossOriginResourcePolicy;
553
+ exports.default = secureHeaders;
554
+ exports.secureHeaders = secureHeaders;
555
+ exports.dnsPrefetchControl = xDnsPrefetchControl;
556
+ exports.xDnsPrefetchControl = xDnsPrefetchControl;
557
+ exports.frameguard = xFrameOptions;
558
+ exports.xFrameOptions = xFrameOptions;
559
+ exports.hsts = strictTransportSecurity;
560
+ exports.strictTransportSecurity = strictTransportSecurity;
561
+ exports.ieNoOpen = xDownloadOptions;
562
+ exports.xDownloadOptions = xDownloadOptions;
563
+ exports.noSniff = xContentTypeOptions;
564
+ exports.xContentTypeOptions = xContentTypeOptions;
565
+ exports.originAgentCluster = originAgentCluster;
566
+ exports.permissionPolicy = permissionPolicy;
567
+ exports.permittedCrossDomainPolicies = xPermittedCrossDomainPolicies;
568
+ exports.xPermittedCrossDomainPolicies = xPermittedCrossDomainPolicies;
569
+ exports.referrerPolicy = referrerPolicy;
570
+ exports.xXssProtection = xXssProtection;
571
+ exports.xssFilter = xXssProtection;