content-security-policy-builder

Build Content Security Policy directives.

MIT 9 个版本
安装
npm install content-security-policy-builder
yarn add content-security-policy-builder
pnpm add content-security-policy-builder
bun add content-security-policy-builder
README

Content Security Policy builder

Take an object and turn it into a Content Security Policy string.

It can handle a lot of things you can you throw at it; camelCased or dash-separated directives, arrays or strings, et cetera.

Usage:

import builder from "content-security-policy-builder";

// default-src 'self' default.com; script-src scripts.com; whatever-src something; object-src
builder({
  directives: {
    defaultSrc: ["'self'", "default.com"],
    scriptSrc: "scripts.com",
    "whatever-src": "something",
    objectSrc: true,
  },
});

// default-src 'self'; whatever-src something
builder({
  directives: new Map([
    ["defaultSrc", ["'self'", "default.com"]],
    ["whatever-src", "something"],
  ]),
});

This module is considered complete. I expect to continue maintenance if needed, but I don't plan to add features or make breaking changes.

版本列表
2.3.0 2025-03-28
2.2.0 2024-04-25
2.1.1 2022-03-23
2.1.0 2019-06-13
2.0.0 2018-01-23
1.1.0 2016-07-31
1.0.0 2015-12-18
0.2.0 2015-09-18
0.1.0 2015-09-10