index.d.cts 7.2 KB

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