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

@inkanjs/secure-headers

v0.2.1

Published

Security headers for inkan: a strict Content-Security-Policy with per-request nonces, HSTS and the rest, each one yours to change.

Readme

@inkanjs/secure-headers

Security headers for inkan, what helmet does for Express: a strict Content-Security-Policy with a nonce per request when you need one, HSTS over HTTPS, and the rest. Every header can be changed or left out, and a header the handler set itself is never overwritten.

npm install @inkanjs/inkan @inkanjs/secure-headers
import { html, inkan } from "@inkanjs/inkan";
import { secureHeaders } from "@inkanjs/secure-headers";

const app = inkan()
  .register(secureHeaders())
  .get("/", (ctx) => html`<script nonce="${ctx.cspNonce}">start()</script>`);

What every answer gets

| header | default | option | | --- | --- | --- | | content-security-policy | see below | csp | | strict-transport-security | max-age=31536000; includeSubDomains, over HTTPS only | hsts | | x-content-type-options | nosniff | noSniff | | x-frame-options | DENY | frameOptions | | referrer-policy | no-referrer | referrerPolicy | | cross-origin-opener-policy | same-origin | crossOriginOpenerPolicy | | cross-origin-resource-policy | same-origin | crossOriginResourcePolicy | | x-dns-prefetch-control | off | dnsPrefetchControl | | permissions-policy | camera=(), geolocation=(), microphone=(), payment=(), usb=(), interest-cohort=() | permissionsPolicy | | origin-agent-cluster | ?1 | originAgentCluster | | x-permitted-cross-domain-policies | none | permittedCrossDomainPolicies |

Give a string to send another value, false to leave the header out. extra adds headers of your own the same way.

The default policy, DEFAULT_CSP:

default-src 'self'; base-uri 'self'; font-src 'self' https: data:; form-action 'self';
frame-ancestors 'none'; img-src 'self' data:; object-src 'none'; script-src 'self';
script-src-attr 'none'; style-src 'self'

No 'unsafe-inline' anywhere: inline scripts and styles need a nonce.

secureHeaders({
  csp: {
    directives: { "img-src": ["'self'", "https://cdn.example.com"], "script-src-attr": false, "upgrade-insecure-requests": true },
    // useDefaults: false   start from nothing
    // reportOnly: true     content-security-policy-report-only
  },
  hsts: { maxAge: 63072000, preload: true },
  crossOriginResourcePolicy: "cross-origin", // a public API that pages on other sites load
});

Options

| option | default | | | --- | --- | --- | | csp | {} | false for none; directives over the defaults (false drops one, true for one without sources), useDefaults, reportOnly | | hsts | {} | false for none; maxAge, includeSubDomains (true), preload (false), force (false) | | https | ctx.secure | (ctx) => boolean: whether the request came over HTTPS | | skip | none | (ctx) => boolean: answers to leave alone | | extra | none | more headers, by name | | each header above | | a string, or false |

How it behaves

  • The nonce. ctx.cspNonce is 128 random bits, fresh for every request, made only when read. An answer whose handler (or template) read it gets 'nonce-…' in script-src and style-src; every other answer gets the plain policy. With only default-src in the policy, script-src and style-src are written out from it to take the nonce.
  • HSTS goes out only over HTTPS: ctx.secure is true, or https(ctx) says so. Behind a proxy that ends TLS, give the app trustProxy (then ctx.secure follows the proxy's x-forwarded-proto), or pass hsts: { force: true }.
  • Your headers win. A header the handler or a hook before this one set stays as it is, so one route can send its own policy.
  • inkan's own pages keep working. /docs, /openapi.json and the inspector are answered before any hook runs, so they never get these headers: the docs page runs an inline script and style, which the default policy would block.
  • Problems (4xx, 5xx) get the headers too. Streams do, as their headers go out first.
  • Shared plugin: register it on the app for every route, or inside a plugin for its routes. The OpenAPI document is not changed.