@middy/http-security-headers 7.2.3 → 7.3.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.
Files changed (3) hide show
  1. package/index.d.ts +4 -0
  2. package/index.js +99 -1
  3. package/package.json +3 -6
package/index.d.ts CHANGED
@@ -58,4 +58,8 @@ declare function httpSecurityHeaders(
58
58
  options?: WithBoolValues<Options>,
59
59
  ): middy.MiddlewareObj<unknown, unknown, Error>;
60
60
 
61
+ export declare function httpSecurityHeadersValidateOptions(
62
+ options?: Record<string, unknown>,
63
+ ): void;
64
+
61
65
  export default httpSecurityHeaders;
package/index.js CHANGED
@@ -1,6 +1,104 @@
1
1
  // Copyright 2017 - 2026 will Farrell, Luciano Mammino, and Middy contributors.
2
2
  // SPDX-License-Identifier: MIT
3
- import { normalizeHttpResponse } from "@middy/util";
3
+ import { normalizeHttpResponse, validateOptions } from "@middy/util";
4
+
5
+ // Each policy option accepts either a config object or a boolean (true = use
6
+ // defaults, false = disable). See middleware body for enable/disable logic.
7
+
8
+ const booleanOr = (objectSchema) => ({
9
+ oneOf: [{ type: "boolean" }, objectSchema],
10
+ });
11
+
12
+ const policyObject = (policyEnum) => ({
13
+ type: "object",
14
+ properties: {
15
+ policy: policyEnum
16
+ ? { type: "string", enum: policyEnum }
17
+ : { type: "string" },
18
+ },
19
+ additionalProperties: false,
20
+ });
21
+
22
+ const actionObject = {
23
+ type: "object",
24
+ properties: {
25
+ action: { type: "string" },
26
+ },
27
+ additionalProperties: false,
28
+ };
29
+
30
+ const referrerPolicyValues = [
31
+ "no-referrer",
32
+ "no-referrer-when-downgrade",
33
+ "origin",
34
+ "origin-when-cross-origin",
35
+ "same-origin",
36
+ "strict-origin",
37
+ "strict-origin-when-cross-origin",
38
+ "unsafe-url",
39
+ ];
40
+
41
+ const permittedCrossDomainPoliciesValues = [
42
+ "none",
43
+ "master-only",
44
+ "by-content-type",
45
+ "by-ftp-filename",
46
+ "all",
47
+ ];
48
+
49
+ const optionSchema = {
50
+ type: "object",
51
+ properties: {
52
+ // CSP directives are an open-ended string map; keep permissive.
53
+ contentSecurityPolicy: booleanOr({ type: "object" }),
54
+ contentSecurityPolicyReportOnly: { type: "boolean" },
55
+ contentTypeOptions: booleanOr(actionObject),
56
+ crossOriginEmbedderPolicy: booleanOr(policyObject()),
57
+ crossOriginOpenerPolicy: booleanOr(policyObject()),
58
+ crossOriginResourcePolicy: booleanOr(policyObject()),
59
+ dnsPrefetchControl: booleanOr({
60
+ type: "object",
61
+ properties: {
62
+ allow: { type: "boolean" },
63
+ },
64
+ additionalProperties: false,
65
+ }),
66
+ downloadOptions: booleanOr(actionObject),
67
+ frameOptions: booleanOr(actionObject),
68
+ originAgentCluster: booleanOr({
69
+ type: "object",
70
+ additionalProperties: false,
71
+ }),
72
+ // Permissions-Policy features are an open-ended string map.
73
+ permissionsPolicy: booleanOr({ type: "object" }),
74
+ permittedCrossDomainPolicies: booleanOr(
75
+ policyObject(permittedCrossDomainPoliciesValues),
76
+ ),
77
+ poweredBy: { type: "boolean" },
78
+ referrerPolicy: booleanOr(policyObject(referrerPolicyValues)),
79
+ // Reporting-Endpoints is an open-ended group->url map.
80
+ reportingEndpoints: booleanOr({ type: "object" }),
81
+ // Report-To groups are open-ended; maxAge/includeSubdomains are known.
82
+ reportTo: booleanOr({ type: "object" }),
83
+ strictTransportSecurity: booleanOr({
84
+ type: "object",
85
+ properties: {
86
+ maxAge: { type: "number", minimum: 0 },
87
+ includeSubDomains: { type: "boolean" },
88
+ preload: { type: "boolean" },
89
+ },
90
+ additionalProperties: false,
91
+ }),
92
+ xssProtection: booleanOr({
93
+ type: "object",
94
+ additionalProperties: false,
95
+ }),
96
+ },
97
+ additionalProperties: false,
98
+ };
99
+
100
+ export const httpSecurityHeadersValidateOptions = (options) =>
101
+ validateOptions("@middy/http-security-headers", optionSchema, options);
4
102
 
5
103
  // Code and Defaults heavily based off https://helmetjs.github.io/
6
104
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-security-headers",
3
- "version": "7.2.3",
3
+ "version": "7.3.1",
4
4
  "description": "Applies best practice security headers to responses. It's a simplified port of HelmetJS",
5
5
  "type": "module",
6
6
  "engines": {
@@ -17,9 +17,6 @@
17
17
  "import": {
18
18
  "types": "./index.d.ts",
19
19
  "default": "./index.js"
20
- },
21
- "require": {
22
- "default": "./index.js"
23
20
  }
24
21
  }
25
22
  },
@@ -68,10 +65,10 @@
68
65
  "url": "https://github.com/sponsors/willfarrell"
69
66
  },
70
67
  "dependencies": {
71
- "@middy/util": "7.2.3"
68
+ "@middy/util": "7.3.1"
72
69
  },
73
70
  "devDependencies": {
74
- "@middy/core": "7.2.3",
71
+ "@middy/core": "7.3.1",
75
72
  "@types/aws-lambda": "^8.0.0",
76
73
  "@types/node": "^22.0.0"
77
74
  }