index.mjs 20 KB

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