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

helmet-permitted-cross-domain-policies

v1.1.0

Published

Express and Node.js middleware SDK for the X-Permitted-Cross-Domain-Policies security header.

Readme

helmet-permitted-cross-domain-policies

helmet-permitted-cross-domain-policies is a small but reusable middleware SDK for applying the X-Permitted-Cross-Domain-Policies response header in Express apps, internal Node.js frameworks, and shared platform packages.

Instead of shipping a single inline middleware function, this package is organized into reusable modules so developers can consume only what they need.

What developers get

  • Express-compatible middleware
  • Plain response helper for custom frameworks
  • Normalized policy parsing and validation
  • zod-based options parsing
  • Safe setIfAbsent support for layered middleware stacks

Installation

npm install helmet-permitted-cross-domain-policies

Package structure

helmet-permitted-cross-domain-policies/
├── index.js
├── src/
│   ├── constants.js
│   ├── helpers.js
│   ├── index.js
│   ├── middleware.js
│   └── validation.js
└── test.js

Quick start

Express

const express = require('express');
const permittedCrossDomainPolicies = require('helmet-permitted-cross-domain-policies');

const app = express();

app.use(permittedCrossDomainPolicies());

Shared security preset

const permittedCrossDomainPolicies = require('helmet-permitted-cross-domain-policies');

function attachSecurityHeaders(app) {
  app.use(
    permittedCrossDomainPolicies({
      permittedPolicies: 'none',
      setIfAbsent: true,
    })
  );
}

module.exports = { attachSecurityHeaders };

Plain Node.js

const http = require('http');
const { applyHeader } = require('helmet-permitted-cross-domain-policies');

const server = http.createServer((req, res) => {
  applyHeader(res, 'by-content-type');
  res.end('policy header applied');
});

API reference

permittedCrossDomainPolicies(options?)

Returns Express-compatible middleware.

app.use(
  permittedCrossDomainPolicies({
    permittedPolicies: 'master-only',
    setIfAbsent: true,
  })
);

Options:

| Option | Default | Description | | --- | --- | --- | | permittedPolicies | 'none' | Header value to set | | setIfAbsent | false | Leaves an existing header untouched |

You can also pass a policy string directly:

app.use(permittedCrossDomainPolicies('master-only'));

applyHeader(res, policy?, options?)

Sets the header on any response-like object that exposes setHeader().

applyHeader(res, 'none');
applyHeader(res, 'master-only', { setIfAbsent: true });

buildHeaderValue(policy?)

Validates and normalizes a policy string.

const headerValue = buildHeaderValue('Master-Only');
// 'master-only'

parsePolicy(value)

Returns the normalized policy string or null.

isValidPolicy(value)

Returns true when the supplied value is supported.

Exported constants

  • HEADER_NAME
  • DEFAULT_POLICY
  • VALID_POLICIES

Supported policy values

| Value | Meaning | | --- | --- | | none | Disallow policy files | | master-only | Allow only the master policy file | | by-content-type | Allow only correctly served policy files | | by-ftp-filename | Allow only crossdomain.xml for FTP | | all | Allow all policy files |

When to use this package

This package is useful when you are:

  • building a shared Express starter
  • standardizing response headers across services
  • wrapping security defaults in an internal SDK
  • avoiding repeated header validation logic in multiple repositories

License

This package is licensed under the MIT License. See LICENSE.