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

protected-cors

v1.10.0

Published

**protected-cors** is an advanced version of CORS made for developers who want **complete control** over who can access their API.

Readme

🔒 protected-cors

protected-cors is an advanced version of CORS made for developers who want complete control over who can access their API.

It helps protect your backend by allowing only requests from your trusted frontend and blocking everything else — including Postman, Thunder Client, and curl.
You can also enable open mode to allow all origins, even with credentials enabled.


💡 What It Does

✅ Allows requests only from trusted origins (in secure mode)
🌍 Can allow all origins — including Postman, Thunder Client, curl (in open mode)
🔐 Blocks unauthorized users or bots hitting your endpoints
🍪 Supports credentials (cookies, tokens) even with ["*"]
🧠 Works out of the box — simple setup, powerful protection


🧩 Example 1 — Secure Mode (Recommended for Production)

In this mode, only your specified frontend domains can access your API.
All other clients (like Postman, Thunder Client, curl, or bots) are automatically blocked.

import express from "express";
import CORS from "protected-cors";

const app = express();

// ✅ Secure configuration — allows only specific trusted domains
app.use(
  CORS({
    origin: [
      "https://your-frontend-domain.com",
      "https://another-trusted-site.com"
    ],
    credentials: true,
  })
);

app.get("/", (req, res) => {
  res.json({ message: "CORS upgraded and secure 🔒" });
});

app.listen(3000, () => console.log("Server running securely on port 3000"));

🔐 Description

  • Only the listed domains in origin are allowed.
  • Requests from unknown clients or tools (Postman, curl, etc.) get 403 Forbidden.
  • Use this for production or private APIs.

🧩 Example 2 — Open Mode (Allow All Origins, Including Postman & curl)

In this mode, your API accepts requests from any origin — browsers, Postman, Thunder Client, curl, bots, or custom scripts.
Unlike standard CORS, you can safely enable credentials: true even with ["*"].

import express from "express";
import CORS from "protected-cors";

const app = express();

// 🌐 Open configuration — allows ALL origins including Postman, Thunder Client, curl, etc.
app.use(
  CORS({
    origin: ["*"], // wildcard — allows every origin
    methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
    allowedHeaders: "Content-Type,Authorization",
    credentials: true, // ✅ allowed even with ["*"] in protected-cors
    maxAge: 600,
  })
);

app.get("/", (req, res) => {
  res.json({ message: "CORS open for all origins 🌍 with credentials support 🍪" });
});

app.listen(3000, () => console.log("Server running on port 3000 (CORS open for all)"));

⚙️ Description

  • origin: ["*"] allows every origin, including Postman, Thunder Client, curl, browsers, and bots.
  • credentials: true is supported with ["*"].
  • Ideal for testing, development, or public APIs.
  • Use with caution in production.

⚙️ Configuration Options

| Key | Type | Default | Description | Example | |------|------|----------|-------------|----------| | origin | string[] | ["*"] | Array of allowed origins. Each must be a string. ⚠️ Using ["*"] allows all origins, including Postman, Thunder Client, curl, and bots. | ["https://your-frontend-domain.com"] | | methods | string | "GET,HEAD,PUT,PATCH,POST,DELETE" | HTTP methods allowed for cross-origin requests. | "GET,POST" | | allowedHeaders | string | "Content-Type,Authorization" | Request headers allowed from the frontend. | "Content-Type,Authorization,X-Access-Token" | | exposedHeaders | string | "" | Response headers browsers can access. | "X-Total-Count" | | credentials | boolean | false | Allows cookies or tokens to be included in cross-origin requests. ✅ Supported even with ["*"]. | true | | maxAge | number | 600 | Cache time (in seconds) for preflight (OPTIONS) responses. | 3600 |


🧠 How It Works

  1. Checks if the request origin matches one in your allowed list.
  2. Validates the User-Agent and request headers to confirm real browser traffic.
  3. Allows credentials and cookies securely.
  4. Instantly blocks untrusted or malformed requests with a 403 Forbidden response.

🚫 Secure Mode Blocks These Clients

  1. 🧪 Postman
  2. ⚡ Thunder Client
  3. 🌀 curl / wget
  4. 🧰 Custom scripts and bots
  5. 🤖 Non-browser or unauthorized requests

If it’s not coming from a real browser on your trusted frontend, it’s blocked.


🛡️ License

ISC License © 2025 — simple, open, and developer-friendly.

Built for developers who want CORS done right — strict, secure, and easy.


🧩 Author

protected-cors — built with ❤️ for developers who want powerful yet flexible CORS control.