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

csp-header

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csp-header

Content-Security-Policy header generator

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
37K
decreased by-13.6%
Maintainers
1
Weekly downloads
 
Created
Source

csp-header

Content-Security-Policy header generator for Node.JS

Usage

const csp = require('csp-header');
csp({
  policies: {
    'script-src': [
      csp.SELF,
      csp.INLINE,
      csp.EVAL,
      csp.nonce('gg3g43#$g32gqewgaAEGeag2@#GFQ#g=='),
      'example.com'
    ],
    'style-src': [
      csp.SELF,
      'mystyle.net'
    ]
  }
  'report-uri': 'https://cspreport.com/send'
});

// result: "script-src 'self' 'unsafe-inline' 'unsafe-eval' 'nonce-gg3g43#$g32gqewgaAEGeag2@#GFQ#g==' example.com; style-src 'self' mystyle.net; report-uri https://cspreport.com/send;"

Extending

If you want to extend your config by some rules:

const myCSPPolicies = require('./my-csp-rules');

csp({
  policies: myCSPPolicies,
  extend: {
    'connect-src': ['test.com']
  }
});

Presets

You can use csp presets prefixed by 'csp-preset'. If you have a web-service it would be great if you write preset with rules for your service users.

E.g. your service is called my-super-service.com. You publish preset csp-preset-my-super-service containing following code:

modules.exports = {
  'script-src': ['api.my-super-service.com'],
  'img-src': ['images.my-super-service.com']
};

Then someone wants to configure its CSP to work with your service. And now it's so easy:

const myCSPPolicies = require('./my-csp-rules');

csp({
  policies: myCSPPolicies,
  presets: ['my-super-service']
});

And you will get a lot of thanks ;)

Keywords

FAQs

Package last updated on 21 Mar 2017

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