Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

content-security-policy-parser

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

content-security-policy-parser

Parse Content Security Policy directives.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is content-security-policy-parser?

The content-security-policy-parser npm package is designed to parse Content Security Policy (CSP) headers into a more manageable and structured format. This can be useful for analyzing, modifying, or validating CSP headers in web applications.

What are content-security-policy-parser's main functionalities?

Parse CSP Header

This feature allows you to parse a CSP header string into an object. The parsed object provides a structured representation of the CSP directives, making it easier to analyze and manipulate.

const cspParser = require('content-security-policy-parser');
const cspHeader = "default-src 'self'; script-src 'self' 'unsafe-inline'";
const parsedCSP = cspParser(cspHeader);
console.log(parsedCSP);

Validate CSP Directives

This feature allows you to validate specific directives within the parsed CSP object. For example, you can check if 'unsafe-inline' is included in the 'script-src' directive.

const cspParser = require('content-security-policy-parser');
const cspHeader = "default-src 'self'; script-src 'self' 'unsafe-inline'";
const parsedCSP = cspParser(cspHeader);
const isValid = parsedCSP['script-src'].includes("'unsafe-inline'");
console.log(isValid);

Modify CSP Directives

This feature allows you to modify the CSP directives within the parsed object and then convert it back to a string format. For example, you can add 'unsafe-inline' to the 'script-src' directive.

const cspParser = require('content-security-policy-parser');
let cspHeader = "default-src 'self'; script-src 'self'";
let parsedCSP = cspParser(cspHeader);
parsedCSP['script-src'].push("'unsafe-inline'");
cspHeader = Object.entries(parsedCSP).map(([key, value]) => `${key} ${value.join(' ')}`).join('; ');
console.log(cspHeader);

Other packages similar to content-security-policy-parser

Keywords

FAQs

Package last updated on 15 Jun 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc