@middy/http-security-headers 3.0.0-alpha.6 → 3.0.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/README.md +23 -13
- package/index.cjs +3 -0
- package/index.js +2 -242
- package/package.json +13 -6
package/README.md
CHANGED
|
@@ -1,27 +1,37 @@
|
|
|
1
|
-
# Middy http-security-headers middleware
|
|
2
|
-
|
|
3
|
-
<div align="center">
|
|
4
|
-
<img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.png"/>
|
|
5
|
-
</div>
|
|
6
|
-
|
|
7
1
|
<div align="center">
|
|
2
|
+
<h1>Middy http-security-headers middleware</h1>
|
|
3
|
+
<img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.svg"/>
|
|
8
4
|
<p><strong>HTTP security headers middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda</strong></p>
|
|
9
5
|
<p>Applies best practice security headers to responses. It's a simplified port of [HelmetJS](https://helmetjs.github.io/). See HelmetJS documentation for more details.</p>
|
|
10
|
-
</div>
|
|
11
|
-
|
|
12
|
-
<div align="center">
|
|
13
6
|
<p>
|
|
14
|
-
<a href="
|
|
7
|
+
<a href="https://www.npmjs.com/package/@middy/http-security-headers?activeTab=versions">
|
|
15
8
|
<img src="https://badge.fury.io/js/%40middy%2Fhttp-security-headers.svg" alt="npm version" style="max-width:100%;">
|
|
16
9
|
</a>
|
|
10
|
+
<a href="https://packagephobia.com/result?p=@middy/http-security-headers">
|
|
11
|
+
<img src="https://packagephobia.com/badge?p=@middy/http-security-headers" alt="npm install size" style="max-width:100%;">
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://github.com/middyjs/middy/actions">
|
|
14
|
+
<img src="https://github.com/middyjs/middy/workflows/Tests/badge.svg" alt="GitHub Actions test status badge" style="max-width:100%;">
|
|
15
|
+
</a>
|
|
16
|
+
<br/>
|
|
17
|
+
<a href="https://standardjs.com/">
|
|
18
|
+
<img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="Standard Code Style" style="max-width:100%;">
|
|
19
|
+
</a>
|
|
17
20
|
<a href="https://snyk.io/test/github/middyjs/middy">
|
|
18
21
|
<img src="https://snyk.io/test/github/middyjs/middy/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/middyjs/middy" style="max-width:100%;">
|
|
19
22
|
</a>
|
|
20
|
-
<a href="https://
|
|
21
|
-
<img src="https://img.shields.io/
|
|
23
|
+
<a href="https://lgtm.com/projects/g/middyjs/middy/context:javascript">
|
|
24
|
+
<img src="https://img.shields.io/lgtm/grade/javascript/g/middyjs/middy.svg?logo=lgtm&logoWidth=18" alt="Language grade: JavaScript" style="max-width:100%;">
|
|
25
|
+
</a>
|
|
26
|
+
<a href="https://bestpractices.coreinfrastructure.org/projects/5280">
|
|
27
|
+
<img src="https://bestpractices.coreinfrastructure.org/projects/5280/badge" alt="Core Infrastructure Initiative (CII) Best Practices" style="max-width:100%;">
|
|
22
28
|
</a>
|
|
29
|
+
<br/>
|
|
23
30
|
<a href="https://gitter.im/middyjs/Lobby">
|
|
24
|
-
<img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter"
|
|
31
|
+
<img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter" style="max-width:100%;">
|
|
32
|
+
</a>
|
|
33
|
+
<a href="https://stackoverflow.com/questions/tagged/middy?sort=Newest&uqlId=35052">
|
|
34
|
+
<img src="https://img.shields.io/badge/StackOverflow-[middy]-yellow" alt="Ask questions on StackOverflow" style="max-width:100%;">
|
|
25
35
|
</a>
|
|
26
36
|
</p>
|
|
27
37
|
</div>
|
package/index.cjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _util=require("@middy/util");const defaults={contentSecurityPolicy:{"default-src":"'none'","base-uri":"'none'",sandbox:"","form-action":"'none'","frame-ancestors":"'none'","navigate-to":"'none'","report-to":"csp","require-trusted-types-for":"'script'","trusted-types":"'none'","upgrade-insecure-requests":""},contentTypeOptions:{action:"nosniff"},crossOriginEmbedderPolicy:{policy:"require-corp"},crossOriginOpenerPolicy:{policy:"same-origin"},crossOriginResourcePolicy:{policy:"same-origin"},dnsPrefetchControl:{allow:false},downloadOptions:{action:"noopen"},frameOptions:{action:"deny"},originAgentCluster:{},permissionsPolicy:{accelerometer:"","ambient-light-sensor":"",autoplay:"",battery:"",camera:"","cross-origin-isolated":"","display-capture":"","document-domain":"","encrypted-media":"","execution-while-not-rendered":"","execution-while-out-of-viewport":"",fullscreen:"",geolocation:"",gyroscope:"","keyboard-map":"",magnetometer:"",microphone:"",midi:"","navigation-override":"",payment:"","picture-in-picture":"","publickey-credentials-get":"","screen-wake-lock":"","sync-xhr":"",usb:"","web-share":"","xr-spatial-tracking":"","clipboard-read":"","clipboard-write":"",gamepad:"","speaker-selection":"","conversion-measurement":"","focus-without-user-activation":"",hid:"","idle-detection":"","interest-cohort":"",serial:"","sync-script":"","trust-token-redemption":"","window-placement":"","vertical-scroll":""},permittedCrossDomainPolicies:{policy:"none"},poweredBy:{server:""},referrerPolicy:{policy:"no-referrer"},reportTo:{maxAge:365*24*60*60,default:"",includeSubdomains:true,csp:"",staple:"",xss:""},strictTransportSecurity:{maxAge:180*24*60*60,includeSubDomains:true,preload:true},xssProtection:{reportTo:"xss"}};const helmet={};const helmetHtmlOnly={};helmetHtmlOnly.contentSecurityPolicy=(headers,config)=>{let header=Object.keys(config).map(policy=>config[policy]?`${policy} ${config[policy]}`:"").filter(str=>str).join("; ");if(config.sandbox===""){header+="; sandbox"}if(config["upgrade-insecure-requests"]===""){header+="; upgrade-insecure-requests"}headers["Content-Security-Policy"]=header};helmetHtmlOnly.crossOriginEmbedderPolicy=(headers,config)=>{headers["Cross-Origin-Embedder-Policy"]=config.policy};helmetHtmlOnly.crossOriginOpenerPolicy=(headers,config)=>{headers["Cross-Origin-Opener-Policy"]=config.policy};helmetHtmlOnly.crossOriginResourcePolicy=(headers,config)=>{headers["Cross-Origin-Resource-Policy"]=config.policy};helmetHtmlOnly.permissionsPolicy=(headers,config)=>{headers["Permissions-Policy"]=Object.keys(config).map(policy=>`${policy}=${config[policy]==="*"?"*":"("+config[policy]+")"}`).join(", ")};helmet.originAgentCluster=(headers,config)=>{headers["Origin-Agent-Cluster"]="?1"};helmet.referrerPolicy=(headers,config)=>{headers["Referrer-Policy"]=config.policy};helmetHtmlOnly.reportTo=(headers,config)=>{headers["Report-To"]=Object.keys(config).map(group=>{const includeSubdomains=group==="default"?`, "include_subdomains": ${config.includeSubdomains}`:"";return config[group]&&group!=="includeSubdomains"?`{ "group": "default", "max_age": ${config.maxAge}, "endpoints": [ { "url": "${config[group]}" } ]${includeSubdomains} }`:""}).filter(str=>str).join(", ")};helmet.strictTransportSecurity=(headers,config)=>{let header="max-age="+Math.round(config.maxAge);if(config.includeSubDomains){header+="; includeSubDomains"}if(config.preload){header+="; preload"}headers["Strict-Transport-Security"]=header};helmet.contentTypeOptions=(headers,config)=>{headers["X-Content-Type-Options"]=config.action};helmet.dnsPrefetchControl=(headers,config)=>{headers["X-DNS-Prefetch-Control"]=config.allow?"on":"off"};helmet.downloadOptions=(headers,config)=>{headers["X-Download-Options"]=config.action};helmetHtmlOnly.frameOptions=(headers,config)=>{headers["X-Frame-Options"]=config.action.toUpperCase()};helmet.permittedCrossDomainPolicies=(headers,config)=>{headers["X-Permitted-Cross-Domain-Policies"]=config.policy};helmet.poweredBy=(headers,config)=>{if(config.server){headers["X-Powered-By"]=config.server}else{delete headers.Server;delete headers["X-Powered-By"]}};helmetHtmlOnly.xssProtection=(headers,config)=>{let header="1; mode=block";if(config.reportTo){header+="; report="+config.reportTo}headers["X-XSS-Protection"]=header};const httpSecurityHeadersMiddleware=(opts={})=>{const options={...defaults,...opts};const httpSecurityHeadersMiddlewareAfter=async request=>{(0,_util).normalizeHttpResponse(request);Object.keys(helmet).forEach(key=>{if(!options[key])return;const config={...defaults[key],...options[key]};helmet[key](request.response.headers,config)});if(request.response.headers["Content-Type"]?.includes("text/html")){Object.keys(helmetHtmlOnly).forEach(key=>{if(!options[key])return;const config={...defaults[key],...options[key]};helmetHtmlOnly[key](request.response.headers,config)})}};const httpSecurityHeadersMiddlewareOnError=async request=>{if(request.response===undefined)return;return httpSecurityHeadersMiddlewareAfter(request)};return{after:httpSecurityHeadersMiddlewareAfter,onError:httpSecurityHeadersMiddlewareOnError}};var _default=httpSecurityHeadersMiddleware;exports.default=_default
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=index.cjs.map
|
package/index.js
CHANGED
|
@@ -1,243 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
const defaults = {
|
|
3
|
-
contentSecurityPolicy: {
|
|
4
|
-
'default-src': "'none'",
|
|
5
|
-
'base-uri': "'none'",
|
|
6
|
-
sandbox: '',
|
|
7
|
-
'form-action': "'none'",
|
|
8
|
-
'frame-ancestors': "'none'",
|
|
9
|
-
'navigate-to': "'none'",
|
|
10
|
-
'report-to': 'csp',
|
|
11
|
-
'require-trusted-types-for': "'script'",
|
|
12
|
-
'trusted-types': "'none'",
|
|
13
|
-
'upgrade-insecure-requests': ''
|
|
14
|
-
},
|
|
15
|
-
contentTypeOptions: {
|
|
16
|
-
action: 'nosniff'
|
|
17
|
-
},
|
|
18
|
-
crossOriginEmbedderPolicy: {
|
|
19
|
-
policy: 'require-corp'
|
|
20
|
-
},
|
|
21
|
-
crossOriginOpenerPolicy: {
|
|
22
|
-
policy: 'same-origin'
|
|
23
|
-
},
|
|
24
|
-
crossOriginResourcePolicy: {
|
|
25
|
-
policy: 'same-origin'
|
|
26
|
-
},
|
|
27
|
-
dnsPrefetchControl: {
|
|
28
|
-
allow: false
|
|
29
|
-
},
|
|
30
|
-
downloadOptions: {
|
|
31
|
-
action: 'noopen'
|
|
32
|
-
},
|
|
33
|
-
frameOptions: {
|
|
34
|
-
action: 'deny'
|
|
35
|
-
},
|
|
36
|
-
originAgentCluster: {},
|
|
37
|
-
permissionsPolicy: {
|
|
38
|
-
accelerometer: '',
|
|
39
|
-
'ambient-light-sensor': '',
|
|
40
|
-
autoplay: '',
|
|
41
|
-
battery: '',
|
|
42
|
-
camera: '',
|
|
43
|
-
'cross-origin-isolated': '',
|
|
44
|
-
'display-capture': '',
|
|
45
|
-
'document-domain': '',
|
|
46
|
-
'encrypted-media': '',
|
|
47
|
-
'execution-while-not-rendered': '',
|
|
48
|
-
'execution-while-out-of-viewport': '',
|
|
49
|
-
fullscreen: '',
|
|
50
|
-
geolocation: '',
|
|
51
|
-
gyroscope: '',
|
|
52
|
-
'keyboard-map': '',
|
|
53
|
-
magnetometer: '',
|
|
54
|
-
microphone: '',
|
|
55
|
-
midi: '',
|
|
56
|
-
'navigation-override': '',
|
|
57
|
-
payment: '',
|
|
58
|
-
'picture-in-picture': '',
|
|
59
|
-
'publickey-credentials-get': '',
|
|
60
|
-
'screen-wake-lock': '',
|
|
61
|
-
'sync-xhr': '',
|
|
62
|
-
usb: '',
|
|
63
|
-
'web-share': '',
|
|
64
|
-
'xr-spatial-tracking': '',
|
|
65
|
-
'clipboard-read': '',
|
|
66
|
-
'clipboard-write': '',
|
|
67
|
-
gamepad: '',
|
|
68
|
-
'speaker-selection': '',
|
|
69
|
-
'conversion-measurement': '',
|
|
70
|
-
'focus-without-user-activation': '',
|
|
71
|
-
hid: '',
|
|
72
|
-
'idle-detection': '',
|
|
73
|
-
'interest-cohort': '',
|
|
74
|
-
serial: '',
|
|
75
|
-
'sync-script': '',
|
|
76
|
-
'trust-token-redemption': '',
|
|
77
|
-
'window-placement': '',
|
|
78
|
-
'vertical-scroll': ''
|
|
79
|
-
},
|
|
80
|
-
permittedCrossDomainPolicies: {
|
|
81
|
-
policy: 'none'
|
|
82
|
-
},
|
|
83
|
-
poweredBy: {
|
|
84
|
-
server: ''
|
|
85
|
-
},
|
|
86
|
-
referrerPolicy: {
|
|
87
|
-
policy: 'no-referrer'
|
|
88
|
-
},
|
|
89
|
-
reportTo: {
|
|
90
|
-
maxAge: 365 * 24 * 60 * 60,
|
|
91
|
-
default: '',
|
|
92
|
-
includeSubdomains: true,
|
|
93
|
-
csp: '',
|
|
94
|
-
staple: '',
|
|
95
|
-
xss: ''
|
|
96
|
-
},
|
|
97
|
-
strictTransportSecurity: {
|
|
98
|
-
maxAge: 180 * 24 * 60 * 60,
|
|
99
|
-
includeSubDomains: true,
|
|
100
|
-
preload: true
|
|
101
|
-
},
|
|
102
|
-
xssProtection: {
|
|
103
|
-
reportTo: 'xss'
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
const helmet = {};
|
|
107
|
-
const helmetHtmlOnly = {};
|
|
1
|
+
import{normalizeHttpResponse}from"@middy/util";const defaults={contentSecurityPolicy:{"default-src":"'none'","base-uri":"'none'",sandbox:"","form-action":"'none'","frame-ancestors":"'none'","navigate-to":"'none'","report-to":"csp","require-trusted-types-for":"'script'","trusted-types":"'none'","upgrade-insecure-requests":""},contentTypeOptions:{action:"nosniff"},crossOriginEmbedderPolicy:{policy:"require-corp"},crossOriginOpenerPolicy:{policy:"same-origin"},crossOriginResourcePolicy:{policy:"same-origin"},dnsPrefetchControl:{allow:false},downloadOptions:{action:"noopen"},frameOptions:{action:"deny"},originAgentCluster:{},permissionsPolicy:{accelerometer:"","ambient-light-sensor":"",autoplay:"",battery:"",camera:"","cross-origin-isolated":"","display-capture":"","document-domain":"","encrypted-media":"","execution-while-not-rendered":"","execution-while-out-of-viewport":"",fullscreen:"",geolocation:"",gyroscope:"","keyboard-map":"",magnetometer:"",microphone:"",midi:"","navigation-override":"",payment:"","picture-in-picture":"","publickey-credentials-get":"","screen-wake-lock":"","sync-xhr":"",usb:"","web-share":"","xr-spatial-tracking":"","clipboard-read":"","clipboard-write":"",gamepad:"","speaker-selection":"","conversion-measurement":"","focus-without-user-activation":"",hid:"","idle-detection":"","interest-cohort":"",serial:"","sync-script":"","trust-token-redemption":"","window-placement":"","vertical-scroll":""},permittedCrossDomainPolicies:{policy:"none"},poweredBy:{server:""},referrerPolicy:{policy:"no-referrer"},reportTo:{maxAge:365*24*60*60,default:"",includeSubdomains:true,csp:"",staple:"",xss:""},strictTransportSecurity:{maxAge:180*24*60*60,includeSubDomains:true,preload:true},xssProtection:{reportTo:"xss"}};const helmet={};const helmetHtmlOnly={};helmetHtmlOnly.contentSecurityPolicy=(headers,config)=>{let header=Object.keys(config).map(policy=>config[policy]?`${policy} ${config[policy]}`:"").filter(str=>str).join("; ");if(config.sandbox===""){header+="; sandbox"}if(config["upgrade-insecure-requests"]===""){header+="; upgrade-insecure-requests"}headers["Content-Security-Policy"]=header};helmetHtmlOnly.crossOriginEmbedderPolicy=(headers,config)=>{headers["Cross-Origin-Embedder-Policy"]=config.policy};helmetHtmlOnly.crossOriginOpenerPolicy=(headers,config)=>{headers["Cross-Origin-Opener-Policy"]=config.policy};helmetHtmlOnly.crossOriginResourcePolicy=(headers,config)=>{headers["Cross-Origin-Resource-Policy"]=config.policy};helmetHtmlOnly.permissionsPolicy=(headers,config)=>{headers["Permissions-Policy"]=Object.keys(config).map(policy=>`${policy}=${config[policy]==="*"?"*":"("+config[policy]+")"}`).join(", ")};helmet.originAgentCluster=(headers,config)=>{headers["Origin-Agent-Cluster"]="?1"};helmet.referrerPolicy=(headers,config)=>{headers["Referrer-Policy"]=config.policy};helmetHtmlOnly.reportTo=(headers,config)=>{headers["Report-To"]=Object.keys(config).map(group=>{const includeSubdomains=group==="default"?`, "include_subdomains": ${config.includeSubdomains}`:"";return config[group]&&group!=="includeSubdomains"?`{ "group": "default", "max_age": ${config.maxAge}, "endpoints": [ { "url": "${config[group]}" } ]${includeSubdomains} }`:""}).filter(str=>str).join(", ")};helmet.strictTransportSecurity=(headers,config)=>{let header="max-age="+Math.round(config.maxAge);if(config.includeSubDomains){header+="; includeSubDomains"}if(config.preload){header+="; preload"}headers["Strict-Transport-Security"]=header};helmet.contentTypeOptions=(headers,config)=>{headers["X-Content-Type-Options"]=config.action};helmet.dnsPrefetchControl=(headers,config)=>{headers["X-DNS-Prefetch-Control"]=config.allow?"on":"off"};helmet.downloadOptions=(headers,config)=>{headers["X-Download-Options"]=config.action};helmetHtmlOnly.frameOptions=(headers,config)=>{headers["X-Frame-Options"]=config.action.toUpperCase()};helmet.permittedCrossDomainPolicies=(headers,config)=>{headers["X-Permitted-Cross-Domain-Policies"]=config.policy};helmet.poweredBy=(headers,config)=>{if(config.server){headers["X-Powered-By"]=config.server}else{delete headers.Server;delete headers["X-Powered-By"]}};helmetHtmlOnly.xssProtection=(headers,config)=>{let header="1; mode=block";if(config.reportTo){header+="; report="+config.reportTo}headers["X-XSS-Protection"]=header};const httpSecurityHeadersMiddleware=(opts={})=>{const options={...defaults,...opts};const httpSecurityHeadersMiddlewareAfter=async request=>{normalizeHttpResponse(request);Object.keys(helmet).forEach(key=>{if(!options[key])return;const config={...defaults[key],...options[key]};helmet[key](request.response.headers,config)});if(request.response.headers["Content-Type"]?.includes("text/html")){Object.keys(helmetHtmlOnly).forEach(key=>{if(!options[key])return;const config={...defaults[key],...options[key]};helmetHtmlOnly[key](request.response.headers,config)})}};const httpSecurityHeadersMiddlewareOnError=async request=>{if(request.response===undefined)return;return httpSecurityHeadersMiddlewareAfter(request)};return{after:httpSecurityHeadersMiddlewareAfter,onError:httpSecurityHeadersMiddlewareOnError}};export default httpSecurityHeadersMiddleware
|
|
108
2
|
|
|
109
|
-
|
|
110
|
-
let header = Object.keys(config).map(policy => config[policy] ? `${policy} ${config[policy]}` : '').filter(str => str).join('; ');
|
|
111
|
-
|
|
112
|
-
if (config.sandbox === '') {
|
|
113
|
-
header += '; sandbox';
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (config['upgrade-insecure-requests'] === '') {
|
|
117
|
-
header += '; upgrade-insecure-requests';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
headers['Content-Security-Policy'] = header;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
helmetHtmlOnly.crossOriginEmbedderPolicy = (headers, config) => {
|
|
124
|
-
headers['Cross-Origin-Embedder-Policy'] = config.policy;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
helmetHtmlOnly.crossOriginOpenerPolicy = (headers, config) => {
|
|
128
|
-
headers['Cross-Origin-Opener-Policy'] = config.policy;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
helmetHtmlOnly.crossOriginResourcePolicy = (headers, config) => {
|
|
132
|
-
headers['Cross-Origin-Resource-Policy'] = config.policy;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
helmetHtmlOnly.permissionsPolicy = (headers, config) => {
|
|
136
|
-
headers['Permissions-Policy'] = Object.keys(config).map(policy => `${policy}=${config[policy] === '*' ? '*' : `(${config[policy]})`}`).join(', ');
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
helmet.originAgentCluster = (headers, config) => {
|
|
140
|
-
headers['Origin-Agent-Cluster'] = '?1';
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
helmet.referrerPolicy = (headers, config) => {
|
|
144
|
-
headers['Referrer-Policy'] = config.policy;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
helmetHtmlOnly.reportTo = (headers, config) => {
|
|
148
|
-
headers['Report-To'] = Object.keys(config).map(group => config[group] && group !== 'includeSubdomains' ? `{ "group": "default", "max_age": ${config.maxAge}, "endpoints": [ { "url": "${config[group]}" } ]${group === 'default' ? `, "include_subdomains": ${config.includeSubdomains}` : ''} }` : '').filter(str => str).join(', ');
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
helmet.strictTransportSecurity = (headers, config) => {
|
|
152
|
-
let header = 'max-age=' + Math.round(config.maxAge);
|
|
153
|
-
|
|
154
|
-
if (config.includeSubDomains) {
|
|
155
|
-
header += '; includeSubDomains';
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (config.preload) {
|
|
159
|
-
header += '; preload';
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
headers['Strict-Transport-Security'] = header;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
helmet.contentTypeOptions = (headers, config) => {
|
|
166
|
-
headers['X-Content-Type-Options'] = config.action;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
helmet.dnsPrefetchControl = (headers, config) => {
|
|
170
|
-
headers['X-DNS-Prefetch-Control'] = config.allow ? 'on' : 'off';
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
helmet.downloadOptions = (headers, config) => {
|
|
174
|
-
headers['X-Download-Options'] = config.action;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
helmetHtmlOnly.frameOptions = (headers, config) => {
|
|
178
|
-
headers['X-Frame-Options'] = config.action.toUpperCase();
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
helmet.permittedCrossDomainPolicies = (headers, config) => {
|
|
182
|
-
headers['X-Permitted-Cross-Domain-Policies'] = config.policy;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
helmet.poweredBy = (headers, config) => {
|
|
186
|
-
if (config.server) {
|
|
187
|
-
headers['X-Powered-By'] = config.server;
|
|
188
|
-
} else {
|
|
189
|
-
delete headers.Server;
|
|
190
|
-
delete headers['X-Powered-By'];
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
helmetHtmlOnly.xssProtection = (headers, config) => {
|
|
195
|
-
let header = '1; mode=block';
|
|
196
|
-
|
|
197
|
-
if (config.reportTo) {
|
|
198
|
-
header += '; report=' + config.reportTo;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
headers['X-XSS-Protection'] = header;
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const httpSecurityHeadersMiddleware = (opts = {}) => {
|
|
205
|
-
const options = { ...defaults,
|
|
206
|
-
...opts
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const httpSecurityHeadersMiddlewareAfter = async request => {
|
|
210
|
-
var _request$response$hea;
|
|
211
|
-
|
|
212
|
-
normalizeHttpResponse(request);
|
|
213
|
-
Object.keys(helmet).forEach(key => {
|
|
214
|
-
if (!options[key]) return;
|
|
215
|
-
const config = { ...defaults[key],
|
|
216
|
-
...options[key]
|
|
217
|
-
};
|
|
218
|
-
helmet[key](request.response.headers, config);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
if ((_request$response$hea = request.response.headers['Content-Type']) !== null && _request$response$hea !== void 0 && _request$response$hea.includes('text/html')) {
|
|
222
|
-
Object.keys(helmetHtmlOnly).forEach(key => {
|
|
223
|
-
if (!options[key]) return;
|
|
224
|
-
const config = { ...defaults[key],
|
|
225
|
-
...options[key]
|
|
226
|
-
};
|
|
227
|
-
helmetHtmlOnly[key](request.response.headers, config);
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const httpSecurityHeadersMiddlewareOnError = async request => {
|
|
233
|
-
if (request.response === undefined) return;
|
|
234
|
-
return httpSecurityHeadersMiddlewareAfter(request);
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
return {
|
|
238
|
-
after: httpSecurityHeadersMiddlewareAfter,
|
|
239
|
-
onError: httpSecurityHeadersMiddlewareOnError
|
|
240
|
-
};
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
export default httpSecurityHeadersMiddleware;
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-security-headers",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Applies best practice security headers to responses. It's a simplified port of HelmetJS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -10,10 +10,17 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"exports":
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./index.js",
|
|
16
|
+
"require": "./index.cjs",
|
|
17
|
+
"types": "./index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
14
20
|
"types": "index.d.ts",
|
|
15
21
|
"files": [
|
|
16
22
|
"index.js",
|
|
23
|
+
"index.cjs",
|
|
17
24
|
"index.d.ts"
|
|
18
25
|
],
|
|
19
26
|
"scripts": {
|
|
@@ -49,12 +56,12 @@
|
|
|
49
56
|
"bugs": {
|
|
50
57
|
"url": "https://github.com/middyjs/middy/issues"
|
|
51
58
|
},
|
|
52
|
-
"homepage": "https://
|
|
53
|
-
"gitHead": "
|
|
59
|
+
"homepage": "https://middy.js.org",
|
|
60
|
+
"gitHead": "01520fa8628a36c2f89e126cad656a16547ea0d6",
|
|
54
61
|
"dependencies": {
|
|
55
|
-
"@middy/util": "^3.0.0
|
|
62
|
+
"@middy/util": "^3.0.0"
|
|
56
63
|
},
|
|
57
64
|
"devDependencies": {
|
|
58
|
-
"@middy/core": "^3.0.0
|
|
65
|
+
"@middy/core": "^3.0.0"
|
|
59
66
|
}
|
|
60
67
|
}
|