index.d.mts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import {IncomingMessage, ServerResponse} from "http"
  2. type ContentSecurityPolicyDirectiveValueFunction = (req: IncomingMessage, res: ServerResponse) => string
  3. type ContentSecurityPolicyDirectiveValue = string | ContentSecurityPolicyDirectiveValueFunction
  4. interface ContentSecurityPolicyOptions {
  5. useDefaults?: boolean
  6. directives?: Record<string, null | Iterable<ContentSecurityPolicyDirectiveValue> | typeof dangerouslyDisableDefaultSrc>
  7. reportOnly?: boolean
  8. }
  9. interface ContentSecurityPolicy {
  10. (options?: Readonly<ContentSecurityPolicyOptions>): (req: IncomingMessage, res: ServerResponse, next: (err?: Error) => void) => void
  11. getDefaultDirectives: typeof getDefaultDirectives
  12. dangerouslyDisableDefaultSrc: typeof dangerouslyDisableDefaultSrc
  13. }
  14. declare const dangerouslyDisableDefaultSrc: unique symbol
  15. declare const getDefaultDirectives: () => {
  16. [x: string]: Iterable<ContentSecurityPolicyDirectiveValue>
  17. }
  18. declare const contentSecurityPolicy: ContentSecurityPolicy
  19. interface CrossOriginEmbedderPolicyOptions {
  20. policy?: "require-corp" | "credentialless"
  21. }
  22. declare function crossOriginEmbedderPolicy(options?: Readonly<CrossOriginEmbedderPolicyOptions>): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  23. interface CrossOriginOpenerPolicyOptions {
  24. policy?: "same-origin" | "same-origin-allow-popups" | "unsafe-none"
  25. }
  26. declare function crossOriginOpenerPolicy(options?: Readonly<CrossOriginOpenerPolicyOptions>): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  27. interface CrossOriginResourcePolicyOptions {
  28. policy?: "same-origin" | "same-site" | "cross-origin"
  29. }
  30. declare function crossOriginResourcePolicy(options?: Readonly<CrossOriginResourcePolicyOptions>): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  31. interface ExpectCtOptions {
  32. maxAge?: number
  33. enforce?: boolean
  34. reportUri?: string
  35. }
  36. declare function expectCt(options?: Readonly<ExpectCtOptions>): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  37. declare function originAgentCluster(): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  38. type ReferrerPolicyToken = "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url" | ""
  39. interface ReferrerPolicyOptions {
  40. policy?: ReferrerPolicyToken | ReferrerPolicyToken[]
  41. }
  42. declare function referrerPolicy(options?: Readonly<ReferrerPolicyOptions>): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  43. interface StrictTransportSecurityOptions {
  44. maxAge?: number
  45. includeSubDomains?: boolean
  46. preload?: boolean
  47. }
  48. declare function strictTransportSecurity(options?: Readonly<StrictTransportSecurityOptions>): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  49. declare function xContentTypeOptions(): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  50. interface XDnsPrefetchControlOptions {
  51. allow?: boolean
  52. }
  53. declare function xDnsPrefetchControl(options?: Readonly<XDnsPrefetchControlOptions>): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  54. declare function xDownloadOptions(): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  55. interface XFrameOptionsOptions {
  56. action?: "deny" | "sameorigin"
  57. }
  58. declare function xFrameOptions(options?: Readonly<XFrameOptionsOptions>): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  59. interface XPermittedCrossDomainPoliciesOptions {
  60. permittedPolicies?: "none" | "master-only" | "by-content-type" | "all"
  61. }
  62. declare function xPermittedCrossDomainPolicies(options?: Readonly<XPermittedCrossDomainPoliciesOptions>): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  63. declare function xPoweredBy(): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  64. declare function xXssProtection(): (_req: IncomingMessage, res: ServerResponse, next: () => void) => void
  65. type HelmetOptions = {
  66. contentSecurityPolicy?: ContentSecurityPolicyOptions | boolean
  67. crossOriginEmbedderPolicy?: CrossOriginEmbedderPolicyOptions | boolean
  68. crossOriginOpenerPolicy?: CrossOriginOpenerPolicyOptions | boolean
  69. crossOriginResourcePolicy?: CrossOriginResourcePolicyOptions | boolean
  70. expectCt?: ExpectCtOptions | boolean
  71. originAgentCluster?: boolean
  72. referrerPolicy?: ReferrerPolicyOptions | boolean
  73. } & (
  74. | {
  75. strictTransportSecurity?: StrictTransportSecurityOptions | boolean
  76. hsts?: never
  77. }
  78. | {
  79. hsts?: StrictTransportSecurityOptions | boolean
  80. strictTransportSecurity?: never
  81. }
  82. ) &
  83. (
  84. | {
  85. xContentTypeOptions?: boolean
  86. noSniff?: never
  87. }
  88. | {
  89. noSniff?: boolean
  90. xContentTypeOptions?: never
  91. }
  92. ) &
  93. (
  94. | {
  95. xDnsPrefetchControl?: XDnsPrefetchControlOptions | boolean
  96. dnsPrefetchControl?: never
  97. }
  98. | {
  99. dnsPrefetchControl?: XDnsPrefetchControlOptions | boolean
  100. xDnsPrefetchControl?: never
  101. }
  102. ) &
  103. (
  104. | {
  105. xDownloadOptions?: boolean
  106. ieNoOpen?: never
  107. }
  108. | {
  109. ieNoOpen?: boolean
  110. xDownloadOptions?: never
  111. }
  112. ) &
  113. (
  114. | {
  115. xFrameOptions?: XFrameOptionsOptions | boolean
  116. frameguard?: never
  117. }
  118. | {
  119. frameguard?: XFrameOptionsOptions | boolean
  120. xFrameOptions?: never
  121. }
  122. ) &
  123. (
  124. | {
  125. xPermittedCrossDomainPolicies?: XPermittedCrossDomainPoliciesOptions | boolean
  126. permittedCrossDomainPolicies?: never
  127. }
  128. | {
  129. permittedCrossDomainPolicies?: XPermittedCrossDomainPoliciesOptions | boolean
  130. xPermittedCrossDomainPolicies?: never
  131. }
  132. ) &
  133. (
  134. | {
  135. xPoweredBy?: boolean
  136. hidePoweredBy?: never
  137. }
  138. | {
  139. hidePoweredBy?: boolean
  140. xPoweredBy?: never
  141. }
  142. ) &
  143. (
  144. | {
  145. xXssProtection?: boolean
  146. xssFilter?: never
  147. }
  148. | {
  149. xssFilter?: boolean
  150. xXssProtection?: never
  151. }
  152. )
  153. interface Helmet {
  154. (options?: Readonly<HelmetOptions>): (req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => void) => void
  155. contentSecurityPolicy: typeof contentSecurityPolicy
  156. crossOriginEmbedderPolicy: typeof crossOriginEmbedderPolicy
  157. crossOriginOpenerPolicy: typeof crossOriginOpenerPolicy
  158. crossOriginResourcePolicy: typeof crossOriginResourcePolicy
  159. expectCt: typeof expectCt
  160. originAgentCluster: typeof originAgentCluster
  161. referrerPolicy: typeof referrerPolicy
  162. strictTransportSecurity: typeof strictTransportSecurity
  163. xContentTypeOptions: typeof xContentTypeOptions
  164. xDnsPrefetchControl: typeof xDnsPrefetchControl
  165. xDownloadOptions: typeof xDownloadOptions
  166. xFrameOptions: typeof xFrameOptions
  167. xPermittedCrossDomainPolicies: typeof xPermittedCrossDomainPolicies
  168. xPoweredBy: typeof xPoweredBy
  169. xXssProtection: typeof xXssProtection
  170. dnsPrefetchControl: typeof xDnsPrefetchControl
  171. frameguard: typeof xFrameOptions
  172. hidePoweredBy: typeof xPoweredBy
  173. hsts: typeof strictTransportSecurity
  174. ieNoOpen: typeof xDownloadOptions
  175. noSniff: typeof xContentTypeOptions
  176. permittedCrossDomainPolicies: typeof xPermittedCrossDomainPolicies
  177. xssFilter: typeof xXssProtection
  178. }
  179. declare const helmet: Helmet
  180. export {HelmetOptions, 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}