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 πŸ™

Β© 2025 – Pkg Stats / Ryan Hefner

websecure-ez

v1.0.6

Published

πŸ›‘οΈ The ultimate web security configuration tool and library for Next.js applications. Features a powerful security middleware library, visual configuration interface, and CLI with industry-specific templates.

Readme

The ultimate web security configuration tool and library for Next.js applications. Protect your applications against XSS, clickjacking, CSRF, and other common web vulnerabilities with just a few lines of code.

🎯 What is websecure-ez?

websecure-ez is two things in one:

  1. πŸ“š A powerful security library - Add comprehensive security headers to your Next.js app
  2. 🎨 A visual configuration tool - Configure security settings through an intuitive web interface

πŸš€ Quick Start

websecure-ez is both a library and a configuration tool. Here are the different ways to use it:

πŸ“¦ For Library Users (Securing Your App)

If you want to add security to your existing Next.js project:

# Install in your project
npm install websecure-ez

Create middleware.ts in your project root:

import { createSecureMiddleware } from 'websecure-ez';

const secureMiddleware = createSecureMiddleware();

export default secureMiddleware;

export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};

That's it! Your app is now secured. The websecure-ez package only adds the security library - no extra files or scripts will interfere with your project.

πŸ› οΈ For Configuration (Setting Up Security)

If you want to configure custom security settings, use the CLI tools:

🎨 Visual Mode (Web Interface)

Perfect for visual learners and comprehensive configuration:

# Use without installing (recommended)
npx websecure-ez visual

# Or install globally first
npm install -g websecure-ez
websecure-ez visual

This opens a beautiful web interface at http://localhost:3000 where you can:

  • ✨ Configure security settings with real-time preview
  • πŸ“Š Get instant security analysis and scoring
  • 🎯 Choose from predefined security presets
  • πŸ’» See generated middleware code update live
  • πŸ“‹ Copy production-ready code to your project

⚑ Option 2: Console Mode (Terminal Interface)

Perfect for automation, CI/CD, and developers who prefer CLI:

# Install globally (recommended)
npm install -g websecure-ez
websecure-ez console

# Or run without installing
npx websecure-ez console

This runs entirely in your terminal and allows you to:

  • πŸš€ Quick setup with interactive prompts
  • 🎯 Choose security presets (Strict/Moderate/Custom)
  • βš™οΈ Configure individual security features
  • πŸ’Ύ Auto-generate and save middleware.ts file
  • πŸ”„ Perfect for scripting and automation

🎨 Option 2.5: Industry Templates (CLI)

Perfect for quick setup with industry-specific configurations:

# List all available templates
websecure-ez templates

# Generate from a specific template
websecure-ez template ecommerce
websecure-ez template saas
websecure-ez template healthcare

# Or run without installing
npx websecure-ez template fintech

Available templates:

  • πŸ›’ ecommerce - E-commerce platforms with payment processing (Stripe, PayPal)
  • πŸ’Ό saas - SaaS applications and web dashboards
  • πŸ“ blog - Content sites, blogs, and news platforms
  • πŸ₯ healthcare - HIPAA-compliant healthcare applications
  • πŸ’° fintech - Banking-grade security for financial services
  • πŸ”Œ api - API gateways and microservices

Each template includes:

  • βœ… Pre-configured security headers optimized for the industry
  • 🎯 Appropriate CSP directives for common third-party services
  • πŸ”’ Compliance-ready settings (HIPAA, PCI-DSS considerations)
  • βš™οΈ Optional customization prompts

πŸ“¦ Option 3: Direct Library Usage

For developers who know exactly what they want:

npm install websecure-ez

Create middleware.ts in your project root:

import { createSecureMiddleware } from 'websecure-ez';

// Use default secure configuration
const secureMiddleware = createSecureMiddleware();

export default secureMiddleware;

export const config = {
  matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};

✨ Features

πŸ›‘οΈ Comprehensive Security Headers

  • Content Security Policy (CSP) - Prevent XSS attacks with fine-grained control
  • HTTP Strict Transport Security (HSTS) - Enforce HTTPS connections
  • X-Frame-Options - Block clickjacking attempts
  • Permissions Policy - Control browser feature access
  • X-Content-Type-Options - Prevent MIME-sniffing attacks
  • X-XSS-Protection - Enable browser XSS filtering
  • Referrer Policy - Control referrer information leakage
  • Cross-Origin Policies - Configure CORS and isolation policies

🎨 Visual Configuration Interface

  • Real-time Security Analysis - Get instant feedback on your configuration
  • Security Score Dashboard - See your security posture at a glance
  • Preset Configurations - Choose from Strict, Balanced, or Basic security levels
  • Live Code Generation - See your middleware code update in real-time
  • Dark/Light Mode - Beautiful interface that adapts to your preference

πŸ”§ Developer Experience

  • πŸš€ TypeScript Support - Fully typed for better development experience
  • πŸ“¦ Zero Dependencies - Lightweight and fast
  • 🎯 Next.js Optimized - Built specifically for Next.js middleware
  • πŸ“š Comprehensive Documentation - Clear examples and guides

πŸ“– Configuration Options

Security Presets

Strict Security πŸ”’

  • Maximum security for production applications
  • Blocks most external resources
  • Strictest cookie and frame policies

Balanced Security βš–οΈ

  • Good security with development flexibility
  • Allows common external resources (fonts, CDNs)
  • Balanced policies for most applications

Basic Security πŸ›‘οΈ

  • Essential protections only
  • Permissive for development
  • Good starting point for new projects

Custom Configuration

import { createSecureMiddleware } from 'websecure-ez';

const secureMiddleware = createSecureMiddleware({
  contentSecurityPolicy: {
    enabled: true,
    directives: {
      defaultSrc: ["'self'"],
      scriptSrc: ["'self'", "'unsafe-inline'"],
      styleSrc: ["'self'", "'unsafe-inline'", "https://fonts.googleapis.com"],
      fontSrc: ["'self'", "https://fonts.gstatic.com"],
      imgSrc: ["'self'", "data:", "https:"],
      connectSrc: ["'self'"],
      upgradeInsecureRequests: true,
    },
    reportOnly: false, // Set to true for testing
  },
  hsts: {
    enabled: true,
    maxAge: 31536000, // 1 year
    includeSubDomains: true,
    preload: true,
  },
  xFrameOptions: {
    enabled: true,
    option: 'DENY', // or 'SAMEORIGIN'
  },
  permissionsPolicy: {
    enabled: true,
    features: {
      camera: "'none'",
      microphone: "'none'",
      geolocation: "'none'",
      payment: "'none'",
    },
  },
  secureCookies: {
    enabled: true,
    httpOnly: true,
    secure: true,
    sameSite: 'Strict',
  },
});

export default secureMiddleware;

πŸ”§ Utility Functions

Input Sanitization

import { sanitizeInput } from 'websecure-ez';

const userInput = '<script>alert("xss")</script>';
const safeInput = sanitizeInput(userInput);
// Output: '&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt;'

Secure Cookie Defaults

import { applyCookieDefaults } from 'websecure-ez';

const cookieOptions = applyCookieDefaults({
  maxAge: 3600,
  path: '/',
});

// Use with your cookie library
response.cookies.set('session', token, cookieOptions);

Nonce Generation

import { generateNonce } from 'websecure-ez';

const nonce = generateNonce();
// Use in your CSP directive: script-src 'nonce-{nonce}'

🎯 Command Reference

Global Installation Commands

# Install globally for easy access
npm install -g websecure-ez

# Visual mode (web interface)
websecure-ez visual
websecure-ez          # Default to visual mode

# Console mode (terminal interface)  
websecure-ez console
websecure-ez generate # Alias for console mode

# Template commands
websecure-ez templates              # List all templates
websecure-ez template <name>        # Generate from template
websecure-ez template ecommerce     # E-commerce template
websecure-ez template saas          # SaaS template
websecure-ez template healthcare    # Healthcare template

# Help
websecure-ez help

NPX Commands (No Installation)

# Visual mode
npx websecure-ez visual

# Template generation
npx websecure-ez templates
npx websecure-ez template ecommerce
npx websecure-ez        # Default to visual mode

# Console mode
npx websecure-ez console
npx websecure-ez generate

# Help
npx websecure-ez help

Development Commands (Source Code)

# If you cloned the repository
npm run dev      # Visual interface
npm run console  # Console mode
npm run visual   # Visual interface (alias)
npm run help     # Show help

🎯 Understanding the Modes

When to Use Visual Mode 🎨

  • Learning: First time setting up security
  • Exploration: Want to see all available options
  • Analysis: Need real-time security scoring
  • Comparison: Testing different configurations

When to Use Console Mode ⚑

  • Automation: CI/CD pipelines and scripts
  • Speed: Quick setup for new projects
  • Headless: Server environments without GUI
  • Integration: Part of larger toolchains

🚨 Important Notes

  • Configuration Tool vs Library: The npm run dev command starts the configuration interface. To use the library in your project, install it as a dependency.
  • Testing: Always test your configuration in development before deploying to production.
  • CSP Strictness: Some CSP directives may break functionality if too restrictive - use report-only mode initially.
  • HTTPS Required: HSTS headers only work on HTTPS connections.
  • Browser Compatibility: Some headers may not be supported in older browsers.

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

πŸ“„ License

MIT License - see the LICENSE file for details.

🌟 Support