WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Function securityHeaders

    • Custom Security Headers Middleware

      Adds additional security headers beyond what Helmet provides and removes potentially sensitive server information. This middleware complements Helmet by adding custom security headers and implementing security best practices for API responses.

      The middleware removes the X-Powered-By header to prevent server fingerprinting and adds several security headers to protect against common web vulnerabilities including content type sniffing, clickjacking, XSS attacks, and information leakage.

      Applied early in the middleware stack to ensure all responses include proper security headers regardless of the response path or content type.

      Parameters

      • _req: Request

        Express request object (unused)

      • res: Response

        Express response object to modify headers

      • next: NextFunction

        Express next function to continue middleware chain

      Returns void

      // Usage in main application middleware stack
      import { securityHeaders } from '@/shared/middleware/security';

      app.use(securityHeaders); // Apply early in middleware stack
      // Headers added by this middleware:
      // X-Content-Type-Options: nosniff
      // X-Frame-Options: DENY
      // X-XSS-Protection: 1; mode=block
      // Referrer-Policy: strict-origin-when-cross-origin
      // Permissions-Policy: geolocation=(), microphone=(), camera=()
      // (X-Powered-By header is removed)
      // Security benefits:
      // - Prevents MIME type sniffing attacks
      // - Blocks iframe embedding (clickjacking protection)
      // - Enables XSS filtering in older browsers
      // - Controls referrer information leakage
      // - Restricts dangerous browser APIs
      // - Hides server technology information