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

@noidme/csp

v0.1.0-beta.0

Published

A fail-closed Content-Security-Policy builder for a consent-protected page. Strict default-src 'self' baseline (object-src 'none', pinned base-uri/form-action/frame-ancestors); widen only the exact origins your first-party app needs. buildCsp() → the head

Downloads

133

Readme

@noidme/csp

A fail-closed Content-Security-Policy builder for a consent-protected page. Zero-dependency. A noidme.js building block, usable standalone.

The threat model treats the in-page environment as hostile: a tracker injected after your SDK loads can add <script>/<img>/beacon sinks that main-thread patchers (and even a service worker) can't fully cover. A strict CSP is the browser-enforced backstop. This builds a default-src 'self' baseline and lets you widen only the exact origins your first-party app needs.

import { buildCsp, cspHeaderName, applyCsp } from '@noidme/csp';

// RECOMMENDED — set the policy as an HTTP response header (server-side):
const policy = buildCsp({ connect: ['https://consent.example.com'], img: ['https://cdn.example.com'] });
res.setHeader(cspHeaderName(), policy);

// Fallback — inject a <meta http-equiv> from the client when you can't set the header:
applyCsp({ connect: ['https://consent.example.com'] });   // no-ops off-DOM + if a CSP meta already exists

// Nonce the inline scripts/styles you control (the clean path off 'unsafe-inline'):
const nonce = generateNonce();                       // once per response
buildCsp({ nonce });                                 // adds 'nonce-…' to script-src + style-src
// → render <script nonce="{nonce}"> … </script>

// Observe before enforcing:
buildCsp({ reportOnly: true, reportUri: '/csp-report' });  // → Content-Security-Policy-Report-Only

What it gives you

  • Fail-closed baseline: default-src 'self', object-src 'none', worker-src 'self', and pinned base-uri / form-action / frame-ancestors 'self'. img-src is 'self' only — data: is opt-in (imgData: true), because it's an exfiltration channel under XSS. Widen with connect / img / script / style (append), or directives (wholesale replace — an empty list fails closed to 'none').
  • Injection-safe: every caller-supplied source is validated — a value containing ;, ,, or whitespace throws, so a hostile or typo'd origin can't break out of its directive and silently widen the policy.
  • Nonce support: generateNonce() + nonce prepend 'nonce-…' to script-src/style-src.
  • Header vs meta: buildCsp() for the HTTP header (the strong path). applyCsp() is the client-side <meta> fallback — it strips the directives a meta CSP silently ignores (frame-ancestors/report-uri/ sandbox) and refuses report-only, so it never implies protection it can't give. Safe to call unconditionally (first policy wins). Prefer the header.
  • Also: upgradeInsecureRequests (opt-in). Deterministic directive order (stable diffs/tests).

Install

npm i @noidme/csp

License

MIT.