🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

content-security-policy-builder

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

content-security-policy-builder

Build Content Security Policy directives.

latest
Source
npmnpm
Version
2.3.0
Version published
Weekly downloads
514K
-7.79%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

security

FAQs

Package last updated on 28 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts