npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rineex/helmet-mw-module

v1.2.3

Published

Nest - a Helmet module

Readme

Helmet Middleware Module

Overview

HelmetModule integrates Helmet security middleware into NestJS applications. Helmet sets various HTTP security headers to help protect against common web vulnerabilities.

When to use:

  • Web applications exposed to browsers
  • APIs that serve HTML content
  • Applications requiring security header compliance (CSP, HSTS, etc.)

When not to use:

  • Internal-only APIs not accessed from browsers
  • APIs behind a reverse proxy that sets security headers
  • Applications with custom security header requirements that conflict with Helmet defaults

Public API

HelmetModule

NestJS module that configures and applies Helmet middleware globally.

Static Methods

HelmetModule.forRoot(options?)

Synchronously configures the module with Helmet options.

Parameters:

  • options (optional): HelmetOptions - Configuration options from helmet package
    • Supports all Helmet sub-middleware options (contentSecurityPolicy, hsts, frameguard, etc.)
    • If omitted, uses Helmet's default secure configuration

Returns: DynamicModule - A configured NestJS module

HelmetModule.forRootAsync(options)

Asynchronously configures the module.

Parameters:

  • options: Object with one of:
    • useFactory: (...args: any[]) => HelmetOptions | Promise<HelmetOptions>
    • useClass: Constructor class
    • useExisting: Token for existing provider
    • imports (optional): Array of modules
    • inject (optional): Array of injection tokens

Returns: DynamicModule - A configured NestJS module

Usage Examples

Basic Setup

import { Module } from '@nestjs/common';
import { HelmetModule } from '@rineex/helmet-mw-module';

@Module({
  imports: [HelmetModule.forRoot()],
})
export class AppModule {}

With Custom Options

import { Module } from '@nestjs/common';
import { HelmetModule } from '@rineex/helmet-mw-module';

@Module({
  imports: [
    HelmetModule.forRoot({
      contentSecurityPolicy: {
        directives: {
          defaultSrc: ["'self'"],
          styleSrc: ["'self'", "'unsafe-inline'"],
        },
      },
    }),
  ],
})
export class AppModule {}

Async Configuration

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { HelmetModule } from '@rineex/helmet-mw-module';

@Module({
  imports: [
    ConfigModule.forRoot(),
    HelmetModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: (config: ConfigService) => ({
        hsts: {
          maxAge: config.get<number>('HSTS_MAX_AGE', 31536000),
        },
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}

Behavior & Guarantees

Invariants

  • Middleware applies to all routes (forRoutes('*'))
  • Security headers are set on all HTTP responses
  • Default configuration enables all Helmet sub-middlewares with secure defaults

Performance

  • Minimal overhead per request
  • Header setting is synchronous
  • No external dependencies or network calls

Concurrency

  • Stateless middleware; safe for concurrent requests
  • No shared state between requests

Operational Notes

Configuration

Helmet options include:

  • contentSecurityPolicy: Content Security Policy headers
  • hsts: HTTP Strict Transport Security
  • frameguard: X-Frame-Options header
  • noSniff: X-Content-Type-Options header
  • xssFilter: X-XSS-Protection header
  • referrerPolicy: Referrer-Policy header
  • And other security-related headers

Common Pitfalls

  1. CSP breaking third-party scripts: Overly strict Content Security Policy can block legitimate resources
  2. HSTS in development: Long HSTS maxAge can cause issues during local development
  3. Iframe embedding: Default frameguard blocks iframe embedding; disable if needed for embeddable widgets
  4. Content-Type sniffing: noSniff prevents MIME type sniffing, which may break some legacy clients

Logging

  • No logging provided by this module
  • Helmet errors are handled internally and don't affect request processing

License

Apache-2.0