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

@tetsujs/secure-headers

v0.5.3

Published

Security headers for every Tetsu response: HSTS, CSP, frame and referrer policies

Readme

@tetsujs/secure-headers

Security headers on every response.

bun add @tetsujs/secure-headers

Usage

import { secureHeaders } from "@tetsujs/secure-headers";

const secure = secureHeaders();

createApp({ hooks: { beforeResponse: [secure] }, routes });

secureHeaders() is one beforeResponse hook. Mount it on the application: that slot sees every outgoing response, errors and 404s included.

Sent by default — none of these can break a JSON API:

| Header | Value | | | --- | --- | --- | | x-content-type-options | nosniff | the browser does not guess a content type | | x-frame-options | DENY | the response cannot be framed | | referrer-policy | no-referrer | URLs with identifiers do not leak to other sites | | strict-transport-security | max-age=15552000 | HTTPS only, for 180 days |

HSTS

includeSubDomains and preload are off by default: the first breaks any subdomain still served over plain HTTP, and the second takes months to undo. Turn them on when that is known to be safe:

secureHeaders({ hsts: { maxAge: 63_072_000, includeSubDomains: true } });

preload without includeSubDomains, or with maxAge under a year, makes secureHeaders() throw — the browsers' preload list would reject it.

Content Security Policy

Not sent unless asked, because a wrong policy breaks pages rather than APIs. For an API that only answers JSON, apiPolicy denies everything:

import { apiPolicy, secureHeaders } from "@tetsujs/secure-headers";

secureHeaders({ contentSecurityPolicy: apiPolicy });
// default-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'

If the same application serves a page — the docs page of @tetsujs/openapi, for instance — remove the policy for that route:

const allowDocs = hook.beforeResponse((ctx) => {
  if (ctx.route?.path === "/docs") ctx.out.headers.delete("content-security-policy");
});

const secure = secureHeaders({ contentSecurityPolicy: apiPolicy });

createApp({
  hooks: { beforeResponse: [secure, allowDocs] },
  routes: [docs({ info }), apiController()],
});

An exception for one route

A route's own beforeResponse hook runs after the application's, so it can change a header for that route:

const allowFraming = hook.beforeResponse((ctx) => {
  ctx.out.headers.set("x-frame-options", "SAMEORIGIN");
});

route({
  method: "GET",
  path: "/embeddable",
  hooks: { beforeResponse: [allowFraming] },
  handler: () => page(),
});

Setting the header in the handler does not work: the handler runs before beforeResponse, and the application's value replaces it.

Options

| Option | Default | | | --- | --- | --- | | hsts | { maxAge: 15552000 } | maxAge, includeSubDomains, preload; false turns it off | | frameOptions | "DENY" | "SAMEORIGIN", or false | | referrerPolicy | "no-referrer" | any policy, or false | | noSniff | true | false turns it off | | contentSecurityPolicy | not sent | a policy string; apiPolicy is ready-made |

HSTS is sent on every response, including plain HTTP ones, where browsers ignore it — so it works the same behind any proxy.