@middy/http-security-headers 2.5.4 → 3.0.0-alpha.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.
Files changed (4) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/package.json +7 -7
  4. package/index.js +0 -171
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2021 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
3
+ Copyright (c) 2017-2022 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -77,7 +77,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
77
77
 
78
78
  ## License
79
79
 
80
- Licensed under [MIT License](LICENSE). Copyright (c) 2017-2021 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
80
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
81
81
 
82
82
  <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
83
83
  <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@middy/http-security-headers",
3
- "version": "2.5.4",
3
+ "version": "3.0.0-alpha.0",
4
4
  "description": "Applies best practice security headers to responses. It's a simplified port of HelmetJS",
5
- "type": "commonjs",
5
+ "type": "module",
6
6
  "engines": {
7
- "node": ">=12"
7
+ "node": ">=14"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "main": "index.js",
13
+ "exports": "./index.js",
14
14
  "types": "index.d.ts",
15
15
  "files": [
16
16
  "index.d.ts"
@@ -48,11 +48,11 @@
48
48
  "url": "https://github.com/middyjs/middy/issues"
49
49
  },
50
50
  "homepage": "https://github.com/middyjs/middy#readme",
51
- "gitHead": "a4134a579c757a9fdfed3006877ba2c0ec8a2cfa",
51
+ "gitHead": "c533f62841c8a39d061d7b94f30ba178f002c8db",
52
52
  "dependencies": {
53
- "@middy/util": "^2.5.4"
53
+ "@middy/util": "^3.0.0-alpha.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@middy/core": "^2.5.4"
56
+ "@middy/core": "^3.0.0-alpha.0"
57
57
  }
58
58
  }
package/index.js DELETED
@@ -1,171 +0,0 @@
1
- "use strict";
2
-
3
- const {
4
- normalizeHttpResponse
5
- } = require('@middy/util'); // Code and Defaults heavily based off https://helmetjs.github.io/
6
-
7
-
8
- const defaults = {
9
- // contentDisposition: {
10
- // filename: undefined
11
- // },
12
- dnsPrefetchControl: {
13
- allow: false
14
- },
15
- expectCT: {
16
- enforce: true,
17
- maxAge: 30,
18
- reportUri: ''
19
- },
20
- frameguard: {
21
- action: 'deny'
22
- },
23
- hidePoweredBy: {
24
- setTo: null
25
- },
26
- hsts: {
27
- maxAge: 180 * 24 * 60 * 60,
28
- includeSubDomains: true,
29
- preload: true
30
- },
31
- ieNoOpen: {
32
- action: 'noopen'
33
- },
34
- noSniff: {
35
- action: 'nosniff'
36
- },
37
- permittedCrossDomainPolicies: {
38
- policy: 'none' // none, master-only, by-content-type, by-ftp-filename, all
39
-
40
- },
41
- referrerPolicy: {
42
- policy: 'no-referrer'
43
- },
44
- xssFilter: {
45
- reportUri: ''
46
- }
47
- };
48
- const helmet = {};
49
- const helmetHtmlOnly = {}; // OWASP ASVS 14.4.2
50
- // API Gateway strips out this header :(
51
- // helmet.content = (headers, config) => {
52
- // const filename = config.filename ?? `api.${headers?.['Content-Type'].split(/[/;]/)[1] ?? 'json'}`
53
- // headers['Content-Disposition'] = `attachment; filename="${filename}"`
54
- // }
55
- // contentSecurityPolicy - N/A - no HTML
56
- // featurePolicy - N/A - no HTML
57
- // crossdomain - N/A - For Adobe products
58
- // https://github.com/helmetjs/dns-Prefetch-control
59
-
60
- helmet.dnsPrefetchControl = (headers, config) => {
61
- headers['X-DNS-Prefetch-Control'] = config.allow ? 'on' : 'off';
62
- return headers;
63
- }; // expectCt - in-progress spec
64
- // https://github.com/helmetjs/frameguard
65
-
66
-
67
- helmetHtmlOnly.frameguard = (headers, config) => {
68
- headers['X-Frame-Options'] = config.action.toUpperCase();
69
- return headers;
70
- }; // https://github.com/helmetjs/hide-powered-by
71
-
72
-
73
- helmet.hidePoweredBy = (headers, config) => {
74
- if (config.setTo) {
75
- headers['X-Powered-By'] = config.setTo;
76
- } else {
77
- Reflect.deleteProperty(headers, 'Server');
78
- Reflect.deleteProperty(headers, 'X-Powered-By');
79
- }
80
-
81
- return headers;
82
- }; // hpkp - deprecated
83
- // https://github.com/helmetjs/hsts
84
-
85
-
86
- helmet.hsts = (headers, config) => {
87
- let header = 'max-age=' + Math.round(config.maxAge);
88
-
89
- if (config.includeSubDomains) {
90
- header += '; includeSubDomains';
91
- }
92
-
93
- if (config.preload) {
94
- header += '; preload';
95
- }
96
-
97
- headers['Strict-Transport-Security'] = header;
98
- return headers;
99
- }; // https://github.com/helmetjs/ienoopen
100
-
101
-
102
- helmet.ieNoOpen = (headers, config) => {
103
- headers['X-Download-Options'] = config.action;
104
- return headers;
105
- }; // noCache - N/A - separate middleware
106
- // https://github.com/helmetjs/dont-sniff-mimetype
107
-
108
-
109
- helmet.noSniff = (headers, config) => {
110
- headers['X-Content-Type-Options'] = config.action;
111
- return headers;
112
- }; // https://github.com/helmetjs/referrer-policy
113
-
114
-
115
- helmet.referrerPolicy = (headers, config) => {
116
- headers['Referrer-Policy'] = config.policy;
117
- return headers;
118
- }; // https://github.com/helmetjs/crossdomain
119
-
120
-
121
- helmet.permittedCrossDomainPolicies = (headers, config) => {
122
- headers['X-Permitted-Cross-Domain-Policies'] = config.policy;
123
- return headers;
124
- }; // https://github.com/helmetjs/x-xss-protection
125
-
126
-
127
- helmetHtmlOnly.xssFilter = (headers, config) => {
128
- let header = '1; mode=block';
129
-
130
- if (config.reportUri) {
131
- header += '; report=' + config.reportUri;
132
- }
133
-
134
- headers['X-XSS-Protection'] = header;
135
- return headers;
136
- };
137
-
138
- const httpSecurityHeadersMiddleware = (opts = {}) => {
139
- const options = { ...defaults,
140
- ...opts
141
- };
142
-
143
- const httpSecurityHeadersMiddlewareAfter = async request => {
144
- var _request$response$hea, _request$response$hea2;
145
-
146
- request.response = normalizeHttpResponse(request.response);
147
- Object.keys(helmet).forEach(key => {
148
- const config = { ...defaults[key],
149
- ...options[key]
150
- };
151
- request.response.headers = helmet[key](request.response.headers, config);
152
- });
153
-
154
- if ((_request$response$hea = request.response.headers) !== null && _request$response$hea !== void 0 && (_request$response$hea2 = _request$response$hea['Content-Type']) !== null && _request$response$hea2 !== void 0 && _request$response$hea2.includes('text/html')) {
155
- Object.keys(helmetHtmlOnly).forEach(key => {
156
- const config = { ...defaults[key],
157
- ...options[key]
158
- };
159
- request.response.headers = helmetHtmlOnly[key](request.response.headers, config);
160
- });
161
- }
162
- };
163
-
164
- const httpSecurityHeadersMiddlewareOnError = httpSecurityHeadersMiddlewareAfter;
165
- return {
166
- after: httpSecurityHeadersMiddlewareAfter,
167
- onError: httpSecurityHeadersMiddlewareOnError
168
- };
169
- };
170
-
171
- module.exports = httpSecurityHeadersMiddleware;