hostHeaderValidation.d.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import { RequestHandler } from 'express';
  2. /**
  3. * Express middleware for DNS rebinding protection.
  4. * Validates Host header hostname (port-agnostic) against an allowed list.
  5. *
  6. * This is particularly important for servers without authorization or HTTPS,
  7. * such as localhost servers or development servers. DNS rebinding attacks can
  8. * bypass same-origin policy by manipulating DNS to point a domain to a
  9. * localhost address, allowing malicious websites to access your local server.
  10. *
  11. * @param allowedHostnames - List of allowed hostnames (without ports).
  12. * For IPv6, provide the address with brackets (e.g., '[::1]').
  13. * @returns Express middleware function
  14. *
  15. * @example
  16. * ```typescript
  17. * const middleware = hostHeaderValidation(['localhost', '127.0.0.1', '[::1]']);
  18. * app.use(middleware);
  19. * ```
  20. */
  21. export declare function hostHeaderValidation(allowedHostnames: string[]): RequestHandler;
  22. /**
  23. * Convenience middleware for localhost DNS rebinding protection.
  24. * Allows only localhost, 127.0.0.1, and [::1] (IPv6 localhost) hostnames.
  25. *
  26. * @example
  27. * ```typescript
  28. * app.use(localhostHostValidation());
  29. * ```
  30. */
  31. export declare function localhostHostValidation(): RequestHandler;
  32. //# sourceMappingURL=hostHeaderValidation.d.ts.map